# ZeroMQ Instrument ZeroMQ producers and consumers in the application. Contrib 0.160.0 has no dedicated ZeroMQ server-metrics receiver. ZeroMQ socket events also do not provide request traces, message-processing latency, or proof that a consumer finished its work. ## Configure the calling applications Complete the SDK and OTLP setup for each [application language](README.md#instrument-the-calling-application). Give producers and consumers their own service identities. Create a producer span around sending and a consumer span around processing; send completion is not a delivery acknowledgement or a completed consumer operation. Where your chosen instrumentation does not propagate context, carry W3C trace context in an agreed application envelope. Both sides must understand the envelope before you change a production protocol. Do not put credentials, message bodies, or confidential baggage into telemetry. ## Try a local propagation check This Python example sends one JSON message through in-process PUSH/PULL sockets. It opens no network listener. Complete the [Python SDK setup](../languages/python.md) first and install the binding in the same environment: ```sh python -m pip install pyzmq ``` Run the fragment after SDK initialization with the W3C trace-context propagator enabled. The SDK's normal default propagators include it. ```python import zmq from opentelemetry import trace from opentelemetry.propagate import extract, inject from opentelemetry.trace import SpanKind tracer = trace.get_tracer("example.zeromq") context = zmq.Context() receiver = context.socket(zmq.PULL) sender = context.socket(zmq.PUSH) receiver.setsockopt(zmq.RCVTIMEO, 5000) sender.setsockopt(zmq.SNDTIMEO, 5000) receiver.bind("inproc://otel-smoke") sender.connect("inproc://otel-smoke") try: with tracer.start_as_current_span("send smoke", kind=SpanKind.PRODUCER): carrier = {} inject(carrier) sender.send_json({"trace": carrier, "payload": "smoke"}) envelope = receiver.recv_json() with tracer.start_as_current_span( "process smoke", context=extract(envelope["trace"]), kind=SpanKind.CONSUMER, ): assert envelope["payload"] == "smoke" finally: sender.close(linger=0) receiver.close(linger=0) context.term() ``` Flush/shut down the SDK exporter when the smoke program exits. This example intentionally measures processing after receipt, rather than including idle time spent waiting for a message in the processing span. ## Move the pattern into production Keep your existing transport authentication and access controls. The in-process example has no credentials because both endpoints live in one process; it is not a network security configuration. Restrict who can send messages and bound the size and shape of accepted envelopes before extracting context. On the producer, inject context while its send span is current. On the consumer, extract from the received envelope before creating the processing span. Preserve context across worker/task boundaries. For batches containing several parent contexts, use span links instead of arbitrarily assigning every message one parent. Reusing one message's carrier for unrelated messages joins unrelated work. Add application counters for accepted messages and processing failures and a histogram for processing duration. Use bounded labels such as operation and outcome. Socket connection events can complement those signals but cannot replace them. For existing Prometheus endpoints or process logs, follow [other service collection](other-services.md). ## Verify Run the smoke test and find `send smoke` and `process smoke` in Corridora under the test application's service. They should share a trace ID, with the producer context carried into the consumer span. Then repeat through separate test producer and consumer processes using their actual envelope and service names. If each side produces a separate trace, inspect whether the envelope retained `traceparent`, whether extraction happened before the consumer span started, and whether the configured propagators match. A missing send/receive operation is a transport issue; a completed operation with missing spans calls for [SDK and export verification](../../verification.md). Source basis: PyZMQ 27.2 API documentation; OpenTelemetry Python propagation and instrumentation; Collector Contrib distribution manifest 0.160.0. Reviewed 2026-09-28.