-
Notifications
You must be signed in to change notification settings - Fork 244
feat: support to inject tracerProvider #1202
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ package client | |
|
|
||
| import ( | ||
| "go.opentelemetry.io/otel/attribute" | ||
| "go.opentelemetry.io/otel/trace" | ||
|
|
||
| cloudevents "github.com/cloudevents/sdk-go/v2" | ||
| "github.com/cloudevents/sdk-go/v2/observability" | ||
|
|
@@ -37,6 +38,15 @@ func WithSpanNameFormatter(nameFormatter func(cloudevents.Event) string) OTelObs | |
| } | ||
| } | ||
|
|
||
| // WithTracerProvider sets the tracer provider to use for creating spans. | ||
| func WithTracerProvider(tracerProvider trace.TracerProvider) OTelObservabilityServiceOption { | ||
| return func(os *OTelObservabilityService) { | ||
| if tracerProvider != nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not let them set it to 'nil' if they want?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To prevent, panic. https://github.com/open-telemetry/opentelemetry-go/blob/trace/v1.38.0/trace/noop/noop.go#L36 I think it's the same context with #1202 (comment) |
||
| os.traceProvider = tracerProvider | ||
| } | ||
| } | ||
| } | ||
|
|
||
| var defaultSpanNameFormatter func(cloudevents.Event) string = func(e cloudevents.Event) string { | ||
| return observability.ClientSpanName + "." + e.Context.GetType() | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better/safer to check o.traceProvider for 'nil' and either set tracer to nil or call o.traceProvider.Tracer ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know oTel, but if you allow/check for nil then you can decide if 'nil' for traceProvider means 'nil' for 'tracer too, or to default traceProvider to otel.GetTracerProvider()
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed the below rule. I think it's very useful way to set a guard.
open-telemetry/opentelemetry-go-contrib#1104
ref. open-telemetry/opentelemetry-go-contrib#1107