Skip to content
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

bridge/opentracing: introduce NewTracerProvider that wraps TracerProvider instead of Tracer #3116

Merged

Conversation

bobheadxi
Copy link
Contributor

@bobheadxi bobheadxi commented Aug 26, 2022

Currently, using the OpenTracing bridge tracer pairs, e.g. NewTracerPair, means that all tracing is named with the tracer initially provided to WrappedTracerProvider - calls to Trace() with names and options always returns the same tracer.

This change creates a new opentracing.TracerProvider to allow it to accept trace.TracerProviders and create named/configured tracers dynamically with bridging configured, and adds a new constructor, opentracing.NewTracerProvider, that accepts trace.TracerProvider. It also marks the old static constructor NewWrappedTracerProvider as deprecated.

There is an example usage here: sourcegraph/sourcegraph#40945 . See discussion on this PR for more details.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 26, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: bobheadxi / name: Robert Lin (0ffe14b)

@codecov
Copy link

codecov bot commented Aug 27, 2022

Codecov Report

Merging #3116 (b421d60) into main (89cb6a4) will increase coverage by 0.0%.
The diff coverage is 100.0%.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #3116   +/-   ##
=====================================
  Coverage   78.9%   78.9%           
=====================================
  Files        169     170    +1     
  Lines      12437   12460   +23     
=====================================
+ Hits        9813    9836   +23     
  Misses      2415    2415           
  Partials     209     209           
Impacted Files Coverage Δ
bridge/opentracing/wrapper.go 100.0% <ø> (ø)
bridge/opentracing/provider.go 100.0% <100.0%> (ø)

@dmathieu
Copy link
Member

While this makes sense, it creates a new wrapped tracer every time Tracer() is called, which may cause performance issues.

@bobheadxi
Copy link
Contributor Author

bobheadxi commented Aug 29, 2022

While this makes sense, it creates a new wrapped tracer every time Tracer() is called, which may cause performance issues.

The wrapped tracer is a very lightweight struct, and the creation of the underlying Tracer has some caching of created Tracers already: https://sourcegraph.com/github.com/open-telemetry/opentelemetry-go/-/blob/internal/global/trace.go?L83-110

However @dmathieu I can implement a similar approach here when creating wrapped tracers if that would make this change acceptable!

@bobheadxi
Copy link
Contributor Author

@dmathieu I've added a caching layer and testing in 8a83e1f

@dmathieu
Copy link
Member

Thank you. I'm personally not super fond of the name NewDynamicWrappedTracerProvider, but I'm not finding any.
I wonder if we should deprecate NewWrappedTracerProvider as well, to avoid keeping both methods around.

@bobheadxi
Copy link
Contributor Author

bobheadxi commented Aug 31, 2022

Thank you. I'm personally not super fond of the name NewDynamicWrappedTracerProvider,

What do you think about the name NewBridgedTracerProvider? It indicates that it provides tracers that bridges requests to OpenTracing as well, which is a bit clearer IMO than just saying the provider is wrapped.

Alternatively, maybe a simple NewTracerProvider will suffice? We are exporting it from a bridge package after all - (bridge/opentracing).NewTracerProvider(...) (otel/trace.TracerProvider) reads reasonably well I think

I wonder if we should deprecate NewWrappedTracerProvider as well, to avoid keeping both methods around.

I can add a deprecation godoc to the other constructor!

@dmathieu
Copy link
Member

dmathieu commented Sep 1, 2022

You're right, NewTracerProvider may be good.
Let's wait for opinions from other approvers/maintainers about all this.

@bobheadxi bobheadxi force-pushed the dynamic-wrapped-tracer-provider branch from d53de5d to 59f2c6b Compare September 1, 2022 15:42
@bobheadxi
Copy link
Contributor Author

bobheadxi commented Sep 1, 2022

59f2c6b renames the constructor and adds a deprecation notice to NewWrappedTracerProvider.

It might be valuable to provide new variants of NewTracerPair and NewTracerPairWithContext as well and deprecate the existing utility constructors, but the naming gets clunky, for example:

  • NewTracerPairWithProvider(trace.TracerProvider)
  • NewTracerPairWithProviderAndContext(context.Context, trace.TracerProvider)

We could also introduce new naming like:

  • NewBridgeTracers(trace.TracerProvider) (or simply NewBridge(trace.TracerProvider))
  • NewBridgeTracersWithContext(context.Context, trace.TracerProvider) (or simply NewBridgeWithContext(context.Context, trace.TracerProvider))

Alternatively, we could also deprecate the utilities entirely and rely on users to replicate the setup themselves.

Let me know what you think!

@bobheadxi bobheadxi changed the title bridge/opentracing: add NewDynamicWrappedTracerProvider for named tracers bridge/opentracing: allow WrapperTracerProvider to accept TracerProviders Sep 1, 2022
@bobheadxi
Copy link
Contributor Author

hey @dmathieu, any chance this PR might get another round of reviews? The lack of appropriate Tracer naming in emitted traces is making it difficult at times to narrow down where trace spans are coming from.

bridge/opentracing/wrapper.go Outdated Show resolved Hide resolved
bridge/opentracing/wrapper.go Outdated Show resolved Hide resolved
bridge/opentracing/wrapper.go Outdated Show resolved Hide resolved
@bobheadxi bobheadxi changed the title bridge/opentracing: allow WrapperTracerProvider to accept TracerProviders bridge/opentracing: introduce NewTracerProvider that wraps TracerProvider instead of Tracer Nov 21, 2022
@bobheadxi
Copy link
Contributor Author

@dmathieu @MrAlias - I've addressed the review comments, could one you please take another look when you get the chance? Thank you!

@bobheadxi
Copy link
Contributor Author

bobheadxi commented Jan 11, 2023

Thanks for the review @dmathieu - addressed your last comment, and all checks seem to be green :) (I'm not authorized to merge, so would appreciate some help with that 🙏 )

@MrAlias MrAlias merged commit 640a0cd into open-telemetry:main Jan 12, 2023
@MrAlias MrAlias added this to the Release v1.12.0 milestone Jan 27, 2023
@MrAlias MrAlias mentioned this pull request Jan 28, 2023
bobheadxi added a commit to sourcegraph/sourcegraph that referenced this pull request Feb 23, 2023
…0945)

The existing wrapped OpenTelemetry TracerProvider for bridging
OpenTracing API calls to OpenTelemetryAPI calls discards the name
provided to the `Tracer()` constructor on it, since it uses a fixed
tracer that we provide it.

This change leverages an upstream patch,
open-telemetry/opentelemetry-go#3116 (dependency
update: #47126), that
allows wrapped tracers to be created on the fly with the provided
parameters, so that we can more accurately see the instrumentation
source.

## Test plan

Via the bridge, we can see that the Tracer used is the bridge tracer:

<img width="1322" alt="image"
src="https://user-images.githubusercontent.com/23356519/186957763-60faee32-e6a5-4bda-bb64-fddb82eacc0d.png">

Via direct usage of OpenTelemetry, we can see that the Tracer used has
the custom name set:

<img width="1448" alt="image"
src="https://user-images.githubusercontent.com/23356519/186957773-c6ff7643-3f89-498d-857b-1dd79b36508d.png">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants