mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-02-03 13:11:53 +02:00
Update the internal global TextMapPropagator (#1261)
* Update the internal global TextMapPropagator Include feedback from a post-merge review of #1258 * Apply feedback * Update api/global/internal/propagator.go Co-authored-by: Steven E. Harris <seh@panix.com> Co-authored-by: Steven E. Harris <seh@panix.com>
This commit is contained in:
parent
ec300b28ad
commit
b7197d568f
@ -54,33 +54,29 @@ func (p *textMapPropagator) SetDelegate(delegate otel.TextMapPropagator) {
|
|||||||
p.mtx.Unlock()
|
p.mtx.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasDelegate returns if a delegate is set for p.
|
// effectiveDelegate returns the current delegate of p if one is set,
|
||||||
func (p *textMapPropagator) HasDelegate() bool {
|
// otherwise the default noop TextMapPropagator is returned. This method
|
||||||
|
// can be called concurrently.
|
||||||
|
func (p *textMapPropagator) effectiveDelegate() otel.TextMapPropagator {
|
||||||
p.mtx.Lock()
|
p.mtx.Lock()
|
||||||
defer p.mtx.Unlock()
|
defer p.mtx.Unlock()
|
||||||
return p.delegate != nil
|
if p.delegate != nil {
|
||||||
|
return p.delegate
|
||||||
|
}
|
||||||
|
return p.noop
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject set cross-cutting concerns from the Context into the carrier.
|
// Inject set cross-cutting concerns from the Context into the carrier.
|
||||||
func (p *textMapPropagator) Inject(ctx context.Context, carrier otel.TextMapCarrier) {
|
func (p *textMapPropagator) Inject(ctx context.Context, carrier otel.TextMapCarrier) {
|
||||||
if p.HasDelegate() {
|
p.effectiveDelegate().Inject(ctx, carrier)
|
||||||
p.delegate.Inject(ctx, carrier)
|
|
||||||
}
|
|
||||||
p.noop.Inject(ctx, carrier)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract reads cross-cutting concerns from the carrier into a Context.
|
// Extract reads cross-cutting concerns from the carrier into a Context.
|
||||||
func (p *textMapPropagator) Extract(ctx context.Context, carrier otel.TextMapCarrier) context.Context {
|
func (p *textMapPropagator) Extract(ctx context.Context, carrier otel.TextMapCarrier) context.Context {
|
||||||
if p.HasDelegate() {
|
return p.effectiveDelegate().Extract(ctx, carrier)
|
||||||
return p.delegate.Extract(ctx, carrier)
|
|
||||||
}
|
|
||||||
return p.noop.Extract(ctx, carrier)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fields returns the keys who's values are set with Inject.
|
// Fields returns the keys whose values are set with Inject.
|
||||||
func (p *textMapPropagator) Fields() []string {
|
func (p *textMapPropagator) Fields() []string {
|
||||||
if p.HasDelegate() {
|
return p.effectiveDelegate().Fields()
|
||||||
return p.delegate.Fields()
|
|
||||||
}
|
|
||||||
return p.noop.Fields()
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user