-
Notifications
You must be signed in to change notification settings - Fork 778
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
Replace TracerFactory with TracerProvider #576
Comments
@MikeGoldsmith , the PR that I create is renaming the TracerFactory* to TracerProvider*. I would like to know what else should we change to complete this. Thanks |
@eddynaka Do you still plan on working on this? I think I can take a stab at it if you aren't working on this. @MikeGoldsmith
|
@longility , ok! go for it! thanks :) |
I will try to have something by Monday if not sooner. |
@longility I am also looking at the config pieces , but feel free to go ahead with this approach. |
I have not been in gitter channel. I will try it out. I'll try to do things incrementally and get feedback. |
As I'm studying the code, it is a bit trickier so I'm going to need some feedback considering I'm a newbie in this codebase and may not see the impact. I would like to understand how we want to consume before going into implementation detail. I'm going to start with consumer usage taking our first example in the Currentusing (var tracerFactory = TracerFactory.Create(builder => builder
.UseZipkin(options => {})
.SetResource(Resources.CreateServiceResource("http-client-test")))
{
// Obtain Tracer from the factory above.
var tracer = tracerFactory.GetTracer("zipkin-test");
} ref https://github.com/open-telemetry/opentelemetry-dotnet#basic-configuration Option 1Remove usage and knowledge of using (var tracerProvider = TracerProvider.Create(builder => builder
.UseZipkin(options => {})
.SetResource(Resources.CreateServiceResource("http-client-test")))
{
// Obtain Tracer from the provider above.
var tracer = tracerProvider.GetTracer("zipkin-test");
} Option 2Expected knowledge and usage of using (var tracerFactory = TracerFactory.Create(builder => builder
.UseZipkin(options => {})
.SetResource(Resources.CreateServiceResource("http-client-test")))
using (var tracerProvider = TracerProvider.Create(tracerFactory))
{
// Obtain Tracer from the provider above.
var tracer = tracerProvider.GetTracer("zipkin-test");
} Option 3Expected knowledge and usage of using (var tracerFactory = TracerFactory.Create(builder => builder
.UseZipkin(options => {})
.SetResource(Resources.CreateServiceResource("http-client-test")))
{
// Obtain Tracer from the provider above.
var tracer = TracerProvider.Current.GetTracer("zipkin-test");
} Other options? Something else? I'm not used to this factory / singleton pattern so struggling a bit to mix. I tend to work on enterprise applications where I'm initializing lifetimes such as singleton at the DI container level. |
@longility TracerProvider is an API concept. https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#obtaining-a-tracer It must be implemented in API, so libraries who depend only on API can get a Tracer from TracerProvider. |
Thanks for catching that! You are right @cijothomas. |
Here I go with bold change proposals with limited experience and knowledge... Proposal1. TracerProvider not to be a singleton, separate object as singleton containerPrior ArtBoth go and js approaches this way. One difference between them is that go has one singleton container while js has specific singleton containers (i.e. one for metric and one for tracer). Thoughts
What it might look like (compared to options in other comment above)// configuration
var tracerProvider = new TracerProvider(builder => builder
.UseZipkin(options => {})
.SetResource(Resources.CreateServiceResource("http-client-test"));
OpenTelemetryApi.TracerProvider = tracerProvider; // singleton container...naming may need some work...
// usage
var tracer = OpenTelemetryApi.TracerProvider.GetTracer("zipkin-test"); OR similar to // configuration
var tracerProvider = new TracerProvider(builder => builder
.UseZipkin(options => {})
.SetResource(Resources.CreateServiceResource("http-client-test"));
TracerProvider.Current = tracerProvider;
// usage
var tracer = TracerProvider.Current.GetTracer("zipkin-test"); 2. More consistent naming with noop or default identifierPrior ArtBoth js and go have noop span, noop tracer, and noop tracer provider. Before I can approach and tackle this (assuming I'm capable and right person for the job), I would need guidance or feedback of proposals. |
Alright, I have a WIP that I'm actually comfortable with (slimmed down to allow better reviewing of approach): Not sure what the best way to communicate the change is. I'll do my best here.
Before I can go any further, I need feedback. I think I provided as much options and an approach that I'm comfortable with as a more refined proposal. |
@longility Thanks for sharing this. |
I will answer based on current WIP commit and focused on your question here. If the SDK is not initialized, calling When I will follow up with your comments in the commit in a bit. |
As mentioned in the PR - the issue not solved is when libraries call TracerProvider.GlobalInstance, before SDK is done iniitalizing (i.e setting GlobalInstance = this in your PR), then the library will always live with the NoOp. Libraries mostly get Tracer once at its startup and then cache it. |
That comment helped. Updated v2 at April 27th, 7:30 AM CST@cijothomas here is v2 based on your feedback.
Usage (added 8:12 AM CST)// this is the initial tracer factory with NoopTracerProvider as the associated tracer provider
TracerFactory.Default;
// this gets the proxy tracer which points to the default noop tracer provider
TracerFactory.GetTracer(..);
// create new tracer factory with TracerProviderSdk
var sdkTracerFactory = new TracerFactory(TracerProviderSdk.Create(b => b...));
// Sets new default and updates proxy tracer like how it was doing before.
TracerFactory.SetDefault(sdkTracerFactory);
// points to the new default tracer provider's get tracer
TracerFactory.GetTracer(..);
// support multiple tracer factories
var tracerFactory2 = new TracerFactory(TracerProviderSdk.Create(b => b...));
// throws exception. only allow to set one default like how it was doing before. no change.
TracerFactory.SetDefault(tracerFactory2); Question (added 8:27 AM CST)With this approach, do we need to support multiple tracer factories, or can we simplify by having only one tracer factory where we would set a default // this is the default tracer provider, which is NoopTracerProvider
TracerFactory.Default;
// this gets the proxy tracer which points to the default noop tracer provider
TracerFactory.GetTracer(..);
// Sets TracerProviderSdk as new default and updates proxy tracer like how it was doing before.
TracerFactory.SetDefault(TracerProviderSdk.Create(b => b...));
// points to the new default tracer provider's get tracer
TracerFactory.GetTracer(..);
// support multiple tracer providers
var tracerProviderSdk2 = TracerProviderSdk.Create(b => b...);
// throws exception. only allow to set one default like how it was doing before. no change.
TracerFactory.SetDefault(tracerProviderSdk2); |
@longility Can you open PRs in draft mode with your changes? This makes it easier to try out things. Once we are ready, simply mark PR as ready for final review from draft mode. |
@cijothomas #641 has WIP with two meaningful commit: 1 refactor and 1 wip introduce tracer provider. If we want to split into two PRs, one dependent on the other, we can do that. Let me know what is best to review and tackle this as this is pretty large. I'm very comfortable with git to break things up as needed. I just have it all together so that you have a full working branch to try out things. |
Done. |
…metry#576) Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
Once the API (#573) has TraceProvider defined, the SDK also needs to implement it. We currently use a TracerFactory to build tracers, we can probably move most of the logic from that to the TracerProvider implementation.
https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#tracer-creation
The text was updated successfully, but these errors were encountered: