-
Notifications
You must be signed in to change notification settings - Fork 92
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
Allow multiple context propagators #104
Allow multiple context propagators #104
Conversation
src/Datadog.Trace/Tracer.cs
Outdated
@@ -119,7 +119,8 @@ internal Tracer(TracerSettings settings, ITraceWriter traceWriter, ISampler samp | |||
_scopeManager = scopeManager ?? new AsyncLocalScopeManager(); | |||
Sampler = sampler ?? new RuleBasedSampler(new RateLimiter(Settings.MaxTracesSubmittedPerSecond)); | |||
|
|||
_propagator = ContextPropagatorBuilder.BuildPropagator(Settings.Propagator, TraceIdConvention); | |||
var propagators = ContextPropagatorBuilder.BuildPropagators(Settings.Propagators, TraceIdConvention); |
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.
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.
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.
Current result: no support for different TraceIds in same time
src/Datadog.Trace/Propagation/MultiplexSpanContextPropagator.cs
Outdated
Show resolved
Hide resolved
src/Datadog.Trace/Configuration/ConfigurationSourceExtensions.cs
Outdated
Show resolved
Hide resolved
src/Datadog.Trace/Configuration/ConfigurationSourceExtensions.cs
Outdated
Show resolved
Hide resolved
src/Datadog.Trace/Configuration/ConfigurationSourceExtensions.cs
Outdated
Show resolved
Hide resolved
src/Datadog.Trace/Propagation/MultiplexSpanContextPropagator.cs
Outdated
Show resolved
Hide resolved
src/Datadog.Trace/Propagation/MultiplexSpanContextPropagator.cs
Outdated
Show resolved
Hide resolved
return typedValue; | ||
} | ||
|
||
public static IEnumerable<TEnum> GetTypedValues<TEnum>(this IConfigurationSource source, string key) |
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.
how we would know that an invalid value was provided. more context
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'm not sure this is the right place to deal with validation. As mentioned in #102 it should fail fast. I would propose configuration source validator in early startup (binding configuration to settings instance). After that point configuration should be valid for whole application.
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.
For now, would you consider making this use Enum.Parse
and throw an exception so we know that the result is valid? I'd prefer that this PR close with a clear indication of configuration errors, so this change might be easier than doing a configuration source validator right now
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.
Originally I tried not to change parsing logic with this PR (notice the previous logic is 1:1 same as now) but I can easily change it there is interest.
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 suggest doing it separately.
?? Enumerable.Empty<string>(); | ||
} | ||
|
||
public static TEnum GetTypedValue<TEnum>(this IConfigurationSource source, string key) |
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.
how we would know that an invalid value was provided. more context
|
||
private static void AssertExpected(IHeadersCollection headers, string key, string expected) | ||
{ | ||
var matches = headers.GetValues(key); | ||
Assert.Single(matches); | ||
matches.ToList().ForEach(x => Assert.Equal(expected, x)); | ||
} | ||
|
||
private static void AssertMissing(IHeadersCollection headers, string key) | ||
{ | ||
var matches = headers.GetValues(key); | ||
Assert.Empty(matches); | ||
} |
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.
why these methods have been moved?
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.
Reused for CompositeTextMapPropagatorTests, HeadersCollectionTestBase seems to be ideal for tests that deal with headers.
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 see. Only AssertMissing
is not reused there but I think we can keep it as you refactored 👍
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.
Yep, both seemed to be generic / reusable. Seems bit weird to leave one out 😄
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.
Approving. It will be good to make some follow-up on https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/pull/104/files#r608056476
eb98a7e
to
701847b
Compare
@@ -29,5 +30,18 @@ public static IEnumerable<object[]> GetHeadersInvalidSamplingPrioritiesCartesian | |||
from invalidSamplingPriority in HeadersCollectionTestHelpers.GetInvalidSamplingPriorities().SelectMany(i => i) | |||
select new[] { header, invalidSamplingPriority }; | |||
} | |||
|
|||
internal static void AssertExpected(IHeadersCollection headers, string key, string expected) |
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.
You could make this public so you don't have to add an InternalsVisibleTo
attribute. This won't be consumed by developers so I don't see any reason to keep this internal
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.
IHeadersCollection is also internal, that's the original reason.
/// </summary> | ||
internal class CompositeTextMapPropagator : IPropagator | ||
{ | ||
private readonly ICollection<IPropagator> _propagators; |
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.
Could this be an IEnumerable<IPropagator>
instead? It looks like this is only used to enumerate values and doesn't do insertions/removals
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 usually like to use ICollection when list is actually materialized - so it's quickly visible it's safe to use. With IEnumerable you are also introducing deferred execution, it can easily backfire with context like this.
(for eg if you happen to connect factory with deferred execution, it's perfectly valid code vise, but introduces a major performance loss - so ICollection is also more like a code guard)
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.
In perfect world I would use IReadOnlyCollection, but here it doesn't seem to be a pattern.
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 agree with @RassK . I am used to use IReadOnlyCollection for such cases . It is IMO more readable as well. Also Resharper and Rider static analysis often stops complaining about multiple enumeration in such cases
Unit tests failed because of flaky test: |
Since the test failure is known to be flaky, I'll go ahead and merge |
Background
This PR adds support for multiple propagators that's required by the OTel standard. (following comment in PR #92)
What's next
Configuration source needs to be validated in early startup time. After that point settings instance should be considered as guaranteed OK (no throwing later in run time). See comments: