Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delegating global propagator #1258

Merged
merged 6 commits into from
Oct 15, 2020

Conversation

MrAlias
Copy link
Contributor

@MrAlias MrAlias commented Oct 15, 2020

The api/global TextMapPropagator 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 oteltest package 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

@MrAlias MrAlias added bug Something isn't working pkg:API Related to an API package area:propagators Part of OpenTelemetry context propagation release:required-for-ga labels Oct 15, 2020
@MrAlias MrAlias added this to the RC1 milestone Oct 15, 2020
@MrAlias MrAlias self-assigned this Oct 15, 2020
@codecov
Copy link

codecov bot commented Oct 15, 2020

Codecov Report

Merging #1258 into master will decrease coverage by 0.2%.
The diff coverage is 12.0%.

Impacted file tree graph

@@           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             
Impacted Files Coverage Δ
api/global/internal/propagator.go 10.5% <10.5%> (ø)
api/global/internal/state.go 70.2% <16.6%> (-11.6%) ⬇️

@MrAlias
Copy link
Contributor Author

MrAlias commented Oct 15, 2020

Blipping to see if the CLA bot is working now.

@MrAlias MrAlias closed this Oct 15, 2020
@MrAlias MrAlias reopened this Oct 15, 2020
@MrAlias
Copy link
Contributor Author

MrAlias commented Oct 15, 2020

With #1259 merged I was able to just add the tests here.

@MrAlias
Copy link
Contributor Author

MrAlias commented Oct 15, 2020

Pulled the addition of tests out so they can more easily be reviewed in their own PR.

@MrAlias MrAlias merged commit 786a78e into open-telemetry:master Oct 15, 2020
@MrAlias MrAlias deleted the global-propagators branch October 15, 2020 17:35
return p.noop.Extract(ctx, carrier)
}

// Fields returns the keys who's values are set with Inject.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/who's/whose/


// Inject set cross-cutting concerns from the Context into the carrier.
func (p *textMapPropagator) Inject(ctx context.Context, carrier otel.TextMapCarrier) {
if p.HasDelegate() {
Copy link
Contributor

@seh seh Oct 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

MrAlias added a commit to MrAlias/opentelemetry-go that referenced this pull request Oct 15, 2020
Include feedback from a post-merge review of open-telemetry#1258
MrAlias added a commit that referenced this pull request Oct 17, 2020
* 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>
@MrAlias MrAlias mentioned this pull request Nov 20, 2020
AzfaarQureshi pushed a commit to open-o11y/opentelemetry-go that referenced this pull request Dec 3, 2020
* 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.
AzfaarQureshi pushed a commit to open-o11y/opentelemetry-go that referenced this pull request Dec 3, 2020
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:propagators Part of OpenTelemetry context propagation bug Something isn't working pkg:API Related to an API package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The global TextMapPropagator should delegate after being set
4 participants