If you want to include {prodname} data in your application tracer, you must pass the trace metadata to {prodname}.
You can add tracing support to {prodname} through the https://opentelemetry.io/docs/specs/otel/[OpenTelemetry specification].
== Installation
To enable traceability in {prodname}, you must install the required OpenTelemetry API packages on your Kafka Connect cluster, together with the OpenTelemetry SDK.
There are three main methods for installing OpenTelemetry on Kafka Connect, each having its advantages:
xref:open-telemetry-manual-installation[Manual installation]:: Offers more control and customization.
xref:open-telemetry-strimzi-installation[Strimzi installation]:: Presents a ready-to-use solution on Kubernetes that includes all of the necessary OpenTelemetry components.
You can download the OpenTelemetry packages directly from the Maven repository, or retrieve the packages by using the Maven dependency plugin to ensure version compatibility.
===== Using the Maven Dependency Plugin
1. Create a POM file similar to the one in the following example.
In your version of the file, specify the version of the OpenTelemetry package that you want to use.
2. In the directory that contains the `pom.xml` file, run the following command to download all dependencies (including transitives) to a specified directory (for example, `./lib`)
After you install the API, install the OpenTelemetry SDK.
Install the OpenTelemetry SDK on your Kafka connect cluster by using the https://opentelemetry.io/docs/instrumentation/java/automatic/[Java agent] for automatic instrumentation.
[id="open-telemetry-docker-installation"]
=== Using Docker to install OpenTelemetry
Prefer this installation method if you want to use Docker for local development or testing.
The OpenTelemetry API dependencies are installed in the https://quay.io/repository/debezium/connect[{prodname} Kafka Connect] container image.
The JAR files are downloaded to a separate directory.
By default, the JAR files are not added to the class path.
To add the JAR files to the class path, set the environment variable `ENABLE_OTEL` to `true`.
You must also install the https://opentelemetry.io/docs/instrumentation/java/automatic/[OpenTelemetry Java agent].
[id="open-telemetry-strimzi-installation"]
=== Using Strimzi to install Open Telemetry
https://strimzi.io/[Strimzi] provides a way to deploy an Apache Kafka cluster on Kubernetes.
The Strimzi Kafka image includes all of the necessary OpenTelemetry components.
If you want to view the OpenTelemetry components that are available in the Strimzi image, examine the compose file that is provided in the https://github.com/debezium/debezium-examples/tree/main/outbox[{prodname} Outbox example].
=== Configuring OpenTelemetry
For information about how to configure OpenTelemetry, see the https://opentelemetry.io/docs/instrumentation/java/automatic/agent-config/[OpenTelemetry documentation].
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.
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.
If you enable tracing in the Kafka producer, when messages are written to the Kafka broker, the producer extracts the {prodname} processing span context from the Kafka message headers, creates a new child span, and then records information about the write operation to the broker.
The interceptor cannot propagate the traceability context if the Kafka instrumentation is enabled.
The interceptor simply propagates the traceability context before delegating the instrumentation to the OpenTelemetry SDK.
==== Enabling end-to-end traceability
1. Download and install the https://mvnrepository.com/artifact/io.debezium/debezium-interceptor/[debezium-interceptor] to the Kafka Connect classpath.
2. Disable the automatic OpenTelemetry instrumentation at the Kafka producer and consumer by setting the value of `otel.instrumentation.common.default-enabled` to `false`.
The {prodname} link:/documentation/reference/integrations/outbox[Quarkus extension] for implementing the outbox pattern provides the additional functionality necessary for tracing context propagation out-of-the-box.
Specifically, it provides the `tracingspancontext` field in the outbox table, which is used for passing the tracing span context from a service using the outbox extension to the {prodname} connector.
The link:/documentation/reference/configuration/outbox-event-router[Event Router SMT] acts as an Outbox extension counterpart, it executes the same steps as the `ActivateTracingSpan` SMT, and is used instead of it.