ivanthelad / dotnet-otel-kafka-demo

Simple app to demonstrate how to perform otel tracing in .net across Kafka topics

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dotnet-otel-kafka-demo

Simple app to demonstrate how to perform otel tracing in .net across Kafka topics. The example simply sets the otel headers in the the kafka event. The consumer extracts these and continues the trace

Instead the application now user context Propagators to send the kafka context across the wire. This allows much more flexibilty how we inject and set contexts and also adheres to otels sdk recommended approach.

Prep Demo

The following create the demo setup

Start kafka Broker

cd deploy/kafka 
docker compose up -d 

Create topic

 docker compose exec broker \
  kafka-topics --create \
    --topic purchases \
    --bootstrap-server localhost:9092 \
    --replication-factor 1 \
    --partitions 1 

Deploy otel

taken from here. Commenting out the client and server aspects https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/examples/demo

cd deploy/otel 
docker compose up -d 

build and run producer

This creates a single message on kafka

cd producer 
dotnet build
dotnet run $msg

Kafka connection configuration is confifgured in appsettings.json

 "KafkaProducerConfig": {
   "BootstrapServers": "localhost:9092",
   "ClientId": "my-producer-id",
   "Acks": "all"
 },

Build and run consumer

Kafka connection configuration is confifgured in appsettings.json

cd consumer 
dotnet build
dotnet run 

Kafka connection configuration is confifgured in appsettings.json

 "KafkaConsumerConfig": {
   "BootstrapServers": "localhost:9092",
   "ClientId": "my-consumer-id",
   "Acks": "all",
   "GroupId": "kafka-dotnet-getting-started",
   "AutoOffsetReset": "earliest"
 },

View Results in Jaeger

The results can be see in the jaeger UI which was started in the OTEL docker compose up. Go to http://127.0.0.1:16686/ Screenshot of a comment on a GitHub issue showing an image, added in the Markdown, of an Octocat smiling and raising a tentacle.

Notes

About

Simple app to demonstrate how to perform otel tracing in .net across Kafka topics


Languages

Language:C# 100.0%