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 support for true in x-b3-sampled #1413

Merged
merged 7 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 109 additions & 105 deletions src/OpenTelemetry.Api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,105 +1,109 @@
# Changelog

## Unreleased

## 0.7.0-beta.1

Released 2020-Oct-16

* `IActivityTagEnumerator` is now `IActivityEnumerator<T>`. Added
`EnumerateLinks` extension method on `Activity` for retrieving links
efficiently
([#1314](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1314))
* Added `EnumerateEvents` extension method on `Activity` for retrieving events
efficiently
([#1319](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1319))
* Added `EnumerateTags` extension methods on `ActivityLink` & `ActivityEvent`
for retrieving tags efficiently. Renamed `Activity.EnumerateTagValues` ->
`Activity.EnumerateTags`.
([#1320](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1320))
* Updated System.Diagnostics.DiagnosticSource to version 5.0.0-rc.2.20475.5
([#1346](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1346))
* Updated Span Status as per new spec
([#1313](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1313))

## 0.6.0-beta.1

Released 2020-Sep-15

* Updated System.Diagnostics.DiagnosticSource to version 5.0.0-rc.1.20451.14
([#1265](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1265))
* Added `GetTagValue` extension method on `Activity` for retrieving tag values
efficiently
([#1221](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1221))
* Added `EnumerateTagValues` extension method on `Activity` for enumerating tag
values efficiently
([#1236](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1236))

## 0.5.0-beta.2

Released 2020-08-28

* `Link` and `TelemetrySpan` are using `SpanAttributes` instead of
`ActivityTagsCollection` or `Dictionary`
([#1120](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1120))
* Added `RecordException` in `TelemetrySpan`
([#1116](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1116))
* `PropagationContext` is now used instead of `ActivityContext` in the
`ITextFormat` API
([#1048](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1048))
* Added `BaggageFormat` an `ITextFormat` implementation for managing Baggage
propagation via the [W3C
Baggage](https://github.com/w3c/baggage/blob/master/baggage/HTTP_HEADER_FORMAT.md)
header
([#1048](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1048))
* Removed `DistributedContext` as it is no longer part of the spec
([#1048](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1048)))
* Renaming from `ot` to `otel`
([#1046](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1046))
* Added `RuntimeContext` API
([#948](https://github.com/open-telemetry/opentelemetry-dotnet/pull/948))
* Changed `Link` constructor to accept `ActivityTagsCollection` instead of
`IDictionary<string, object>` attributes
([#954](https://github.com/open-telemetry/opentelemetry-dotnet/pull/954))
* Added more `TelemetrySpan.SetAttribute` overloads with value of type bool,
int, double (string already existed)
([#954](https://github.com/open-telemetry/opentelemetry-dotnet/pull/954))
* Changed `TelemetrySpan.SetAttribute` to match the spec
([#954](https://github.com/open-telemetry/opentelemetry-dotnet/pull/954))
* Setting an attribute with an existing key now results in overwriting it
* Setting null value has no impact except if null is set to an existing key,
it gets removed
* Changed `HttpStatusCode` in all spans attribute (http.status_code) to use int
value
([#998](https://github.com/open-telemetry/opentelemetry-dotnet/pull/998))
* Added `CompositePropagator` which accepts a list of `ITextFormat` to match the
spec ([#923](https://github.com/open-telemetry/opentelemetry-dotnet/pull/923))
* Replaced `ITextFormatActivity` with `ITextFormat`
([#923](https://github.com/open-telemetry/opentelemetry-dotnet/pull/923))
* Added `StartRootSpan` and `StartActiveSpan`
([#994](https://github.com/open-telemetry/opentelemetry-dotnet/pull/994))
* Changed `StartSpan` to not set the created span as Active to match the spec
([#994](https://github.com/open-telemetry/opentelemetry-dotnet/pull/994))
* Updated System.Diagnostics.DiagnosticSource to version 5.0.0-preview.8.20407.11.
* Removed `CorrelationContext` and added `Baggage`, an implementation of the
[`Baggage
API`](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/baggage/api.md)
spec
([#1106](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1106))
* Renamed `TraceContextFormat` to `TextMapPropagator`, `BaggageFormat` to
`BaggagePropagator`, and `B3Format` to `B3Propagator`
([#1175](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1175))
* Renamed `ITextPropagator` to `IPropagator`
([#1190](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1190))

## 0.4.0-beta.2

Released 2020-07-24

* First beta release

## 0.3.0-beta

Released 2020-07-23

* Initial release
# Changelog
Copy link
Member

Choose a reason for hiding this comment

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

some encoding got accidentaly changed to this file? there must have been some CI which detects this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

didn't see that coming, let me take a look

Copy link
Contributor

Choose a reason for hiding this comment

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

check if u are using utf8. I saw that sometimes it changed from utf8 to utf8-BOM.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I edited it in vs code and it claimed it saved as utf-8

Copy link
Contributor

Choose a reason for hiding this comment

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

you solved :) what was the issue in the end?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

definitely line endings lol


## Unreleased

* `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

Released 2020-Oct-16

* `IActivityTagEnumerator` is now `IActivityEnumerator<T>`. Added
`EnumerateLinks` extension method on `Activity` for retrieving links
efficiently
([#1314](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1314))
* Added `EnumerateEvents` extension method on `Activity` for retrieving events
efficiently
([#1319](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1319))
* Added `EnumerateTags` extension methods on `ActivityLink` & `ActivityEvent`
for retrieving tags efficiently. Renamed `Activity.EnumerateTagValues` ->
`Activity.EnumerateTags`.
([#1320](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1320))
* Updated System.Diagnostics.DiagnosticSource to version 5.0.0-rc.2.20475.5
([#1346](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1346))
* Updated Span Status as per new spec
([#1313](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1313))

## 0.6.0-beta.1

Released 2020-Sep-15

* Updated System.Diagnostics.DiagnosticSource to version 5.0.0-rc.1.20451.14
([#1265](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1265))
* Added `GetTagValue` extension method on `Activity` for retrieving tag values
efficiently
([#1221](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1221))
* Added `EnumerateTagValues` extension method on `Activity` for enumerating tag
values efficiently
([#1236](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1236))

## 0.5.0-beta.2

Released 2020-08-28

* `Link` and `TelemetrySpan` are using `SpanAttributes` instead of
`ActivityTagsCollection` or `Dictionary`
([#1120](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1120))
* Added `RecordException` in `TelemetrySpan`
([#1116](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1116))
* `PropagationContext` is now used instead of `ActivityContext` in the
`ITextFormat` API
([#1048](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1048))
* Added `BaggageFormat` an `ITextFormat` implementation for managing Baggage
propagation via the [W3C
Baggage](https://github.com/w3c/baggage/blob/master/baggage/HTTP_HEADER_FORMAT.md)
header
([#1048](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1048))
* Removed `DistributedContext` as it is no longer part of the spec
([#1048](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1048)))
* Renaming from `ot` to `otel`
([#1046](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1046))
* Added `RuntimeContext` API
([#948](https://github.com/open-telemetry/opentelemetry-dotnet/pull/948))
* Changed `Link` constructor to accept `ActivityTagsCollection` instead of
`IDictionary<string, object>` attributes
([#954](https://github.com/open-telemetry/opentelemetry-dotnet/pull/954))
* Added more `TelemetrySpan.SetAttribute` overloads with value of type bool,
int, double (string already existed)
([#954](https://github.com/open-telemetry/opentelemetry-dotnet/pull/954))
* Changed `TelemetrySpan.SetAttribute` to match the spec
([#954](https://github.com/open-telemetry/opentelemetry-dotnet/pull/954))
* Setting an attribute with an existing key now results in overwriting it
* Setting null value has no impact except if null is set to an existing key,
it gets removed
* Changed `HttpStatusCode` in all spans attribute (http.status_code) to use int
value
([#998](https://github.com/open-telemetry/opentelemetry-dotnet/pull/998))
* Added `CompositePropagator` which accepts a list of `ITextFormat` to match the
spec ([#923](https://github.com/open-telemetry/opentelemetry-dotnet/pull/923))
* Replaced `ITextFormatActivity` with `ITextFormat`
([#923](https://github.com/open-telemetry/opentelemetry-dotnet/pull/923))
* Added `StartRootSpan` and `StartActiveSpan`
([#994](https://github.com/open-telemetry/opentelemetry-dotnet/pull/994))
* Changed `StartSpan` to not set the created span as Active to match the spec
([#994](https://github.com/open-telemetry/opentelemetry-dotnet/pull/994))
* Updated System.Diagnostics.DiagnosticSource to version 5.0.0-preview.8.20407.11.
* Removed `CorrelationContext` and added `Baggage`, an implementation of the
[`Baggage
API`](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/baggage/api.md)
spec
([#1106](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1106))
* Renamed `TraceContextFormat` to `TextMapPropagator`, `BaggageFormat` to
`BaggagePropagator`, and `B3Format` to `B3Propagator`
([#1175](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1175))
* Renamed `ITextPropagator` to `IPropagator`
([#1190](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1190))

## 0.4.0-beta.2

Released 2020-07-24

* First beta release

## 0.3.0-beta

Released 2020-07-23

* Initial release
11 changes: 8 additions & 3 deletions src/OpenTelemetry.Api/Context/Propagation/B3Propagator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,19 @@ public sealed class B3Propagator : IPropagator
// 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>
Expand Down Expand Up @@ -180,7 +185,7 @@ private static PropagationContext ExtractFromMultipleHeaders<T>(PropagationConte
}

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;
Expand Down Expand Up @@ -239,7 +244,7 @@ private static PropagationContext ExtractFromSingleHeader<T>(PropagationContext
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;
Expand Down
17 changes: 11 additions & 6 deletions test/OpenTelemetry.Tests/Trace/Propagation/B3PropagatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,28 @@ public void ParseMissingSampledAndMissingFlag()
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));
Expand Down