-
Notifications
You must be signed in to change notification settings - Fork 774
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
Baggage + CorrelationContext improvements by Eddy & Mike #1048
Conversation
src/OpenTelemetry.Instrumentation.Http/HttpWebRequestInstrumentationOptions.netfx.cs
Outdated
Show resolved
Hide resolved
/// </summary> | ||
public static CorrelationContext Empty { get; } = new CorrelationContext(EmptyList); | ||
public IEnumerable<KeyValuePair<string, string>> Correlations => this.activity?.Baggage ?? EmptyBaggage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple questions:
- Would there be memory allocation concern?
- What would happen if a consumer gets the IEnumerable and tries to iterate through it, while the underlying baggage got modified?
- Does this enforce immutability? https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/correlationcontext/api.md#get-correlations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would there be memory allocation concern?
Check out the underlying Activity.Baggage enumeration:
https://github.com/dotnet/runtime/blob/ead2cd50799ecc523e23f50e50b54d8a30d0aa4f/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs#L290
Right below that method is the get.
The memory won't be too bad. An allocation for the state thing generated by the compiler due to the yield
. The internal storage is a LinkedList, not great for searching. O(N)?
What would happen if a consumer gets the IEnumerable and tries to iterate through it, while the underlying baggage got modified?
I think the way the LinkedList works under the hood, it would actually be OK. User can only add to the back of the list. So if you were enumerating you would also consume that new one when you got to the tail.
Does this enforce immutability?
I think so. The enumeration is returning the KVPs. They are structs, so you essentially get a copy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, love the fact that we've removed more lines than we added 👍
I think this is ready for a proper review. There seems to be a couple of flaky tests. Don't seem to be related to the changes. I'll keep digging on those. @cijothomas Anything jump out at you about them? |
/// <param name="key">Correlation item key.</param> | ||
/// <param name="value">Correlation item value.</param> | ||
/// <returns>The <see cref="CorrelationContext"/> instance for chaining.</returns> | ||
public CorrelationContext AddCorrelation(string key, string value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API will not match the spec, right? As spec wants "Set" behavior, but we have "add" behavior, and also we won't have "Remove" feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. The current version is built on top of Activity.Baggage, which is very limiting. Let's discuss this. The other option is we could make CorrelationContext independent of Baggage which would allow us to fully implement the spec. If we do that, let's remove "AllChildren" from #969. CorrelationContext could be used for "AllChildren" behavior and then EnrichmentScope is just responsible for "FirstChild" behavior?
src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs
Show resolved
Hide resolved
/// <summary> | ||
/// TextFormat context. | ||
/// </summary> | ||
public readonly struct TextFormatContext : IEquatable<TextFormatContext> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This represents both SpanContext and Baggage. Not sure if the name TextFormatContext is aptly capturing the purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shooting down a name without a better suggestion isn't fair 🤣 I went with PropagationContext
. Probably some further improvements needed. Let's do a follow-up PR? Our ITextFormat
name doesn't really mirror what the other libraries are doing. All I have checked have HttpTextFormat type of things, which is what is called out in the spec. Some chain like TraceContextHttpPropagationFormat is IHttpPropagationFormat is IPropagationFormat?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like IPropagationFormat
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will follow up for the following
- Should we make CorrelationContext as spec compliant and build it outside Activity.Baggage or just use the Baggage from Activity.
- Potential perf issue as .net (asp.net core) and OTel is potentially extracting the same context in the hot path before sampling.
Changes:
CompositePropagator(TraceContextFormat, BaggageFormat)
by default.IsInjected
fromITextFormat
. It wasn't part of the spec and didn't really make sense for something optional like Baggage.TODO: