Skip to main content
Version: 3.x

OpenTelemetry instrumentation

In this section, we will explore how to enable OpenTelemetry instrumentation when using KafkaFlow.

KafkaFlow includes support for Traces and Baggage signals using OpenTelemetry instrumentation.

tip

You can find a sample on how to enable OpenTelemetry here.

Including OpenTelemetry instrumentation in your code

Add the package KafkaFlow.OpenTelemetry to the project and add the extension method AddOpenTelemetryInstrumentation in your configuration:

services.AddKafka(
kafka => kafka
.AddCluster(...)
.AddOpenTelemetryInstrumentation()
);

Once you have your .NET application instrumentation configured (see here), you just need to subscribe to the source KafkaFlow.OpenTelemetry that is accessible through a constant at KafkaFlowInstrumentation.ActivitySourceName.

Using .NET Automatic Instrumentation

When using .NET automatic instrumentation, the KafkaFlow activity can be captured by including the ActivitySource name KafkaFlow.OpenTelemetry as a parameter to the variable OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES.

Propagation

KafkaFlow uses Propagation, the mechanism that moves context information data between services and processes. When a message is produced using a KafkaFlow producer and consumed by a KafkaFlow consumer, the context will automatically be propagated.