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

CorrelationContext -> Baggage #1106

Merged
merged 23 commits into from
Aug 27, 2020

Conversation

CodeBlanch
Copy link
Member

@CodeBlanch CodeBlanch commented Aug 20, 2020

Changes

We talked on the last SIG about changing the work done on #1048 so that it isn't built on top of Activity.Baggage.

  • Baggage implements the CorrelationContext Baggage API spec entirely, with some additions for perf and usability.
  • BaggageFormat will propagate Baggage in the W3C Baggage header.
  • Took inspiration from Java & Python libs.

TODO:

  • Changes in public API reviewed (this).
  • Code building.
  • Tests passing.
  • CHANGELOG updates.

namespace OpenTelemetry.Context
{
/// <summary>
/// Baggage context.
Copy link
Member

Choose a reason for hiding this comment

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

nit: Add a link to OTel spec here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. It's a dead link right now, but should work once the rename PR is merged.

/// <summary>
/// Baggage context.
/// </summary>
public readonly struct BaggageContext : IEquatable<BaggageContext>
Copy link
Member

Choose a reason for hiding this comment

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

I think we should name it just Baggage.
https://w3c.github.io/baggage/

Copy link
Member

Choose a reason for hiding this comment

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

I have a different opinion on this. This is similar to the fact that we have SpanContext while W3C has TraceContext.
The W3C spec is describing the wire format. The in process representation and class name don't have to (or even should not) follow a name mentioned in the wire format spec.

Copy link
Member

Choose a reason for hiding this comment

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

We can call it whatever OpenTelemetry spec decide to call it. It looked to me like the plan is to replace CorrelationContext to Baggage.
open-telemetry/opentelemetry-specification#536
If its called BaggageContext, then we are good here.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, totally agree. We should follow the OpenTelemetry spec (unless the name is already taken by .NET - such like Span 😆).

Copy link
Member Author

Choose a reason for hiding this comment

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

When I was doing this work, I had it called "Baggage" initially. But for some reason, I felt like the spec would stick with keeping "Context" in the name and it would end up being "BaggageContext" instead. It's really just a guess, we can always rename when it settles?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, lets keep BaggageContext for now.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed name to Baggage

@cijothomas
Copy link
Member

@CodeBlanch the overall approach looks good! Please mark as non-draft when you are ready.

@MikeGoldsmith MikeGoldsmith self-requested a review August 21, 2020 08:28
@codecov
Copy link

codecov bot commented Aug 22, 2020

Codecov Report

Merging #1106 into master will increase coverage by 0.31%.
The diff coverage is 93.06%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1106      +/-   ##
==========================================
+ Coverage   77.41%   77.73%   +0.31%     
==========================================
  Files         219      219              
  Lines        6270     6279       +9     
==========================================
+ Hits         4854     4881      +27     
+ Misses       1416     1398      -18     
Impacted Files Coverage Δ
src/OpenTelemetry.Api/Metrics/MeasureMetric.cs 25.00% <0.00%> (ø)
...penTelemetry.Api/Metrics/NoopBoundCounterMetric.cs 0.00% <ø> (ø)
...penTelemetry.Api/Metrics/NoopBoundMeasureMetric.cs 0.00% <ø> (ø)
src/OpenTelemetry.Api/Metrics/NoopCounterMetric.cs 14.28% <ø> (ø)
src/OpenTelemetry.Api/Trace/TelemetrySpan.cs 88.23% <ø> (+4.45%) ⬆️
...enTelemetry/Metrics/DoubleBoundCounterMetricSdk.cs 75.00% <ø> (ø)
...enTelemetry/Metrics/DoubleBoundMeasureMetricSdk.cs 0.00% <ø> (ø)
...rc/OpenTelemetry/Metrics/DoubleCounterMetricSdk.cs 45.45% <ø> (ø)
...penTelemetry/Metrics/Int64BoundCounterMetricSdk.cs 75.00% <ø> (ø)
...penTelemetry/Metrics/Int64BoundMeasureMetricSdk.cs 66.66% <ø> (ø)
... and 15 more

@CodeBlanch CodeBlanch changed the title Baggage Context CorrelationContext -> Baggage Aug 26, 2020
@CodeBlanch CodeBlanch marked this pull request as ready for review August 26, 2020 05:51
@CodeBlanch CodeBlanch requested a review from a team August 26, 2020 05:51
/// <returns>New <see cref="Baggage"/> containing the key/value pair.</returns>
public Baggage RemoveBaggage(string name)
{
var baggage = new Dictionary<string, string>(this.baggage ?? EmptyBaggage, StringComparer.OrdinalIgnoreCase);
Copy link
Member

Choose a reason for hiding this comment

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

minor: if the key does not exist, we might be able to return the same baggage?

Copy link
Member

Choose a reason for hiding this comment

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

I guess it is not important at this stage, and we probably will replace dictionary with a better data structure before GA anyways.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK I'll leave as is. I did consider that case. I figured if user is calling RemoveBaggage, they probably know it exists. So I didn't want to waste perf doing a hash + lookup where in most cases it would be wasteful? My thinking could be off tho.

Copy link
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

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

LGTM.


HttpRequestMessage thisRequest = (HttpRequestMessage)activity.GetCustomProperty(HttpHandlerDiagnosticListener.RequestCustomPropertyName);

string[] correlationContext = thisRequest.Headers.GetValues("Correlation-Context").First().Split(',');
Copy link
Member

Choose a reason for hiding this comment

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

this is not a feature of Otel right? do we want to test it?

@cijothomas
Copy link
Member

No blocking comments. Merging. We can write docs/examples as follow ups.

@cijothomas cijothomas merged commit d11dc0a into open-telemetry:master Aug 27, 2020
@CodeBlanch CodeBlanch deleted the baggage-context branch August 28, 2020 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants