1
0
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:
Alan Protasio 2023-03-07 05:40:31 -08:00 committed by GitHub
parent 3df561e644
commit 3015c86cfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -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.

View File

@ -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
} }