:_mod-docs-content-type: PROCEDURE

// 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 supported Kafka components

[role="_abstract"]
Distributed tracing is supported for MirrorMaker, MirrorMaker 2, Kafka Connect, and the HTTP Bridge.
Enable tracing using OpenTelemetry by setting the `spec.tracing.type` property to `opentelemetry`. 
Configure the custom resource of the component to specify and enable a tracing system using `spec.template` properties.

By default, OpenTelemetry uses the OTLP (OpenTelemetry Protocol) exporter and endpoint to gather trace data. 
This procedure shows the configuration to use OTLP as the tracing system.

If you prefer to use a different tracing system supported by OpenTelemetry, such as Jaeger, you can modify the exporter and endpoint settings in the tracing configuration.

CAUTION: Strimzi no longer supports OpenTracing.
If you were previously using OpenTracing with the `type: jaeger` option, we encourage you to transition to using OpenTelemetry instead.

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 HTTP Bridge, a tracer based on the tracing configuration defined in the resource is initialized by the HTTP Bridge itself.

.Tracing in MirrorMaker 2

For MirrorMaker 2, messages are traced from the source cluster to the target cluster. The trace data records messages entering and leaving the 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 HTTP Bridge

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

.Procedure

Perform these steps for each `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 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 HTTP 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
#...
----
--

. (Optional) If TLS authentication is configured on the OTLP endpoint, use the `OTEL_EXPORTER_OTLP_CERTIFICATE` environment variable to specify the path to a trusted certificate
This secures communication between Kafka components and the OpenTelemetry endpoint.
+
To provide the certificate, mount a volume containing the secret that holds the trusted certificate.  
Unless the endpoint address is redirected from `http`, use `https`.
+
.Example configuration for TLS
[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: "https://otlp-host:4317"
        - name: OTEL_EXPORTER_OTLP_CERTIFICATE
          value: "/mnt/mysecret/my-certificate.crt"
      volumeMounts:
        - name: tracing-secret-volume
          mountPath: /mnt/mysecret   
    pod:
      volumes:
        - name: tracing-secret-volume
          secret:
            secretName: mysecret     
  tracing:
    type: opentelemetry
  #...
----

. Apply the changes to the custom resource configuration.
