Skip to content

Commit

Permalink
Avoid creating new references on WithDeferredSetup for every span (#…
Browse files Browse the repository at this point in the history
…3833)

* Avoid creating new references on WithDeferredSetup call
  • Loading branch information
alanprot committed Mar 7, 2023
1 parent 3df561e commit 3015c86
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [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

This is a release candidate for the v1.15.0/v0.38.0 release.
Expand Down
9 changes: 7 additions & 2 deletions bridge/opentracing/migration/defer.go
Expand Up @@ -20,15 +20,20 @@ import (

type doDeferredContextSetupType struct{}

var (
doDeferredContextSetupTypeKey = doDeferredContextSetupType{}
doDeferredContextSetupTypeValue = doDeferredContextSetupType{}
)

// WithDeferredSetup returns a context that can tell the OpenTelemetry
// tracer to skip the context setup in the Start() function.
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
// context setup during the span creation in the Start() function.
func SkipContextSetup(ctx context.Context) bool {
_, ok := ctx.Value(doDeferredContextSetupType{}).(doDeferredContextSetupType)
_, ok := ctx.Value(doDeferredContextSetupTypeKey).(doDeferredContextSetupType)
return ok
}

0 comments on commit 3015c86

Please sign in to comment.