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

Inconsistent global set behavior #2140

Closed
MrAlias opened this issue Jul 28, 2021 · 2 comments · Fixed by #2160
Closed

Inconsistent global set behavior #2140

MrAlias opened this issue Jul 28, 2021 · 2 comments · Fixed by #2160
Assignees
Labels
bug Something isn't working

Comments

@MrAlias
Copy link
Contributor

MrAlias commented Jul 28, 2021

Description

The global TextMapPropagator, MeterProvider, and TracerProvider can be set as many times as the user wants to call the appropriate set method.

globalTracer.Store(tracerProviderHolder{tp: tp})

globalMeter.Store(meterProviderHolder{mp: mp})

globalPropagators.Store(propagatorsHolder{tm: p})

The global ErrorHandler can only be set once. Subsequent calls to SetErrorHandler are ignored.

// SetErrorHandler sets the global ErrorHandler to be h.
func SetErrorHandler(h ErrorHandler) {
delegateErrorHandlerOnce.Do(func() {
current := GetErrorHandler()
if current == h {
return
}
if internalHandler, ok := current.(*loggingErrorHandler); ok {
internalHandler.setDelegate(h)
}
})
}

Expected behavior

This inconsistent behavior needs to be made consistent.

@MrAlias MrAlias added the bug Something isn't working label Jul 28, 2021
@pellared
Copy link
Member

pellared commented Jul 29, 2021

My opinion: we should allow setting as many times as the user wants to call the appropriate set method.

Why? Even for the sake of unit testing. Example: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/00f202e858996b1600131b021e810d17f93fb6d6/instrumentation/github.com/emicklei/go-restful/otelrestful/restful_test.go#L149-L176

Just to confirm. Is it possible to get a "current" value to be able to make some set+revert logic?

@MrAlias
Copy link
Contributor Author

MrAlias commented Jul 29, 2021

Just to confirm. Is it possible to get a "current" value to be able to make some set+revert logic?

Yes. There should be a corresponding Get* function for any Set* function (e.g. this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants