Subscribing to Events
Use mirrord subscribe to stream the events of a mirrord session as JSON, for example in CI.
mirrord subscribe lets you stream live events from an active mirrord session — HTTP requests, queue messages, and operator notifications as JSON to stdout. It's useful in CI/tests: assert that a request actually got stolen to your local process instead of silently hitting the real service, so a broken interception fails the build instead of going green.
When do you receive events?
HTTP - you receive an event for each request/response that was routed to or from a target workload by mirrord and matches your subscribed key.
Queue - while queue splitting is active, you receive an event for each message that matches your subscribed key. If no splitting session is active, no events are received.
Queue events support Amazon SQS, Azure Service Bus, GCP Pub/Sub, RabbitMQ, BullMQ, Kafka, NATS, NATS Pub/Sub, and Redis Pub/Sub.
In both cases: no active mirrord session = no events.
Pass --unmatched to also receive the queue messages your filter did not take, so you can see what your split is missing. See Unmatched messages.
Prerequisites
A running session started with a known key:
mirrord exec --key <KEY> .... If you don't pass--key, a random key is generated for the session (mirrord upis the exception, it defaults to your OS username). With CLI3.272.0and operator3.210.0or newer you can also subscribe without a key and get every session's events.
Usage
In one terminal, run the session you want to observe:
In another, subscribe to its events:
The key can also come from the key field in your mirrord config (e.g. mirrord subscribe -f mirrord.json)
To watch every session on the cluster at once, leave the key out (CLI 3.272.0 and operator 3.210.0 or newer; an older CLI insists on a key). Each event then carries a session_key field naming the session it belongs to:
Events stream to stdout, one compact JSON object per line, as the operator intercepts traffic for that key. Status messages go to stderr, so you can pipe events straight into jq:
You may also pass --pretty to pretty-print each event.
Options
All flags are off by default.
--session-key-field
Adds a session_key field naming the session each event belongs to.
--unmatched
Also delivers queue messages that matched no session's filter.
These flags need operator 3.210.0 or newer to take effect.
Unmatched messages
By default you receive a queue message only when your filter claimed it. With --unmatched you also receive the ones nobody claimed.
Events
Every event has the same envelope — service_name (the intercepted workload), timestamp, and a data payload. On a multi-cluster Primary the envelope also has cluster, see Multi-cluster below:
(examples are pretty-printed for clarity; actual output is compact unless --pretty is passed)
To work with just the payload, extract .data with jq:
Every payload that describes an intercepted message carries mode: steal if only your session received it, mirror if the workload received a copy too, or filtered if it matched no filter (see Unmatched messages). http_response has none - a response is routed with the request it answers - and neither does lagged, which is about the stream rather than a message.
data is one of the following (payloads shown on their own):
http_request— an intercepted (stolen) request:
http_response— the response to a stolen request:
A request and its response are separate events. Pair them on connection_id and request_id together: request_id is only unique within its connection.
queue_message— a queue message routed to your session.
queue_type is one of sqs, azure_service_bus, gcppubsub, rmq, bullmq, nats, or natspubsub. message_id and correlation_id are included only when the broker provides them (SQS, GCP Pub/Sub and BullMQ have no correlation_id). properties is the message's attribute bag, with values stringified: text as-is, and binary values base64-encoded.
An Azure Service Bus message (its application properties become properties):
An SQS message, where the payload message attribute was binary (its bytes come back base64-encoded):
A GCP Pub/Sub message. queue_name is the subscription being split, and properties are the message's attributes:
A RabbitMQ message. queue_name is the queue the message was consumed from, and properties are the AMQP headers:
A BullMQ job. message_id is the job ID, and properties are the top-level fields of the job's data payload — the same fields BullMQ splits filter on:
kafka_message— a Kafka message stolen to your session. Kafka uses a different schema thanqueue_message:topic,partition,offset, an optionalkey, andheaders(values stringified — text as-is, binary base64). There is noqueue_typeorcorrelation_id.
redis_message— a Redis Pub/Sub message relayed to your session. Redis also uses a different schema: just thechannelthe message was published to and itspayload_sizein bytes. Pub/Sub messages carry no ID, headers, or attribute bag, and the payload itself is not included.
For a pattern subscription (PSUBSCRIBE), channel is the concrete channel the message arrived on — not the pattern. So an app subscribed to orders.* that receives a message on orders.created reports:
lagged— your consumer fell behind and the operator droppedcountevents:
Lagging takes place whenever the consumer is not able to keep up with the messages and receive them in a timely fashion (e.g. due to a slow network connection). By default, the operator buffers up to 2048 messages (configurable in values.yaml through subscribeEventBufferSize), and lagging will take place if more than this many messages accumulate in the internal buffer without the consumer receiving them. Note that lagging only affects slow consumers — functioning consumers will continue to receive all events even in the presence of slow peers.
Multi-cluster
In a multi-cluster setup, one mirrord subscribe against the Primary cluster streams the events of every cluster, with or without a key. This is useful when a session spans several Workload clusters: you no longer need a subscription per cluster to see which one intercepted a request.
Every event names the cluster that intercepted it in cluster, using the cluster names from the Primary's operator.multiCluster.clusters configuration (the Primary's own events carry its operator.multiCluster.clusterName):
If the Primary cannot reach a Workload cluster's operator, the stream keeps going with the other clusters' events and reports the missing one once, as a cluster_unavailable event. The Primary keeps retrying that cluster in the background, so its events resume on their own once it is reachable again:
This needs operator 3.219.0 or newer on the Primary. Each Workload cluster's operator must let the Primary watch events: the chart grants this through the mirrord-operator-envoy-remote role as of the same version, so a Workload cluster on an older chart shows up as cluster_unavailable with a message naming the missing permission until its chart is upgraded. Subscribing directly to a Workload cluster still works and streams that cluster alone, without a cluster field.
Direct Kube API access (no mirrord CLI required)
mirrord subscribe is a thin wrapper over an operator endpoint that emits Server-Sent Events (text/event-stream). You can access it directly through the Kubernetes API, without requiring the mirrord CLI:
The subscribe arguments --session-key-field and --unmatched correspond to the query parameters include_session_key=true and include_unmatched=true.
Omit session_key to receive every session's events on one stream. Such a stream always names the session each event belongs to, regardless of the value of include_session_key. This is what mirrord subscribe without --key and the local UI do.
On a multi-cluster Primary, local_only=true limits the stream to events the Primary intercepted itself, leaving out the Workload clusters. The Primary sets it on the streams it relays, so you normally never need it.
or with kubectl proxy + curl:
watch=true is necessary to stop the Kube API server from cutting out the stream after ~60s.
Last updated
Was this helpful?

