You are viewing documentation for an outdated version of Debezium.
If you want to view the latest stable version of this page, please gohere.

Distributed Tracing

Overview

Observability is an important aspect of microservice-oriented applications. One of the key ingredients for observability isdistributed tracing.

It is necessary to provide additional precautions when an application writes a record to a database that is later processed by Debezium. The active trace is effectively demarcated by the write to the database. If we want Debezium to join the larger scope application tracer we need to pass the trace metadata to Debezium.

The tracing support is added to Debezium through theOpenTracingspecification. It is also necessary to provide a client implementing the specification. Debezium was tested withJaegerimplementation.

无论是规范JAR文件还是Jaegerclient are part of the Debezium Kafka Connect container image. The user either needs to extend the image with them or can use theStrimziKafka image. In that case, the tracing of Kafka producer and consumer is also available.

See compose file ofOutbox example.

ActivateTracingSpan SMT

The main implementation point of tracing in Debezium isActivateTracingSpanSMT. In this case, the application writing to a database is responsible for providing the tracing span context. The writer must inject the span context into ajava.util.Propertiesinstance that is serialized and written to the database as a distinct field of the table.

If the span context is not provided then the SMT will create a new span. In this case, Debezium operations together with metadata will be traced but will not be connected to business transaction traces to enable end-to-end tracing.

When this SMT is invoked with a message then it will:

  • extract the parent span context if present in the message

  • create the eventdb-log-writespan context with the start timestamp set to the database log write timestamp

  • insert fields fromsourceblock into the span astags

  • create the processingdebezium-readspan as a child ofdb-log-writespan with the start timestamp set to the processing time of the even

  • insert fields from envelope such asopinto the processing span astags

  • injects the processing span context into message headers

Kafka Producer tracing

Optionally it is possible to enable tracing at the Kafka producer level. If enabled then when the message is being written to the Kafka broker the producer will extract Debezium’s processing span context from the Kafka message headers, create a new child span and record information about the write to the broker. Then it injects the new span into the message headers so a consumer of the message can restore the trace and resume end-to-end tracing.

Configuration options

Configuration property

Type

Default

tracing.span.context.field

The name of the field containing span context.

The sender must write the span context into the database column as a serialized instance ofjava.util.Propertieswith injected span context.

string

tracingspancontext

tracing.operation.name

The operation name representing the Debezium processing span.

string

debezium-read

tracing.with.context.field.only

Only events that have serialized context field should be traced.

If set totruethen tracing span will be created only for events with associated tracing span context field. If set tofalsethen the tracing span is created for all incoming events regardless of having associated span context.

boolean

false

Outbox Extension

The DebeziumQuarkus extensionfor implementing the outbox pattern provides the additional functionality necessary for tracing context propagation out-of-the-box. Specifically, it provides thetracingspancontextfield in the outbox table, which is used for passing the tracing span context from a service using the outbox extension to the Debezium connector.

When an outbox event is emitted, the extension will:

  • create a newoutbox-writespan as a child of current active span

  • inject the span context into thatjava.util.Propertiesinstance that is serialized into thetracingspancontextcolumn

  • write the record into the database

The tracing integration in the outbox extension is automatically enabled if also thesmallrye-opentracingQuarkus extension is present. If you want to disable tracing support for the outbox extension despite thesmallrye-opentracingQuarkus extension being is present, you can disable it by setting an optionquarkus.debezium-outbox.tracing.enabled=falsein the Quarkusapplication.propertiesfile.

Event Router SMT

TheEvent Router SMTacts as an Outbox extension counterpart, it executes the same steps as theActivateTracingSpanSMT, and is used instead of it.