Metadata subscriptions

Realtime metadata updates are provided by subscribing to metachannels using the realtime interface of an Ably SDK. Metachannels are a namespace of channels beginning with the [meta] qualifier and they can be subscribed to in the same manner as regular channels.

Events are published to metachannels that provide app-level metadata about different resources, such as channels, connections and API requests.

Metachannels

The following is a list of available metachannels:

MetachannelDescription
[meta]connection.lifecycleconnection-lifecycle: Publishes connection lifecycle events of realtime connections
[meta]channel.lifecyclechannel-lifecycle: Publishes channel lifecycle events, such as channels opening and closing
[meta]stats:minutestats: Publishes app statistics at one minute intervals
[meta]clientEvents:connectionssample: Publishes metadata for a sample of connection events
[meta]clientEvents:apiRequestssample: Publishes metadata for a sample of API request events
[meta]loglog: Publishes error events that would otherwise not be received by a client. Excludes errors related to Push Notifications
[meta]log:pushlog: Similar to [meta]log, but only for errors that occur during delivery of Push Notifications

It is never possible to publish or be present on a metachannel, however you can query their history.

The following is an example of a capability that provides access to subscribe to all metachannels:

JSON

1

{"[meta]*":["subscribe"]}

Connection lifecycle events

Connection lifecycle events are published when connections are opened and closed within an app. They are published to the [meta]connection.lifecycle metachannel.

Channel lifecycle events

Channel lifecycle events are published when channels are opened and closed within an app.

The following events are published to [meta]channel.lifecycle:

EventDescription
channel.openedIndicates that the channel has been activated globally. This means that it has become active in at least one region, having previously been inactive
channel.closedIndicates that the channel has been deactivated globally
channel.region.activeIndicates that the channel has been activated in a specific region
channel.region.inactiveIndicates that the channel has been deactivated in a specific region

The data property of all events is a ChannelDetails object. The ChannelDetails.ChannelStatus which includes occupancy details varies depending on the event. If the event is specific to a region, such as channel.region.active then the occupancy metrics will only be for that region. For other events such as channel.opened, the occupancy metrics will be global.

The following is an example of subscribing to all [meta]channel.lifecycle events:

Realtime

1

2

3

4

5

const channel = ably.channels.get('[meta]channel.lifecycle');

await channel.subscribe((msg) => {
    console.log('Event type: ' + msg.name, msg.data);
});

The following is an example of subscribing to channel.closed events:

Realtime

1

2

3

4

5

const channel = ably.channels.get('[meta]channel.lifecycle');

await channel.subscribe('channel.closed', (msg) => {
    console.log('lifecycle meta channel (closed): ', msg.data);
});

Log events

The [meta]log and [meta]log:push metachannels publish events that aren't otherwise available to clients.

Errors where the client can be directly notified are not published to the metachannels. For example, if a client attempts to publish a message but exceeds a channel rate limit, the client will be notified by an error callback passed to the publish() method.

The following example subscribes to the [meta]log channel:

JavaScript

1

2

const channel = realtime.channels.get('[meta]log');
channel.subscribe(msg => console.log(msg));

App statistics events

The [meta]stats:minute metachannel publishes app-level statistics at one minute intervals. This is in addition to being available in your account dashboard and to query programmatically.

Events are published every minute and contain statistics for only the past minute. They are published as an update and this is the only event name published to the metachannel.

The following is an example of subscribing to [meta]stats:minute:

Realtime

1

2

3

4

5

const channel = ably.channels.get("[meta]stats:minute");

await channel.subscribe('update', event => {
  console.log(JSON.stringify(event, undefined, 2));
});

As there could potentially be a delay of up to one minute before the first event, you can obtain the most recent statistics event using the rewind channel option.

The following example will return the most recent event and also subscribe to subsequent events:

Realtime

1

  const channel = ably.channels.get('[meta]stats:minute', {params: {rewind: '1'}});

You can also subscribe to [meta]stats:minute using SSE.

App statistics event format

Each event will be formatted according to the app-stats JSON schema. The following is an example of a returned event:

JSON

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

{
  "name": "update",
  "id": "trVvT-KeEw:0:0",
  "encoding": null,
  "data": {
    "intervalId": "2021-10-07:16:23",
    "unit": "minute",
    "schema": "https://schemas.ably.com/json/app-stats-0.0.1.json",
    "entries": {
      "connections.all.peak": 1,
      "connections.all.min": 1,
      "connections.all.mean": 0.2,
      "connections.all.opened": 2,
      "apiRequests.all.succeeded": 2,
      "apiRequests.tokenRequests.succeeded": 2
    }
  }
}

The following are the event properties:

PropertyDescription
nameOnly update is supported as an event name
idThe unique ID of the event
encodingThe encoding of the event data
intervalIdThis is an indication of the date-time interval that this statistics record relates to
unitOnly minute is supported as a statistics unit
schemaThe JSON schema used for the encoding of the event
entriesThis is a flattened representation of the categories for which there are non-zero entries for this statistics record

Sampled connection and request events

Enterprise accounts can sample connection and request events in order to monitor the usage of Ably services. Events are published to two metachannels that contain metadata for a sample of connections and API requests. These events can be used to compile statistics on app usage, enabling you to perform arbitrary data processing and aggregation related to client population and client activity. These metachannels must be enabled for each app you would like to sample.

Events are published on the metachannels [meta]clientEvents:connections and [meta]clientEvents:apiRequests.

The following code snippet shows how to subscribe to connection.opened events:

Realtime

1

2

3

4

5

const channel = ably.channels.get('[meta]clientEvents:connections');

await channel.subscribe('connection.opened', (msg) => {
    console.log('connection opened: ', msg.data);
});

The following code snippet shows how to subscribe to all sampled API request events:

Realtime

1

2

3

4

5

6

const channel = ably.channels.get('[meta]clientEvents:apiRequests');

// To subscribe to all event types
await channel.subscribe((msg) => {
    console.log('Event type: ' + msg.name, msg.data);
});

Sample rate

The rate of sampling dictates the number of events published to the metachannels. For example, a rate of 0.1% for connections would publish an average of one message in every 1000. The sample rate can be configured independently for connections and API requests within the same app.

Connections

A sample of connection events are published to the channel [meta]clientEvents:connections. Connection events can be used to compile statistics relating to client population.

The connection event types are:

Event TypeDescription
connection.openedThe connection was successfully made by the client to Ably
connection.closedThe connection was explicitly closed by the client
connection.refusedThe connection was rejected for an expected reason, such as invalid credentials or a malformed request
connection.failedThe connection was rejected for an unexpected reason, such as a network failure

Events contain a subset of the following metadata in the data field:

FieldTypeDescription
hostStringThe host the connection was made to
requestIdStringThe unique ID of the request that Ably can use to correlate a connection event with internal logs, if necessary
regionStringThe region the connection was made from
headersJSON ObjectThe headers sent with the connection
queryJSON ObjectThe parsed query string of the connection request, excluding authentication parameters. It contains connection information such as the client library version and any custom transport parameters
connectionIdStringThe unique ID of the connection
clientIdStringThe ID of the client that attempted the connection
channelsArrayA list of channels included in the request. This is only relevant where channels are supported as part of the connection request, such as with SSE
durationIntegerThe duration the connection was open for
errorJSON ObjectThe details of any error encountered whilst making the connection request. It includes an error message, error code and HTTP status code

An example of a connection.closed event is:

JSON

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

{
  "host": "realtime.ably.io",
  "requestId": "fbbcb0ab-fa56-47c4-bbd4-fccc22a271b8",
  "region": "us-east-1",
  "headers": {
    "host": "realtime.ably.io",
    ...
  },
  "query": {
    "format": "json",
    "heartbeats": "true",
    "v": "1.2",
    "lib": "js-web-1.2.9"
  },
  "connectionId": "54321",
  "clientId": "12345",
  "duration": 61151
}

API requests

Sampled API request events for an app are published to the channel [meta]clientEvents:apiRequests. API request events can be used to compile statistics relating to client activity.

The request event types are:

Event TypeDescription
request.succeededThe request was successful
request.refusedThe request was rejected for an expected reason, such as a malformed request or insufficient privileges
request.failedThe request was rejected for an unexpected reason, such as a network failure

Events contain a subset of the following metadata in the data field:

FieldTypeDescription
hostStringThe host the request was made to
requestIdStringThe unique ID of the request that Ably can use to correlate a request event with internal logs, if necessary
regionStringThe region the request was made in
headersJSON ObjectThe headers sent with the request
queryJSON ObjectThe details of the parsed request query, including information such as the request format
pathStringThe path of the endpoint called in the request, for example /channels/{channel-name}/messages
channelsArrayA list of channels the request was made against
errorJSON ObjectThe details of any error encountered whilst making the request. It includes an error message, error code and HTTP status code

An example of a request.succeeded event is:

JSON

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

{
  "host": "rest.ably.io",
  "requestId": "fbbcb0ab-fa56-47c4-bbd4-fccc22a271c9",
  "region": "us-east-2",
  "headers": {
    "host": "rest.ably.io",
    ...
  },
  "query": {
    "format": "json"
  },
  "path": "/channels/example-channel/messages",
  "channels": [
    "my-test-channel"
  ]
}
Select...