mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-11-28 08:38:51 +02:00
Avoid creating new references on WithDeferredSetup
for every span (#3833)
* Avoid creating new references on WithDeferredSetup call
This commit is contained in:
parent
3df561e644
commit
3015c86cfd
@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Avoid creating new objects on all calls to `WithDeferredSetup` and `SkipContextSetup` in OpenTracing bridge. (#3833)
|
||||||
|
|
||||||
## [1.15.0-rc.1/0.38.0-rc.1] 2023-03-01
|
## [1.15.0-rc.1/0.38.0-rc.1] 2023-03-01
|
||||||
|
|
||||||
This is a release candidate for the v1.15.0/v0.38.0 release.
|
This is a release candidate for the v1.15.0/v0.38.0 release.
|
||||||
|
@ -20,15 +20,20 @@ import (
|
|||||||
|
|
||||||
type doDeferredContextSetupType struct{}
|
type doDeferredContextSetupType struct{}
|
||||||
|
|
||||||
|
var (
|
||||||
|
doDeferredContextSetupTypeKey = doDeferredContextSetupType{}
|
||||||
|
doDeferredContextSetupTypeValue = doDeferredContextSetupType{}
|
||||||
|
)
|
||||||
|
|
||||||
// WithDeferredSetup returns a context that can tell the OpenTelemetry
|
// WithDeferredSetup returns a context that can tell the OpenTelemetry
|
||||||
// tracer to skip the context setup in the Start() function.
|
// tracer to skip the context setup in the Start() function.
|
||||||
func WithDeferredSetup(ctx context.Context) context.Context {
|
func WithDeferredSetup(ctx context.Context) context.Context {
|
||||||
return context.WithValue(ctx, doDeferredContextSetupType{}, doDeferredContextSetupType{})
|
return context.WithValue(ctx, doDeferredContextSetupTypeKey, doDeferredContextSetupTypeValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SkipContextSetup can tell the OpenTelemetry tracer to skip the
|
// SkipContextSetup can tell the OpenTelemetry tracer to skip the
|
||||||
// context setup during the span creation in the Start() function.
|
// context setup during the span creation in the Start() function.
|
||||||
func SkipContextSetup(ctx context.Context) bool {
|
func SkipContextSetup(ctx context.Context) bool {
|
||||||
_, ok := ctx.Value(doDeferredContextSetupType{}).(doDeferredContextSetupType)
|
_, ok := ctx.Value(doDeferredContextSetupTypeKey).(doDeferredContextSetupType)
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user