-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Context interaction from Tracer/CorrelationContextManager #455
Comments
I'm confused. Is this issue in favor of removing Tracer? What would be left on the tracer if span operations are removed? |
On the Tracer we will still have the "Span" creation API which is important in order to be able to provide different implementations for the "Span". |
@dyladan Updated the description to make this clear, hope that helps ;) |
So the Tracer will no longer modify context, but may still read from the current context (in order to find parent for a span, etc). Does that mean |
@dyladan I would say most likely yes at this point. Similar with |
Be aware that this language will probably need to change if this proposal is accepted https://github.com/open-telemetry/opentelemetry-specification/pull/424/files#diff-ea4f4a46fe8755cf03f9fb3a6434cb0cR132 as it implies that the Tracer is accessing/setting context values |
@dyladan Oh definitely. This part will be updated if we proceed with this. |
+1 on this idea, but are there thoughts on being stricter on things like tracer having span setting methods? I like as much consistency as possible between APIs, today I'm able to run through an API I'm familiar with (Python), and quickly relate the concepts to other languages. If, for example, setting current span in the tracer becomes popular in one language, and is non-existent in the other language, people will have to remember that detail as a caveat. I personally advocate for exclusively having context set methods in a context util object, and disencouraging setter methods elsewhere. |
The conversation in open-telemetry/opentelemetry-specification#455 is specifying that the tracer is no longer responsible for handling the setting and getting of active spans. As such, named tracers would only be respnosible for creating new spans, but not for setting the active one. This implies that there tracers do not have their own active spans. In addition, there is a benefit of having a single active span, as it vastly simplifies the process to modify the current span (no need to explicitly retrieve the tracer responsible for getting the span).
The conversation in open-telemetry/opentelemetry-specification#455 is specifying that the tracer is no longer responsible for handling the setting and getting of active spans. As such, named tracers would only be responsible for creating new spans, but not for setting the active one. This implies that there tracers do not have their own active spans. In addition, there is a benefit of having a single active span, as it vastly simplifies the process to modify the current span (no need to explicitly retrieve the tracer responsible for getting the span).
@carlosalberto is there any update on this? In Python, I think I'd like to move out the span getter methods outside of the Tracer itself, which I think requires this detail to be made explicit in the spec. |
What is the benefit to being outside the Tracer? Something has to know the context key used to store the current span/correlationcontext/etc and assigning that role to a utils module seems odd. |
We are intending to start returning the span context and either the context or a context token from The issue is the need by some libraries to return to a previous context while it was originally built for returning only to a previous span context as the active span. {SpanCtx, Ctx} = ot_tracer:start_span("some-span"),
try
// some-span is the active span here and will be the parent
// of any span created in do_some_stuff()
do_some_stuff()
after
ot_span:end_span(SpanCtx),
ot_ctx:set_context(Ctx)
end. This ensures that if there is bad code in whatever Within a context the active span contexts are a list that prepends the new span it is created and a call to I think this has finally solved some of our issues, though I haven't opened the PR to move to this API yet. What I'm unsure about is CorrelationContext. if Maybe it should be? I'm not sure. I guess what I am rambling on towards is whether the API should |
One could also say that it is odd that you have to create a Tracer just to retrieve the current span (one could also say that's good though since then we know which instrumentation library accesses the span). EDIT: Also note that Propagators get a full Context, so they also need to retrieve the span from it, and it does seem odd for these to need a Tracer instance. |
This is (for me) the precise motivation with the separation. I think that the trace get / set methods need to be part of the module or package, but not part of the tracer object. Python has already divorced trace get / set methods from the tracer, which has made the code simpler:
vs
Erlang with it's actor model may not disambiguate between a module and a class instance, and at that point it wouldn't be as relevant.
This is a good pattern. We don't do that directly in Python, but we do offer an API to manually set an active span and get the context token to pop afterward: |
EDIT: This is largely a discussion ticket, and the action isn't as simple as writing a PR. I started a tangential discussion around package-level span getter / setters in this issue, and I'm creating a new ticket to reduce the confusion (#924) |
Actually, isn't this already done? AFAIK we only have optional convenience methods specified in the tracing API. |
Right. It is just a module and does not call into any process in order to look up the current context, it is just that the tracer module knows the key to use for lookup. So equivalent to I suppose it is more I objected to |
I think the key to the current span must not be in a generic ContextUtils class, since such a class should be one layer below and agnostic of concerns like tracing/metrics/baggage. E.g. in Java, this is handled in a class TracingContextUtils which is part of the trace API module. |
@bogdandrutu i had a look over this with @carlosalberto , it seems like this is possibly breaking API by removing methods in trace so would be good to get this change in before the freeze. |
This may be getting off topic but I just realized when discussing how we are doing context with others that there is the matter of CorrelationContext. I'm thinking specifically about the use of This works fine for spans but leaves CorrelationContext behind. How are other languages handling this? I know I've seen others creating inactive spans to pass to new processes/tasks/coroutines but don't recall them doing anything about CorrelationContext. I'll dig up examples of what I mean in case this isn't clear. |
Oh, good, I'm not the only one :) |
Fixes open-telemetry#455. The previous spec stated that the active span get / set behavior MUST behave the same across Tracers retrieved from the same TracerProvider. As such, the active span manipulation methods are better provided by the TracerProvider directly. As it is still cumbersome to retrieve the current TracerProvider simply to get the current span, add in the concept of a "Trace Package", that can provide utilty methods to delegate to the configured default TracerProvider. This enables a fluid interface to retrieve the current span: from opentelemetry import trace current_span = trace.get_current_span() To help maintain backwards compatibility, the Tracer may still expose active span methods.
Please check out #923, I think it addresses the major concern of this issue. EDIT: although the PR is somewhat related, it doesn't resolve the discussion, as Context interactions are still performed by the Trace-related code. |
Currently, the convenience methods are encouraged, not completely optional:
And I don't think there's a requirement to expose any get / set of active span elsewhere in the codebase. However, it is possible for a consumer to re-implement the behavior by replicating the Context interaction. |
Although I previously wrote +1, I'm switching my vote to a -1 as this has an impact on usability (e.g. starting and activating the tracer would not be possible in the same call), and I think this can also lead to proliferating boilerplate, such as naming the specific key that the span populates in the context. Also, I am moving my discussion around providing simpler active span get / set APIs to a new issue #924 |
…etry#923) * Moving active span interaction To TracerProvider Fixes open-telemetry#455. The previous spec stated that the active span get / set behavior MUST behave the same across Tracers retrieved from the same TracerProvider. As such, the active span manipulation methods are better provided by the TracerProvider directly. As it is still cumbersome to retrieve the current TracerProvider simply to get the current span, add in the concept of a "Trace Package", that can provide utilty methods to delegate to the configured default TracerProvider. This enables a fluid interface to retrieve the current span: from opentelemetry import trace current_span = trace.get_current_span() To help maintain backwards compatibility, the Tracer may still expose active span methods. * Adding missing entries for TracerProvider functionality * Addressing feedback * fixing lint (multiple blank lines) * Addressing feedback Removing the get / set current span methods from the TracerProvider. There is consensus that the functions should have the same behavior regardless of the TracerProvider. This change now means that the span retrieval methods can not be defined completely by the Trace Package. Moving the requirements up to the package level. * Addressing comments Selecting "Tracing Context Utilities" rather than "Trace Package" to provide clear guidance on languages that do not have static module-level functions. Adding a section on the ability to expose these as module-level functions to ensure that the simplified workflow of a top-level get / set span is possible. * fixing invalid Trace Package reference * removing unrelated change * adding changelog entry Co-authored-by: Carlos Alberto Cortez <calberto.cortez@gmail.com> Co-authored-by: Armin Ruech <armin.ruech@dynatrace.com>
From #424:
Should the
Context
interactions be part of theTracer
/CorrelationContextManager
, or can we have aContextUtil
class in the each package that handles this interaction? This would mean removing members such as:Tracer.getCurrentSpan()
CorrelationContextManager.getCurrentContext()
Now that
Context
is a well defined notion, probably we don't need an abstraction on top of it.The text was updated successfully, but these errors were encountered: