add support for true in x-b3-sampled (#1413)
* add support for true in x-b3-sampled * fix order of properties * set string comparer on hashset and clean up tests * add information to changelog * fix line endings
This commit is contained in:
parent
a388874f03
commit
da4d352a19
|
|
@ -6,6 +6,9 @@
|
|||
([#1415](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1415))
|
||||
* Removed `IsOk` property from `Status` and fixed `StatusCode` enum values
|
||||
([#1414](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1414))
|
||||
* `B3Propagator` now supports the value `true` to be passed in for the header
|
||||
`X-B3-Sampled`.
|
||||
([#1413](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1413))
|
||||
|
||||
## 0.7.0-beta.1
|
||||
|
||||
|
|
|
|||
|
|
@ -40,14 +40,19 @@ namespace OpenTelemetry.Context.Propagation
|
|||
// ActivityTraceId.SIZE hex characters (8-bytes traceId) in the past.
|
||||
internal const string UpperTraceId = "0000000000000000";
|
||||
|
||||
// Sampled value via the X_B3_SAMPLED header.
|
||||
// Sampled values via the X_B3_SAMPLED header.
|
||||
internal const string SampledValue = "1";
|
||||
|
||||
// Some old zipkin implementations may send true/false for the sampled header. Only use this for checking incoming values.
|
||||
internal const string LegacySampledValue = "true";
|
||||
|
||||
// "Debug" sampled value.
|
||||
internal const string FlagsValue = "1";
|
||||
|
||||
private static readonly HashSet<string> AllFields = new HashSet<string>() { XB3TraceId, XB3SpanId, XB3ParentSpanId, XB3Sampled, XB3Flags };
|
||||
|
||||
private static readonly HashSet<string> SampledValues = new HashSet<string>(StringComparer.Ordinal) { SampledValue, LegacySampledValue };
|
||||
|
||||
private readonly bool singleHeader;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -180,7 +185,7 @@ namespace OpenTelemetry.Context.Propagation
|
|||
}
|
||||
|
||||
var traceOptions = ActivityTraceFlags.None;
|
||||
if (SampledValue.Equals(getter(carrier, XB3Sampled)?.FirstOrDefault(), StringComparison.Ordinal)
|
||||
if (SampledValues.Contains(getter(carrier, XB3Sampled)?.FirstOrDefault())
|
||||
|| FlagsValue.Equals(getter(carrier, XB3Flags)?.FirstOrDefault(), StringComparison.Ordinal))
|
||||
{
|
||||
traceOptions |= ActivityTraceFlags.Recorded;
|
||||
|
|
@ -239,7 +244,7 @@ namespace OpenTelemetry.Context.Propagation
|
|||
if (parts.Length > 2)
|
||||
{
|
||||
var traceFlagsStr = parts[2];
|
||||
if (SampledValue.Equals(traceFlagsStr, StringComparison.Ordinal)
|
||||
if (SampledValues.Contains(traceFlagsStr)
|
||||
|| FlagsValue.Equals(traceFlagsStr, StringComparison.Ordinal))
|
||||
{
|
||||
traceOptions |= ActivityTraceFlags.Recorded;
|
||||
|
|
|
|||
|
|
@ -81,23 +81,28 @@ namespace OpenTelemetry.Context.Propagation.Tests
|
|||
Assert.Equal(new PropagationContext(spanContext, default), this.b3propagator.Extract(default, headersNotSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseSampled()
|
||||
[Theory]
|
||||
[InlineData("1")]
|
||||
[InlineData("true")]
|
||||
public void ParseSampled(string sampledValue)
|
||||
{
|
||||
var headersSampled = new Dictionary<string, string>
|
||||
{
|
||||
{ B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 }, { B3Propagator.XB3Sampled, "1" },
|
||||
{ B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 }, { B3Propagator.XB3Sampled, sampledValue },
|
||||
};
|
||||
var activityContext = new ActivityContext(TraceId, SpanId, TraceOptions, isRemote: true);
|
||||
Assert.Equal(new PropagationContext(activityContext, default), this.b3propagator.Extract(default, headersSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseZeroSampled()
|
||||
[Theory]
|
||||
[InlineData("0")]
|
||||
[InlineData("false")]
|
||||
[InlineData("something_else")]
|
||||
public void ParseNotSampled(string sampledValue)
|
||||
{
|
||||
var headersNotSampled = new Dictionary<string, string>
|
||||
{
|
||||
{ B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 }, { B3Propagator.XB3Sampled, "0" },
|
||||
{ B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 }, { B3Propagator.XB3Sampled, sampledValue },
|
||||
};
|
||||
var activityContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None, isRemote: true);
|
||||
Assert.Equal(new PropagationContext(activityContext, default), this.b3propagator.Extract(default, headersNotSampled, Getter));
|
||||
|
|
|
|||
Loading…
Reference in New Issue