-
Notifications
You must be signed in to change notification settings - Fork 246
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
feat: default tracer prototype #425
Conversation
open-telemetry/opentelemetry-specification#1063 has merged. It technically allows for what we have in this PR where |
acc30b2
to
5b68f28
Compare
5b68f28
to
dd924fb
Compare
Here's how the various options look from a client perspective: Static methods on
|
I've implemented the first option in #439. It is obviously a lot more invasive, but I think the result is better and more in the spirit of the spec. |
I agree. I'll go ahead and close this. |
I guess one thing that isn't in #439 is the default tracer (the OpenTelemetry.tracer delegate). Is this something we're interested in? If so, I can bring this PR back in some form. |
I don't think that's something we should do. As mentioned above:
|
Description
With the OTel Ruby API as it currently stands
Tracer
is the one stop shop for everything that a user needs / wants to do with a span. This design is intentional and was chosen for it's simplicity. There are currently questions around how interactions with context and the current span should be handled: see open-telemetry/opentelemetry-specification#1019.This description is ridiculously long as it assumes little to no familiarity with the Ruby API. If you are familiar with the project, skip the Changes in this PR section towards the bottom.
For folks less familiar with the project, I'll show how the API currently works for a handful scenarios, and then go on to explain the changes added in this PR and what improvements they bring.
Tracer operations
First, get a handle on a tracer
The rest of the examples use this tracer
Span creation
Start span
Start span in current context
Span and context managment
Read the current span
From the current (implicit) context
From an explicit context
Set span in a context
Implicit context
Explicit context
Execute block with span in a context
Changes in this PR
The
Tracer#current_context
andTracer#span_with_context
methods do not explicitly depend on state from a tracer instance, so they could be class (static) methods on a tracer. However, this introduces some unneccessary complications to the API.As an alternative solution, this PR introduces an easy to access default tracer on the top-level OpenTelemetry module. It's available as
OpenTelemetry.tracer
and can be used whenever a user needs to access tracer methods, but does not have an explicit handle on one.For example, users might want to grab the
current_span
out of the ether to add an attribute, or event.The
OpenTelemetry.tracer
method is just a delegate to the global tracer provider. When called without parameters, it returns a tracer named "default". It can also take arguments for name and version which becomes a shortcut forOpenTelemetry.tracer_provider('tracer-name', 'tracer-version')
.Alternatives
Originally I added a
default_tracer
method that delegates to the global tracer provider, obtains a tracer named 'default', and memoizes and returns the result. It has the benefit of not having to lookup the tracer each time it's invoked. I switched to thetracer
delegate method as it solves the same use case, is less verbose, and is usable in other scenarios. I think it's worth the tradeoff, but could be convinced otherwise.