// Module included in the following assemblies:
//
// assembly-setting-up-tracing-mirror-maker-connect-bridge.adoc

[id='proc-enabling-tracing-in-connect-mirror-maker-bridge-resources-{context}']
= Enabling tracing in MirrorMaker, Kafka Connect, and Kafka Bridge resources

[role="_abstract"]
Distributed tracing is supported for MirrorMaker, MirrorMaker 2, Kafka Connect, and the Strimzi Kafka Bridge.
Configure the custom resource of the component to specify and enable a tracer service. 

Enabling tracing in a resource triggers the following events:

* Interceptor classes are updated in the integrated consumers and producers of the component.

* For MirrorMaker, MirrorMaker 2, and Kafka Connect, the tracing agent initializes a tracer based on the tracing configuration defined in the resource.

* For the Kafka Bridge, a tracer based on the tracing configuration defined in the resource is initialized by the Kafka Bridge itself.

You can enable tracing that uses OpenTelemetry.

.Tracing in MirrorMaker and MirrorMaker 2

For MirrorMaker and MirrorMaker 2, messages are traced from the source cluster to the target cluster. The trace data records messages entering and leaving the MirrorMaker or MirrorMaker 2 component.

.Tracing in Kafka Connect

For Kafka Connect, only messages produced and consumed by Kafka Connect are traced. To trace messages sent between Kafka Connect and external systems, you must configure tracing in the connectors for those systems.

.Tracing in the Kafka Bridge

For the Kafka Bridge, messages produced and consumed by the Kafka Bridge are traced. Incoming HTTP requests from client applications to send and receive messages through the Kafka Bridge are also traced.
To have end-to-end tracing, you must configure tracing in your HTTP clients.

.Procedure

Perform these steps for each `KafkaMirrorMaker`, `KafkaMirrorMaker2`, `KafkaConnect`, and `KafkaBridge` resource.

. In the `spec.template` property, configure the tracer service.
+
--
* Use the xref:ref-tracing-environment-variables-{context}[tracing environment variables] as template configuration properties.
* For OpenTelemetry, set the `spec.tracing.type` property to `opentelemetry`.
--
+
--
.Example tracing configuration for Kafka Connect using OpenTelemetry
[source,yaml,subs=attributes+]
----
apiVersion: {KafkaConnectApiVersion}
kind: KafkaConnect
metadata:
  name: my-connect-cluster
spec:
  #...
  template:
    connectContainer:
      env:
        - name: OTEL_SERVICE_NAME
          value: my-otel-service
        - name: OTEL_EXPORTER_OTLP_ENDPOINT
          value: "http://otlp-host:4317"
  tracing:
    type: opentelemetry
  #...
----

.Example tracing configuration for MirrorMaker using OpenTelemetry
[source,yaml,subs=attributes+]
----
apiVersion: {KafkaMirrorMakerApiVersion}
kind: KafkaMirrorMaker
metadata:
  name: my-mirror-maker
spec:
  #...
  template:
    mirrorMakerContainer:
      env:
        - name: OTEL_SERVICE_NAME
          value: my-otel-service
        - name: OTEL_EXPORTER_OTLP_ENDPOINT
          value: "http://otlp-host:4317"
  tracing:
    type: opentelemetry
#...
----

.Example tracing configuration for MirrorMaker 2 using OpenTelemetry
[source,yaml,subs=attributes+]
----
apiVersion: {KafkaMirrorMaker2ApiVersion}
kind: KafkaMirrorMaker2
metadata:
  name: my-mm2-cluster
spec:
  #...
  template:
    connectContainer:
      env:
        - name: OTEL_SERVICE_NAME
          value: my-otel-service
        - name: OTEL_EXPORTER_OTLP_ENDPOINT
          value: "http://otlp-host:4317"
  tracing:
    type: opentelemetry
#...
----

.Example tracing configuration for the Kafka Bridge using OpenTelemetry
[source,yaml,subs=attributes+]
----
apiVersion: {KafkaBridgeApiVersion}
kind: KafkaBridge
metadata:
  name: my-bridge
spec:
  #...
  template:
    bridgeContainer:
      env:
        - name: OTEL_SERVICE_NAME
          value: my-otel-service
        - name: OTEL_EXPORTER_OTLP_ENDPOINT
          value: "http://otlp-host:4317"
  tracing:
    type: opentelemetry
#...
----
--

. Create or update the resource:
+
[source,shell,subs="+quotes"]
----
kubectl apply -f _<resource_configuration_file>_
----
