opentelemetry-java icon indicating copy to clipboard operation
opentelemetry-java copied to clipboard

TraceInterceptors functionality to the SDK

Open NickAnge opened this issue 2 years ago • 6 comments

Is your feature request related to a problem? Please describe. Hello :)

Currently, we are in the process of migrating from DD (DataDog) instrumentation to Opentelemetry. During this migration, we have encountered a specific case where we want to implement TraceInterceptors. In other words, we want to add custom functionality at the end of a specific trace.

Here's a simple example: we would like to have a TraceInterceptor that collects the number of spans for that particular trace and then adds this number as an attribute to the root span. This is just an example

Datadog Instrumentation, provides that feature with the TraceInterceptor interface (Ref)

Is there something similar to the sdk that we can use to achieve the same functionality ?

Describe the solution you'd like The solution that we would like is to have an Interface that we could utilize to: add our custom implementation at the end of a trace, and have all the information (Spans, SpanData etc) for the trace.

Describe alternatives you've considered The alternative that we have considered is using the SpanProcessor. However its not possible to know when the Trace has ended as it applies only to spans.

Thanks in advance for your help, comments

NickAnge avatar Aug 01 '23 09:08 NickAnge

This is not something that is specified as a part of OpenTelemetry. If you need something new, I recommend opening an issue in the specification.

jkwatson avatar Aug 02 '23 15:08 jkwatson

at the end of a trace, and have all the information (Spans, SpanData etc) for the trace

you could look into the tail sampling functionality in the collector, possibly this could support your use case

trask avatar Aug 02 '23 17:08 trask

Thanks a lot for your comments. @jkwatson . Sorry I am not familiar with the process as it is my first time opening an issue . Could you please link the specification where I could open the issue ?

@trask . I took a look at the tail-sampling processor, and I am afraid that it cannot support our case. The reason is that we want to apply some custom logic, which will end up to add the right attributes to the root span of the trace. (E.g one of the use cases that we want to achieve is to list the spans of a trace, and check the different type of spans, for that specific trace. That way we can add attributes to the root span, regarding the rpcs for that specific trace). Let me know if my example makes sense.

NickAnge avatar Aug 05 '23 16:08 NickAnge

Thanks a lot for your comments. @jkwatson . Sorry I am not familiar with the process as it is my first time opening an issue . Could you please link the specification where I could open the issue ?

https://github.com/open-telemetry/opentelemetry-specification

jkwatson avatar Aug 05 '23 17:08 jkwatson

@NickAnge I'm not aware of anything in the sdk or the agent that tracks the entirety of a trace lifecycle in the way you're describing. Traces are often spread across multiple services, hence the term "distributed tracing".

Even if one service can detect that there are no additional downstream spans, it doesn't imply that the trace has ended because there could be ongoing spans in other peer services. My initial reaction is that maybe your current vendor has a slightly different definition of a trace or trace lifecycle. Maybe @tylerbenson can shed some light on that.

breedx-splk avatar Aug 10 '23 21:08 breedx-splk

I believe in OTel there is functionality to access the root span of a currently active trace, but not afterwards.

The reason what you're asking for is possible in Datadog but not OTel is that Datadog's tracer maintains a much stronger definition of a trace. They track open spans for each trace and hold off reporting them until they are all complete. This allows them to do things at the end of a trace, but also requires keeping more in memory until the trace is complete. In contrast, OTel reports spans individually as they complete.

If you need to achieve something like Datadog's processing mechanism, you might be able to implement an alternative to the BatchSpanProcessor that groups spans into logical traces and reports them when they're "done" or after a timeout or something.

tylerbenson avatar Aug 14 '23 15:08 tylerbenson