Distributed Tracing
Overview
Observability is an important aspect of microservice-oriented applications. One of the key ingredients for observability is distributed 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 the OpenTracing specification. It is also necessary to provide a client implementing the specification. Debezium was tested with Jaeger implementation.
Neither the specification JAR files nor the Jaeger client are part of the Debezium Kafka Connect container image. The user either needs to extend the image with them or can use the Strimzi Kafka image. In that case, the tracing of Kafka producer and consumer is also available. See compose file of Outbox example. |
ActivateTracingSpan SMT
The main implementation point of tracing in Debezium is ActivateTracingSpan
SMT.
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 a java.util.Properties
instance 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 event
db-log-write
span context with the start timestamp set to the database log write timestamp -
insert fields from
source
block into the span as tags -
create the processing
debezium-read
span as a child ofdb-log-write
span with the start timestamp set to the processing time of the even -
insert fields from envelope such as
op
into the processing span as tags -
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 |
|
string |
tracingspancontext |
|
string |
debezium-read |
|
boolean |
false |
Outbox Extension
The Outbox extension provides the additional operations necessary for tracing context propagation out-of-the-box.
It provides the tracingspancontext
field in an outbox table that is used as the vehicle to pass span context from service using the outbox extension to a Debezium connector.
When an outbox even is emitted the extension will:
-
create a new
outbox-write
span as a child of current active span -
inject the span context into that
java.util.Properties
instance that is serialized into thetracingspancontext
column -
write the record into the database
Event Router SMT
The Event Router SMT acts as an Outbox extension counterpart, it executes the same steps as the ActivateTracingSpan
SMT, and is used instead of it.