Description
First time contributor here--please let me know if there's anything I need to correct procedurally!
What are you trying to achieve?
I'm hoping to extend the API description for Context as it pertains to Traces (or perhaps change the API description for Traces?)
Here's the problem I'm trying to solve:
Consider a user flow in which a file conversion service accepts an HTTP request. The user's intent is to upload a file to convert it from one file type to another (e.g. .pdf
-> .png
). For infrastructure performance reasons, this work is enqueued in a messaging system/background job processing system (e.g. Sidekiq in the Ruby ecosystem). As part of handling the same request, a similar message/background job is sent to the same system. This flow is depicted below:
graph TD
A[Client] -->|Requests| B[Request Handler]
B -->|Enqueues| C[Background Job for File Conversion]
B -.->|Enqueues| D[Background Job for Analytics]
style D stroke-dasharray: 5 5
From a user's perspective, only the solid-line nodes in the above graph are important. The dashed lines are merely an implementation detail. Similarly, only the Spans related to the solid-line nodes are, to me as the engineer monitoring this system, significant. If the analytics-related message is not complete for another hour, that does not matter to me very much.
This maps neatly to the notion of child Spans & Links: for a step in a flow where it is all really part of one high-level request, one would hope to have that represented as a child Span. It is truly just part of the overall Trace (or, at least, what I would expect a Trace to capture). On the other hand, the analytics message is relatively detached. While a Link could point me to its source, it is not something that is part of the user journey.
What did you expect to see?
Ideally, this is something that you'd be able to hint at via Context. Here's what the above would look like via pseudocode:
function requestHandler():
Context.current.setPropagationStyleHintTo('Child'):
BackgroundJobSystem.enqueue(FileConversionTask)
BackgroundJobSystem.enqueue(AnalyticsTask)
This way, the Otel instrumentation for BackgroundJobSystem
would know how to relate the next Span it creates to the current Span. This hint would reset within further nested spans (e.g. any tasks that FileConversionTask
may enqueue would, by default, be connected via Links.
Some open questions that I don't have the answer to just yet:
- What makes sense as the default propagation style? My guess is this would be defined by the instrumentation library. E.g. Sidekiq's uses Links by default.
Should an instrumentation library be permitted to disregard this hint?- I would think yes: in the Sidekiq example, there would necessarily be the creation of both the
PRODUCER
andCONSUMER
Spans and you'd want it to apply to both. So the instrumentation library needs to be given some flexibility in interpretation. Also, making it a requirement would necessarily be a breaking change I would think?
- I would think yes: in the Sidekiq example, there would necessarily be the creation of both the
Additional context.
I was directed here from open-telemetry/opentelemetry-ruby-contrib#991 as a contributor thought this may make sense more generally.