-
Notifications
You must be signed in to change notification settings - Fork 440
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
[EXAMPLE] Use of WithActiveSpan() is confusing #2418
Comments
I think if you want to explicitly
{
...
// start span with parent context extracted from http header **and make it the active one**
auto span = get_tracer("http-server")->StartSpan(span_name, {}, options);
auto scope = Scope(span );
...
span ->AddEvent(...);
...
// if really required...
span->End();
} |
Well, what I would like is to avoid to have to explicitly activate the
It does the job. Unless I missed something... |
Bonjour @nleclercq The span Keeping a pointer on the span to call End() allows to pass Most of the time, end span options are not needed, but when passing an end timestamp is required, the call to End(option) must be explicit. Having the Scope class calling The Scope class is designed to maintain the current active span in thread local storage (the runtime context), but does not interfere with the span given. Note that when nothing calls End(), when the shared pointer on the span is destroyed, the span destructor is called, which will End() the span if not already done. |
Instead of a Scope::Span() method, the following is preferred:
Now, this issue also exposed that the following code is confusing:
WithActiveSpan is a static method, calling it using an object is misleading. Considering that WithActiveSpan only creates a Scope, this code in the examples can be rewritten as:
Keeping this issue opened to address this part. |
Ok, I see. I'm going to adopt the proposed impl. Thanks. |
This issue was marked as stale due to lack of activity. |
In the provided
http
example, the server does the following upon reception of a client request:I can hardly figure out why the
span
is created, then explicitly activated. I would expect something like:Ok, one could argue that there's now no way to explicitly
End
the span. Ok, but why not simply add an accessor to the underlying Span toopenTelemetry::trace::Scope
? Something like:Would that violate a design choice or the Scope paradigm?
The text was updated successfully, but these errors were encountered: