-
Notifications
You must be signed in to change notification settings - Fork 356
Description
Component
OpenTelemetry.Instrumentation.ConfluentKafka
Is your feature request related to a problem?
After I call consumer.Consume, Activity.Current is null and so any logs, HTTP requests, SQL updates, etc. I make while processing the message are not tied to the message that triggered them. That prevents me from easily pulling up a trace of a message and seeing if it was successfully processed or not by consumers.
What is the expected behavior?
The current implementation of this component both starts and stops the Activity inside the consumer.Consume method call, preventing any business logic that processes the message (logs, Redis, SQL, HTTP, etc.) from being correlated to that message. That seems to go against the goals of distributed tracing, ending the trace in the middle of the work.
Datadog's tracer accomplishes that by leaving the activity open after Consume is called and closing it next time Consume is called, which in a typical consume loop is immediately after the message is processed. You can look at their code here: https://github.com/DataDog/dd-trace-dotnet/blob/0070285865b391ac1db44682aa24ead9c903dad1/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Kafka/KafkaConsumerConsumeIntegration.cs#L66
Which alternative solutions or features have you considered?
I found https://opentelemetry.io/docs/specs/semconv/messaging/messaging-spans/#consumer-spans which appears to document how things should work here. This section here seems to suggest an alternative solution:
“Process” spans MAY be created in addition to “Receive” spans for pull-based scenarios for operations of processing messages. Such spans could be created by application code, or by abstraction layers built on top of messaging SDKs.
It's not clear how one would do that here though, without effectively re-implementing all the logic of this component (parsing headers, adding tags, etc.). If I'm going to do all that I may as well not use this component at all.
Additional context
No response