Skip to content

Conversation

@minuk-dev
Copy link

  • There is no option to inject tracerProvider instead of global provider
  • So, add WithTracerProvider as an option.

@minuk-dev minuk-dev requested a review from a team as a code owner November 9, 2025 15:18
@minuk-dev minuk-dev force-pushed the observability-tracerprovider branch from c9b228e to 6cb85f2 Compare November 9, 2025 15:19
// WithTracerProvider sets the tracer provider to use for creating spans.
func WithTracerProvider(tracerProvider trace.TracerProvider) OTelObservabilityServiceOption {
return func(os *OTelObservabilityService) {
if tracerProvider != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not let them set it to 'nil' if they want?

Copy link
Author

@minuk-dev minuk-dev Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prevent, panic.
If someone want to disable trace, we can use noop.TracerProvider.

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)

// OTelObservabilityService implements the ObservabilityService interface from cloudevents
type OTelObservabilityService struct {
traceProvider trace.TracerProvider

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this blank line? If anything I would expect 'traceProvider' and 'tracer' to be grouped and the blank line after 'tracer'. But I'm not sure we need a line break with only 4 fields

opt(o)
}

o.tracer = o.traceProvider.Tracer(
Copy link
Contributor

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 ?

Copy link
Contributor

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()

Copy link
Author

@minuk-dev minuk-dev Nov 10, 2025

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

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.

2 participants