fs2-kafka-otel4s

Producer tracing configurator

Choose a batch mode, inspect spans and outgoing headers, and copy the Scala example. For a first send, see Producers.

Configure your producer

Trace timeline

Expand a span to see its attributes and links. Indented spans are children of the application span.

Incoming message contexts

Existing trace contexts are preserved. The demo uses sample W3C traceparent headers and needs a W3C propagator. In your application, keep the upstream headers.

Outgoing trace headers

Follow a context link to see its source. For records in a batch without existing context:

Generated Scala

Supply a configured otel4s TracerProvider. Run Kafka at localhost:9092 and create the selected topic. The code uses .flatten to submit records and wait for acknowledgment.

The interactive selector requires JavaScript. The rules below and the producer instrumentation reference describe the same behavior.

Understand the choices

Choice Effect
PerRecordSpans For batches, create a span for each record missing trace context, then a CLIENT send span linked to every record context
SharedSendSpan Create one send span; preserve existing contexts and inject its context into other records
Single record The batch mode has no effect: a missing context gives a PRODUCER send span; an existing context gives a linked CLIENT send span
Empty batch Call the underlying producer without spans or header preparation
Disable send span Keep publishing and create spans. Records without context use a create span or the active application span, if available
Application span Create and send become siblings under the application span; incoming record contexts remain links

withSendSpanSetup customizes send spans. Create-span names and setup are fixed. KafkaTracer.noop disables all spans and propagation.

Constant attributes apply to library spans. They do not change names, outgoing contexts, or link attributes. Single-record results add the partition and offset after acknowledgment, replacing matching constant attributes.

The context in each outgoing record can become a consumer process span's parent with .withRelationship(ProcessSpanRelationship.ParentFromRecord) on the consumer's process span setup. This preserves message links and applies to single-record processing and singleton process batches. Explore both modes in the Consumer tracing configurator.

For mixed topics, partitions, and other rules, see Producer instrumentation. For shared options, see Configuration.

Selections are saved in the URL. Keep secrets out of shared attribute values.