- Set up a custom log handler to capture and manage errors in a way that suits your requirements.
- Meta channels allow you to monitor errors that might not otherwise be visible to clients, providing additional insights into issues.
- The Dev console in your Ably dashboard is a quick and easy way to inspect errors and events, especially during development or debugging.
Monitoring best practices
Use SDK mechanisms for error detection
Ably SDKs provide built-in mechanisms to notify you when errors occur:- Connection state changes - The connection will emit events when it changes state. If it enters the
disconnectedorfailedstate, the state change will include areasonexplaining why. In thedisconnectedstate, it will automatically retry after 15 seconds. - Channel state changes - Channel state works similarly, with different states and automatic retry behavior.
- Client library logs - ERROR level logs can be accessed programmatically using a custom log handler.
Avoid monitoring HTTP status codes
Strongly recommended against monitoring HTTP status codes of individual requests to detect problems. An HTTP request with a non-2xx response does not necessarily indicate a problem. There are many possible reasons individual HTTP requests may return error status codes, especially with imperfect network connections, and only a small fraction represent actual problems. For example:- When a token expires and cannot complete online reauth in time, a comet receive stream will close with a 401 status code and error code 40142. This is expected behavior that triggers the library to obtain a new token and resume the connection.
- Many actual problems won’t show up as non-2xx HTTP requests (for example, errors sent as protocol messages down a WebSocket).
Recommended approach: Use the built-in SDK mechanisms, particularly connection state changes and channel state changes, for reliable error detection and monitoring.
SSL certificate issues
Common SSL certificate errors
If you encounter SSL certificate errors when connecting to Ably, you may see errors such as:Root cause
SSL certificate verification failures typically occur when:- Your system’s root certificate authority (CA) certificates are outdated
- The certificate chain cannot be properly verified
- Your system lacks the necessary intermediate certificates
Solutions
Update root certificates
The most common solution is to update your system’s root certificates: On Ubuntu/Debian:Alternative approaches
If updating root certificates doesn’t resolve the issue:- Check your firewall/proxy: Corporate networks may intercept SSL connections
- Verify system time: Ensure your system clock is accurate, as certificate validation depends on correct time
- Test with curl: Use
curl -I https://rest.ably.ioto test SSL connectivity directly
Error info
All errors returned by Ably are standardized and use theErrorInfo object:
ErrorInfo object:
- code - Ably-specific numeric code indicating the error type.
- statusCode - An HTTP status code providing broader context, such as 400 for a bad request.
- cause - A brief description of the issue.
- nonfatal - A boolean indicating whether the error is critical.
- href - A direct link to Ably’s documentation or for quick troubleshooting references.
Logging
Ably SDKs allow you to customize the function that handles logging. This function is usually set in the options when configuring a client, such as theClientOptions object for Pub/Sub.
Two separate properties can be set:
- logHandler - Provides a custom function for each line of log output.
- logLevel - The verbosity of the logging output, from silent to trace. In some SDKs this is numeric, and in others string.
logLevel setting for the Ably client, which controls how much logging output is shown. Higher levels include more detailed information:
| Level | Description |
|---|---|
0 | No logs |
1 | Errors only |
2 | Errors plus connection and channel state changes |
3 | Abbreviated debug output |
4 | Full debug output |
logLevel:1 and processes them with the function logWriteFun():
Metachannels
Ably provides a set of metachannels that expose internal events from the Ably system. These metachannels are be useful for debugging and monitoring, especially when investigating issues not surfaced directly to clients.Errors returned directly to clients are not published to metachannels. For example, if a client publishes a message but exceeds a channel rate limit, the
publish() method uses an error callback to notify the client.- [meta]log - Publishes errors that aren’t visible to clients, except those related to push notifications.
- [meta]log:push - Similar to
[meta]log, but only publishes errors related to the delivery of push notifications.
[meta]log channel:
Dev console
The Dev console in your Ably dashboard is a quick and easy way to inspect errors. It provides a live stream of all events in your application, which is especially useful during early-stage development or low-traffic periods when events are easier to track:- Monitor all live events in your application for detailed insights.
- Test publishing and subscribing to channels to identify and resolve issues with these functions.
The Dev console displays a realtime feed of events. It does not store historical data, so you won’t be able to query past events after an error has occurred.
