Add delegating global propagator#1258
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1258 +/- ##
========================================
- Coverage 76.7% 76.4% -0.3%
========================================
Files 131 132 +1
Lines 5903 5926 +23
========================================
+ Hits 4531 4532 +1
- Misses 1120 1142 +22
Partials 252 252
|
|
Blipping to see if the CLA bot is working now. |
|
With #1259 merged I was able to just add the tests here. |
This reverts commit af7ae17.
|
Pulled the addition of tests out so they can more easily be reviewed in their own PR. |
| return p.noop.Extract(ctx, carrier) | ||
| } | ||
|
|
||
| // Fields returns the keys who's values are set with Inject. |
|
|
||
| // Inject set cross-cutting concerns from the Context into the carrier. | ||
| func (p *textMapPropagator) Inject(ctx context.Context, carrier otel.TextMapCarrier) { | ||
| if p.HasDelegate() { |
There was a problem hiding this comment.
Both here and in (*textMapPropagator).Fields, it would be safer to use the value read while holding the mutex. Sketching:
p.mtx.Lock()
delegate := p.delegate
p.mtx.Unlock()
if delegate == nil {
delegate = p.noop
}
delegate.Inject(ctx, carrier)You could introduce a helper method to make that more concise:
func (p *textMapPropagator) currentDelegate() otel.TextMapPropagator {
p.mtx.Lock()
defer p.mtx.Unlock()
return p.delegate
}
func (p *textMapPropagator) HasDelegate() bool {
return p.currentDelegate() != nil
}There was a problem hiding this comment.
This seems good. I was basing this off the fact that the delegate only ever changes from nil to not nil, and it only does this once, but I think you're approach doesn't add overhead and guards against future changes invalidating these assumptions. I'll open a PR to address your feedback. Thanks.
Include feedback from a post-merge review of open-telemetry#1258
* 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>
* Add delegating global propagator * Add Changes to CHANGELOG * Add PR number to CHANGELOG * Add tests using new test framework * Revert "Add tests using new test framework" This reverts commit af7ae17.
* Update the internal global TextMapPropagator Include feedback from a post-merge review of open-telemetry#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>
The
api/globalTextMapPropagator now delegates functionality to a globally set delegate for all previously returned propagators.This does not include tests. I have them lined up but they use new propagator testing utils in the
oteltestpackage that are going to be in a PR shortly following this being opened. Once that is merged I can submit the tests for this.Resolves #1257