From da72b13b72aff05ffbe621bcf18104629e042e0f Mon Sep 17 00:00:00 2001 From: Eddy Nakamura Date: Thu, 27 Aug 2020 22:59:09 -0300 Subject: [PATCH] Renaming TraceContextFormat/B3Format/BaggageFormat (#1175) * Renaming TraceContextFormat to TextMapPropagator updating changelog renaming b3Format to B3PRopagator renaming BaggageFormat to BaggagePropagator renaming file * renaming variables after merge Co-authored-by: Cijo Thomas --- .../TestOpenTracingWithConsoleExporter.cs | 2 +- .../Utils/Messaging/MessageReceiver.cs | 2 +- .../Utils/Messaging/MessageSender.cs | 2 +- src/OpenTelemetry.Api/CHANGELOG.md | 3 + .../{B3Format.cs => B3Propagator.cs} | 26 ++-- ...{BaggageFormat.cs => BaggagePropagator.cs} | 14 +- ...eContextFormat.cs => TextMapPropagator.cs} | 16 +- .../AspNetInstrumentationOptions.cs | 6 +- .../Implementation/HttpInListener.cs | 6 +- .../AspNetCoreInstrumentationOptions.cs | 6 +- .../Implementation/HttpInListener.cs | 2 +- .../HttpClientInstrumentationOptions.cs | 7 +- ...pWebRequestInstrumentationOptions.netfx.cs | 7 +- .../HttpHandlerDiagnosticListener.cs | 2 +- .../TracerShimTests.cs | 20 +-- .../{B3FormatTest.cs => B3PropagatorTest.cs} | 138 +++++++++--------- ...FormatTest.cs => BaggagePropagatorTest.cs} | 21 +-- .../Propagation/CompositePropagatorTest.cs | 4 +- .../Trace/Propagation/TestPropagator.cs | 4 +- ...ontextTest.cs => TextMapPropagatorTest.cs} | 36 ++--- 20 files changed, 165 insertions(+), 159 deletions(-) rename src/OpenTelemetry.Api/Context/Propagation/{B3Format.cs => B3Propagator.cs} (92%) rename src/OpenTelemetry.Api/Context/Propagation/{BaggageFormat.cs => BaggagePropagator.cs} (93%) rename src/OpenTelemetry.Api/Context/Propagation/{TraceContextFormat.cs => TextMapPropagator.cs} (95%) rename test/OpenTelemetry.Tests/Trace/Propagation/{B3FormatTest.cs => B3PropagatorTest.cs} (63%) rename test/OpenTelemetry.Tests/Trace/Propagation/{BaggageFormatTest.cs => BaggagePropagatorTest.cs} (86%) rename test/OpenTelemetry.Tests/Trace/Propagation/{TraceContextTest.cs => TextMapPropagatorTest.cs} (85%) diff --git a/examples/Console/TestOpenTracingWithConsoleExporter.cs b/examples/Console/TestOpenTracingWithConsoleExporter.cs index e5751e84d..2883f4509 100644 --- a/examples/Console/TestOpenTracingWithConsoleExporter.cs +++ b/examples/Console/TestOpenTracingWithConsoleExporter.cs @@ -40,7 +40,7 @@ namespace Examples.Console // Following shows how to use the OpenTracing shim - var tracer = new TracerShim(TracerProvider.Default.GetTracer("MyCompany.MyProduct.MyWebServer"), new TraceContextFormat()); + var tracer = new TracerShim(TracerProvider.Default.GetTracer("MyCompany.MyProduct.MyWebServer"), new TextMapPropagator()); using (IScope parentScope = tracer.BuildSpan("Parent").StartActive(finishSpanOnDispose: true)) { diff --git a/examples/MicroserviceExample/Utils/Messaging/MessageReceiver.cs b/examples/MicroserviceExample/Utils/Messaging/MessageReceiver.cs index 31b74d0cb..82a3945df 100644 --- a/examples/MicroserviceExample/Utils/Messaging/MessageReceiver.cs +++ b/examples/MicroserviceExample/Utils/Messaging/MessageReceiver.cs @@ -30,7 +30,7 @@ namespace Utils.Messaging public class MessageReceiver : IDisposable { private static readonly ActivitySource ActivitySource = new ActivitySource(nameof(MessageReceiver)); - private static readonly ITextFormat TextFormat = new TraceContextFormat(); + private static readonly ITextFormat TextFormat = new TextMapPropagator(); private readonly ILogger logger; private readonly IConnection connection; diff --git a/examples/MicroserviceExample/Utils/Messaging/MessageSender.cs b/examples/MicroserviceExample/Utils/Messaging/MessageSender.cs index 20dd5b054..95f81c227 100644 --- a/examples/MicroserviceExample/Utils/Messaging/MessageSender.cs +++ b/examples/MicroserviceExample/Utils/Messaging/MessageSender.cs @@ -28,7 +28,7 @@ namespace Utils.Messaging public class MessageSender : IDisposable { private static readonly ActivitySource ActivitySource = new ActivitySource(nameof(MessageSender)); - private static readonly ITextFormat TextFormat = new TraceContextFormat(); + private static readonly ITextFormat TextFormat = new TextMapPropagator(); private readonly ILogger logger; private readonly IConnection connection; diff --git a/src/OpenTelemetry.Api/CHANGELOG.md b/src/OpenTelemetry.Api/CHANGELOG.md index f65501d68..e0798e836 100644 --- a/src/OpenTelemetry.Api/CHANGELOG.md +++ b/src/OpenTelemetry.Api/CHANGELOG.md @@ -49,6 +49,9 @@ 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)) ## 0.4.0-beta.2 diff --git a/src/OpenTelemetry.Api/Context/Propagation/B3Format.cs b/src/OpenTelemetry.Api/Context/Propagation/B3Propagator.cs similarity index 92% rename from src/OpenTelemetry.Api/Context/Propagation/B3Format.cs rename to src/OpenTelemetry.Api/Context/Propagation/B3Propagator.cs index c633c24e9..d08752abb 100644 --- a/src/OpenTelemetry.Api/Context/Propagation/B3Format.cs +++ b/src/OpenTelemetry.Api/Context/Propagation/B3Propagator.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,7 +26,7 @@ namespace OpenTelemetry.Context.Propagation /// /// B3 text propagator. See https://github.com/openzipkin/b3-propagation for the specification. /// - public sealed class B3Format : ITextFormat + public sealed class B3Propagator : ITextFormat { internal const string XB3TraceId = "X-B3-TraceId"; internal const string XB3SpanId = "X-B3-SpanId"; @@ -51,18 +51,18 @@ namespace OpenTelemetry.Context.Propagation private readonly bool singleHeader; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public B3Format() + public B3Propagator() : this(false) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Determines whether to use single or multiple headers when extracting or injecting span context. - public B3Format(bool singleHeader) + public B3Propagator(bool singleHeader) { this.singleHeader = singleHeader; } @@ -81,13 +81,13 @@ namespace OpenTelemetry.Context.Propagation if (carrier == null) { - OpenTelemetryApiEventSource.Log.FailedToExtractActivityContext(nameof(B3Format), "null carrier"); + OpenTelemetryApiEventSource.Log.FailedToExtractActivityContext(nameof(B3Propagator), "null carrier"); return context; } if (getter == null) { - OpenTelemetryApiEventSource.Log.FailedToExtractActivityContext(nameof(B3Format), "null getter"); + OpenTelemetryApiEventSource.Log.FailedToExtractActivityContext(nameof(B3Propagator), "null getter"); return context; } @@ -106,19 +106,19 @@ namespace OpenTelemetry.Context.Propagation { if (context.ActivityContext.TraceId == default || context.ActivityContext.SpanId == default) { - OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(B3Format), "invalid context"); + OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(B3Propagator), "invalid context"); return; } if (carrier == null) { - OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(B3Format), "null carrier"); + OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(B3Propagator), "null carrier"); return; } if (setter == null) { - OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(B3Format), "null setter"); + OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(B3Propagator), "null setter"); return; } @@ -192,7 +192,7 @@ namespace OpenTelemetry.Context.Propagation } catch (Exception e) { - OpenTelemetryApiEventSource.Log.ActivityContextExtractException(nameof(B3Format), e); + OpenTelemetryApiEventSource.Log.ActivityContextExtractException(nameof(B3Propagator), e); return context; } } @@ -252,7 +252,7 @@ namespace OpenTelemetry.Context.Propagation } catch (Exception e) { - OpenTelemetryApiEventSource.Log.ActivityContextExtractException(nameof(B3Format), e); + OpenTelemetryApiEventSource.Log.ActivityContextExtractException(nameof(B3Propagator), e); return context; } } diff --git a/src/OpenTelemetry.Api/Context/Propagation/BaggageFormat.cs b/src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs similarity index 93% rename from src/OpenTelemetry.Api/Context/Propagation/BaggageFormat.cs rename to src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs index 3c970bbbf..c04bed827 100644 --- a/src/OpenTelemetry.Api/Context/Propagation/BaggageFormat.cs +++ b/src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,7 +26,7 @@ namespace OpenTelemetry.Context.Propagation /// /// W3C baggage: https://github.com/w3c/baggage/blob/master/baggage/HTTP_HEADER_FORMAT.md. /// - public class BaggageFormat : ITextFormat + public class BaggagePropagator : ITextFormat { internal const string BaggageHeaderName = "Baggage"; @@ -47,13 +47,13 @@ namespace OpenTelemetry.Context.Propagation if (carrier == null) { - OpenTelemetryApiEventSource.Log.FailedToExtractBaggage(nameof(BaggageFormat), "null carrier"); + OpenTelemetryApiEventSource.Log.FailedToExtractBaggage(nameof(BaggagePropagator), "null carrier"); return context; } if (getter == null) { - OpenTelemetryApiEventSource.Log.FailedToExtractBaggage(nameof(BaggageFormat), "null getter"); + OpenTelemetryApiEventSource.Log.FailedToExtractBaggage(nameof(BaggagePropagator), "null getter"); return context; } @@ -72,7 +72,7 @@ namespace OpenTelemetry.Context.Propagation } catch (Exception ex) { - OpenTelemetryApiEventSource.Log.BaggageExtractException(nameof(BaggageFormat), ex); + OpenTelemetryApiEventSource.Log.BaggageExtractException(nameof(BaggagePropagator), ex); } return context; @@ -83,13 +83,13 @@ namespace OpenTelemetry.Context.Propagation { if (carrier == null) { - OpenTelemetryApiEventSource.Log.FailedToInjectBaggage(nameof(BaggageFormat), "null carrier"); + OpenTelemetryApiEventSource.Log.FailedToInjectBaggage(nameof(BaggagePropagator), "null carrier"); return; } if (setter == null) { - OpenTelemetryApiEventSource.Log.FailedToInjectBaggage(nameof(BaggageFormat), "null setter"); + OpenTelemetryApiEventSource.Log.FailedToInjectBaggage(nameof(BaggagePropagator), "null setter"); return; } diff --git a/src/OpenTelemetry.Api/Context/Propagation/TraceContextFormat.cs b/src/OpenTelemetry.Api/Context/Propagation/TextMapPropagator.cs similarity index 95% rename from src/OpenTelemetry.Api/Context/Propagation/TraceContextFormat.cs rename to src/OpenTelemetry.Api/Context/Propagation/TextMapPropagator.cs index 0dd4bf363..a499a6385 100644 --- a/src/OpenTelemetry.Api/Context/Propagation/TraceContextFormat.cs +++ b/src/OpenTelemetry.Api/Context/Propagation/TextMapPropagator.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,7 +26,7 @@ namespace OpenTelemetry.Context.Propagation /// /// W3C trace context text wire protocol formatter. See https://github.com/w3c/distributed-tracing/. /// - public class TraceContextFormat : ITextFormat + public class TextMapPropagator : ITextFormat { private const string TraceParent = "traceparent"; private const string TraceState = "tracestate"; @@ -53,13 +53,13 @@ namespace OpenTelemetry.Context.Propagation if (carrier == null) { - OpenTelemetryApiEventSource.Log.FailedToExtractActivityContext(nameof(TraceContextFormat), "null carrier"); + OpenTelemetryApiEventSource.Log.FailedToExtractActivityContext(nameof(TextMapPropagator), "null carrier"); return context; } if (getter == null) { - OpenTelemetryApiEventSource.Log.FailedToExtractActivityContext(nameof(TraceContextFormat), "null getter"); + OpenTelemetryApiEventSource.Log.FailedToExtractActivityContext(nameof(TextMapPropagator), "null getter"); return context; } @@ -94,7 +94,7 @@ namespace OpenTelemetry.Context.Propagation } catch (Exception ex) { - OpenTelemetryApiEventSource.Log.ActivityContextExtractException(nameof(TraceContextFormat), ex); + OpenTelemetryApiEventSource.Log.ActivityContextExtractException(nameof(TextMapPropagator), ex); } // in case of exception indicate to upstream that there is no parseable context from the top @@ -106,19 +106,19 @@ namespace OpenTelemetry.Context.Propagation { if (context.ActivityContext.TraceId == default || context.ActivityContext.SpanId == default) { - OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(TraceContextFormat), "Invalid context"); + OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(TextMapPropagator), "Invalid context"); return; } if (carrier == null) { - OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(TraceContextFormat), "null carrier"); + OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(TextMapPropagator), "null carrier"); return; } if (setter == null) { - OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(TraceContextFormat), "null setter"); + OpenTelemetryApiEventSource.Log.FailedToInjectActivityContext(nameof(TextMapPropagator), "null setter"); return; } diff --git a/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentationOptions.cs index 80b57e3d6..31b818b0a 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentationOptions.cs @@ -26,12 +26,12 @@ namespace OpenTelemetry.Instrumentation.AspNet public class AspNetInstrumentationOptions { /// - /// Gets or sets for context propagation. Default value: with & . + /// Gets or sets for context propagation. Default value: with & . /// public ITextFormat TextFormat { get; set; } = new CompositePropagator(new ITextFormat[] { - new TraceContextFormat(), - new BaggageFormat(), + new TextMapPropagator(), + new BaggagePropagator(), }); /// diff --git a/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs index 060fa4665..9a9bf8c75 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs @@ -63,7 +63,7 @@ namespace OpenTelemetry.Instrumentation.AspNet.Implementation var request = context.Request; var requestValues = request.Unvalidated; - if (!(this.options.TextFormat is TraceContextFormat)) + if (!(this.options.TextFormat is TextMapPropagator)) { var ctx = this.options.TextFormat.Extract(default, request, HttpRequestHeaderValuesGetter); @@ -125,7 +125,7 @@ namespace OpenTelemetry.Instrumentation.AspNet.Implementation Activity activityToEnrich = activity; Activity createdActivity = null; - if (!(this.options.TextFormat is TraceContextFormat)) + if (!(this.options.TextFormat is TextMapPropagator)) { // If using custom context propagator, then the activity here // could be either the one from Asp.Net, or the one @@ -190,7 +190,7 @@ namespace OpenTelemetry.Instrumentation.AspNet.Implementation } } - if (!(this.options.TextFormat is TraceContextFormat)) + if (!(this.options.TextFormat is TextMapPropagator)) { if (activity.OperationName.Equals(ActivityNameByHttpInListener)) { diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs index 08722ac74..e858eea91 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs @@ -26,12 +26,12 @@ namespace OpenTelemetry.Instrumentation.AspNetCore public class AspNetCoreInstrumentationOptions { /// - /// Gets or sets for context propagation. Default value: with & . + /// Gets or sets for context propagation. Default value: with & . /// public ITextFormat TextFormat { get; set; } = new CompositePropagator(new ITextFormat[] { - new TraceContextFormat(), - new BaggageFormat(), + new TextMapPropagator(), + new BaggagePropagator(), }); /// diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs index e073aacc1..f6c978ad1 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs @@ -69,7 +69,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation } var request = context.Request; - if (!this.hostingSupportsW3C || !(this.options.TextFormat is TraceContextFormat)) + if (!this.hostingSupportsW3C || !(this.options.TextFormat is TextMapPropagator)) { var ctx = this.options.TextFormat.Extract(default, request, HttpRequestHeaderValuesGetter); diff --git a/src/OpenTelemetry.Instrumentation.Http/HttpClientInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.Http/HttpClientInstrumentationOptions.cs index c1246d6b8..0d50ff0d7 100644 --- a/src/OpenTelemetry.Instrumentation.Http/HttpClientInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.Http/HttpClientInstrumentationOptions.cs @@ -13,6 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // + using System; using System.Net.Http; using System.Runtime.CompilerServices; @@ -32,12 +33,12 @@ namespace OpenTelemetry.Instrumentation.Http public bool SetHttpFlavor { get; set; } /// - /// Gets or sets for context propagation. Default value: with & . + /// Gets or sets for context propagation. Default value: with & . /// public ITextFormat TextFormat { get; set; } = new CompositePropagator(new ITextFormat[] { - new TraceContextFormat(), - new BaggageFormat(), + new TextMapPropagator(), + new BaggagePropagator(), }); /// diff --git a/src/OpenTelemetry.Instrumentation.Http/HttpWebRequestInstrumentationOptions.netfx.cs b/src/OpenTelemetry.Instrumentation.Http/HttpWebRequestInstrumentationOptions.netfx.cs index f956365da..8330172ab 100644 --- a/src/OpenTelemetry.Instrumentation.Http/HttpWebRequestInstrumentationOptions.netfx.cs +++ b/src/OpenTelemetry.Instrumentation.Http/HttpWebRequestInstrumentationOptions.netfx.cs @@ -13,6 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // + #if NETFRAMEWORK using System; using System.Net; @@ -32,12 +33,12 @@ namespace OpenTelemetry.Instrumentation.Http public bool SetHttpFlavor { get; set; } /// - /// Gets or sets for context propagation. Default value: with & . + /// Gets or sets for context propagation. Default value: with & . /// public ITextFormat TextFormat { get; set; } = new CompositePropagator(new ITextFormat[] { - new TraceContextFormat(), - new BaggageFormat(), + new TextMapPropagator(), + new BaggagePropagator(), }); /// diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs index d0200800a..f2d2d9664 100644 --- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs @@ -111,7 +111,7 @@ namespace OpenTelemetry.Instrumentation.Http.Implementation } } - if (!(this.httpClientSupportsW3C && this.options.TextFormat is TraceContextFormat)) + if (!(this.httpClientSupportsW3C && this.options.TextFormat is TextMapPropagator)) { this.options.TextFormat.Inject(new PropagationContext(activity.Context, Baggage.Current), request, HttpRequestMessageHeaderValueSetter); } diff --git a/test/OpenTelemetry.Shims.OpenTracing.Tests/TracerShimTests.cs b/test/OpenTelemetry.Shims.OpenTracing.Tests/TracerShimTests.cs index ad6ddaca3..1a799ad79 100644 --- a/test/OpenTelemetry.Shims.OpenTracing.Tests/TracerShimTests.cs +++ b/test/OpenTelemetry.Shims.OpenTracing.Tests/TracerShimTests.cs @@ -39,7 +39,7 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests Assert.Throws(() => new TracerShim(null, null)); // null tracer - Assert.Throws(() => new TracerShim(null, new TraceContextFormat())); + Assert.Throws(() => new TracerShim(null, new TextMapPropagator())); // null context format var tracerMock = new Mock(); @@ -50,7 +50,7 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests public void ScopeManager_NotNull() { var tracer = TracerProvider.Default.GetTracer(TracerName); - var shim = new TracerShim(tracer, new TraceContextFormat()); + var shim = new TracerShim(tracer, new TextMapPropagator()); // Internals of the ScopeManagerShim tested elsewhere Assert.NotNull(shim.ScopeManager as ScopeManagerShim); @@ -60,7 +60,7 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests public void BuildSpan_NotNull() { var tracer = TracerProvider.Default.GetTracer(TracerName); - var shim = new TracerShim(tracer, new TraceContextFormat()); + var shim = new TracerShim(tracer, new TextMapPropagator()); // Internals of the SpanBuilderShim tested elsewhere Assert.NotNull(shim.BuildSpan("foo") as SpanBuilderShim); @@ -70,7 +70,7 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests public void Inject_ArgumentValidation() { var tracer = TracerProvider.Default.GetTracer(TracerName); - var shim = new TracerShim(tracer, new TraceContextFormat()); + var shim = new TracerShim(tracer, new TextMapPropagator()); var spanContextShim = new SpanContextShim(new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None)); var mockFormat = new Mock>(); @@ -86,7 +86,7 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests public void Inject_UnknownFormatIgnored() { var tracer = TracerProvider.Default.GetTracer(TracerName); - var shim = new TracerShim(tracer, new TraceContextFormat()); + var shim = new TracerShim(tracer, new TextMapPropagator()); var spanContextShim = new SpanContextShim(new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded)); @@ -102,7 +102,7 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests public void Extract_ArgumentValidation() { var tracer = TracerProvider.Default.GetTracer(TracerName); - var shim = new TracerShim(tracer, new TraceContextFormat()); + var shim = new TracerShim(tracer, new TextMapPropagator()); Assert.Throws(() => shim.Extract(null, new Mock().Object)); Assert.Throws(() => shim.Extract(new Mock>().Object, null)); @@ -112,7 +112,7 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests public void Extract_UnknownFormatIgnored() { var tracer = TracerProvider.Default.GetTracer(TracerName); - var shim = new TracerShim(tracer, new TraceContextFormat()); + var shim = new TracerShim(tracer, new TextMapPropagator()); var spanContextShim = new SpanContextShim(new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None)); @@ -128,11 +128,11 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests public void Extract_InvalidTraceParent() { var tracer = TracerProvider.Default.GetTracer(TracerName); - var shim = new TracerShim(tracer, new TraceContextFormat()); + var shim = new TracerShim(tracer, new TextMapPropagator()); var mockCarrier = new Mock(); - // The ProxyTracer uses OpenTelemetry.Context.Propagation.TraceContextFormat, so we need to satisfy the traceparent key at the least + // The ProxyTracer uses OpenTelemetry.Context.Propagation.TextMapPropagator, so we need to satisfy the traceparent key at the least var carrierMap = new Dictionary { // This is an invalid traceparent value @@ -155,7 +155,7 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests var spanContextShim = new SpanContextShim(new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None)); - var format = new TraceContextFormat(); + var format = new TextMapPropagator(); var tracer = TracerProvider.Default.GetTracer(TracerName); var shim = new TracerShim(tracer, format); diff --git a/test/OpenTelemetry.Tests/Trace/Propagation/B3FormatTest.cs b/test/OpenTelemetry.Tests/Trace/Propagation/B3PropagatorTest.cs similarity index 63% rename from test/OpenTelemetry.Tests/Trace/Propagation/B3FormatTest.cs rename to test/OpenTelemetry.Tests/Trace/Propagation/B3PropagatorTest.cs index 2d5c096da..f7d818d21 100644 --- a/test/OpenTelemetry.Tests/Trace/Propagation/B3FormatTest.cs +++ b/test/OpenTelemetry.Tests/Trace/Propagation/B3PropagatorTest.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ using Xunit.Abstractions; namespace OpenTelemetry.Context.Propagation.Tests { - public class B3FormatTest + public class B3PropagatorTest { private const string TraceIdBase16 = "ff000000000000000000000000000041"; private const string TraceIdBase16EightBytes = "0000000000000041"; @@ -42,12 +42,12 @@ namespace OpenTelemetry.Context.Propagation.Tests return new string[] { v }; }; - private readonly B3Format b3Format = new B3Format(); - private readonly B3Format b3FormatSingleHeader = new B3Format(true); + private readonly B3Propagator b3propagator = new B3Propagator(); + private readonly B3Propagator b3PropagatorSingleHeader = new B3Propagator(true); private readonly ITestOutputHelper output; - public B3FormatTest(ITestOutputHelper output) + public B3PropagatorTest(ITestOutputHelper output) { this.output = output; } @@ -56,8 +56,8 @@ namespace OpenTelemetry.Context.Propagation.Tests public void Serialize_SampledContext() { var carrier = new Dictionary(); - this.b3Format.Inject(new PropagationContext(new ActivityContext(TraceId, SpanId, TraceOptions), default), carrier, Setter); - this.ContainsExactly(carrier, new Dictionary { { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Sampled, "1" } }); + this.b3propagator.Inject(new PropagationContext(new ActivityContext(TraceId, SpanId, TraceOptions), default), carrier, Setter); + this.ContainsExactly(carrier, new Dictionary { { B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 }, { B3Propagator.XB3Sampled, "1" } }); } [Fact] @@ -66,8 +66,8 @@ namespace OpenTelemetry.Context.Propagation.Tests var carrier = new Dictionary(); var context = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None); this.output.WriteLine(context.ToString()); - this.b3Format.Inject(new PropagationContext(context, default), carrier, Setter); - this.ContainsExactly(carrier, new Dictionary { { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 } }); + this.b3propagator.Inject(new PropagationContext(context, default), carrier, Setter); + this.ContainsExactly(carrier, new Dictionary { { B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 } }); } [Fact] @@ -75,10 +75,10 @@ namespace OpenTelemetry.Context.Propagation.Tests { var headersNotSampled = new Dictionary { - { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, + { B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 }, }; var spanContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None); - Assert.Equal(new PropagationContext(spanContext, default), this.b3Format.Extract(default, headersNotSampled, Getter)); + Assert.Equal(new PropagationContext(spanContext, default), this.b3propagator.Extract(default, headersNotSampled, Getter)); } [Fact] @@ -86,10 +86,10 @@ namespace OpenTelemetry.Context.Propagation.Tests { var headersSampled = new Dictionary { - { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Sampled, "1" }, + { B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 }, { B3Propagator.XB3Sampled, "1" }, }; var activityContext = new ActivityContext(TraceId, SpanId, TraceOptions); - Assert.Equal(new PropagationContext(activityContext, default), this.b3Format.Extract(default, headersSampled, Getter)); + Assert.Equal(new PropagationContext(activityContext, default), this.b3propagator.Extract(default, headersSampled, Getter)); } [Fact] @@ -97,10 +97,10 @@ namespace OpenTelemetry.Context.Propagation.Tests { var headersNotSampled = new Dictionary { - { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Sampled, "0" }, + { B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 }, { B3Propagator.XB3Sampled, "0" }, }; var activityContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None); - Assert.Equal(new PropagationContext(activityContext, default), this.b3Format.Extract(default, headersNotSampled, Getter)); + Assert.Equal(new PropagationContext(activityContext, default), this.b3propagator.Extract(default, headersNotSampled, Getter)); } [Fact] @@ -108,10 +108,10 @@ namespace OpenTelemetry.Context.Propagation.Tests { var headersFlagSampled = new Dictionary { - { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Flags, "1" }, + { B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 }, { B3Propagator.XB3Flags, "1" }, }; var activityContext = new ActivityContext(TraceId, SpanId, TraceOptions); - Assert.Equal(new PropagationContext(activityContext, default), this.b3Format.Extract(default, headersFlagSampled, Getter)); + Assert.Equal(new PropagationContext(activityContext, default), this.b3propagator.Extract(default, headersFlagSampled, Getter)); } [Fact] @@ -119,10 +119,10 @@ namespace OpenTelemetry.Context.Propagation.Tests { var headersFlagNotSampled = new Dictionary { - { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Flags, "0" }, + { B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, SpanIdBase16 }, { B3Propagator.XB3Flags, "0" }, }; var activityContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None); - Assert.Equal(new PropagationContext(activityContext, default), this.b3Format.Extract(default, headersFlagNotSampled, Getter)); + Assert.Equal(new PropagationContext(activityContext, default), this.b3propagator.Extract(default, headersFlagNotSampled, Getter)); } [Fact] @@ -130,12 +130,12 @@ namespace OpenTelemetry.Context.Propagation.Tests { var headersEightBytes = new Dictionary { - { B3Format.XB3TraceId, TraceIdBase16EightBytes }, - { B3Format.XB3SpanId, SpanIdBase16 }, - { B3Format.XB3Sampled, "1" }, + { B3Propagator.XB3TraceId, TraceIdBase16EightBytes }, + { B3Propagator.XB3SpanId, SpanIdBase16 }, + { B3Propagator.XB3Sampled, "1" }, }; var activityContext = new ActivityContext(TraceIdEightBytes, SpanId, TraceOptions); - Assert.Equal(new PropagationContext(activityContext, default), this.b3Format.Extract(default, headersEightBytes, Getter)); + Assert.Equal(new PropagationContext(activityContext, default), this.b3propagator.Extract(default, headersEightBytes, Getter)); } [Fact] @@ -143,10 +143,10 @@ namespace OpenTelemetry.Context.Propagation.Tests { var headersEightBytes = new Dictionary { - { B3Format.XB3TraceId, TraceIdBase16EightBytes }, { B3Format.XB3SpanId, SpanIdBase16 }, + { B3Propagator.XB3TraceId, TraceIdBase16EightBytes }, { B3Propagator.XB3SpanId, SpanIdBase16 }, }; var activityContext = new ActivityContext(TraceIdEightBytes, SpanId, ActivityTraceFlags.None); - Assert.Equal(new PropagationContext(activityContext, default), this.b3Format.Extract(default, headersEightBytes, Getter)); + Assert.Equal(new PropagationContext(activityContext, default), this.b3propagator.Extract(default, headersEightBytes, Getter)); } [Fact] @@ -154,9 +154,9 @@ namespace OpenTelemetry.Context.Propagation.Tests { var invalidHeaders = new Dictionary { - { B3Format.XB3TraceId, InvalidId }, { B3Format.XB3SpanId, SpanIdBase16 }, + { B3Propagator.XB3TraceId, InvalidId }, { B3Propagator.XB3SpanId, SpanIdBase16 }, }; - Assert.Equal(default, this.b3Format.Extract(default, invalidHeaders, Getter)); + Assert.Equal(default, this.b3propagator.Extract(default, invalidHeaders, Getter)); } [Fact] @@ -164,17 +164,17 @@ namespace OpenTelemetry.Context.Propagation.Tests { var invalidHeaders = new Dictionary { - { B3Format.XB3TraceId, InvalidSizeId }, { B3Format.XB3SpanId, SpanIdBase16 }, + { B3Propagator.XB3TraceId, InvalidSizeId }, { B3Propagator.XB3SpanId, SpanIdBase16 }, }; - Assert.Equal(default, this.b3Format.Extract(default, invalidHeaders, Getter)); + Assert.Equal(default, this.b3propagator.Extract(default, invalidHeaders, Getter)); } [Fact] public void ParseMissingTraceId() { - var invalidHeaders = new Dictionary { { B3Format.XB3SpanId, SpanIdBase16 }, }; - Assert.Equal(default, this.b3Format.Extract(default, invalidHeaders, Getter)); + var invalidHeaders = new Dictionary { { B3Propagator.XB3SpanId, SpanIdBase16 }, }; + Assert.Equal(default, this.b3propagator.Extract(default, invalidHeaders, Getter)); } [Fact] @@ -182,9 +182,9 @@ namespace OpenTelemetry.Context.Propagation.Tests { var invalidHeaders = new Dictionary { - { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, InvalidId }, + { B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, InvalidId }, }; - Assert.Equal(default, this.b3Format.Extract(default, invalidHeaders, Getter)); + Assert.Equal(default, this.b3propagator.Extract(default, invalidHeaders, Getter)); } [Fact] @@ -192,16 +192,16 @@ namespace OpenTelemetry.Context.Propagation.Tests { var invalidHeaders = new Dictionary { - { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, InvalidSizeId }, + { B3Propagator.XB3TraceId, TraceIdBase16 }, { B3Propagator.XB3SpanId, InvalidSizeId }, }; - Assert.Equal(default, this.b3Format.Extract(default, invalidHeaders, Getter)); + Assert.Equal(default, this.b3propagator.Extract(default, invalidHeaders, Getter)); } [Fact] public void ParseMissingSpanId() { - var invalidHeaders = new Dictionary { { B3Format.XB3TraceId, TraceIdBase16 } }; - Assert.Equal(default, this.b3Format.Extract(default, invalidHeaders, Getter)); + var invalidHeaders = new Dictionary { { B3Propagator.XB3TraceId, TraceIdBase16 } }; + Assert.Equal(default, this.b3propagator.Extract(default, invalidHeaders, Getter)); } [Fact] @@ -209,8 +209,8 @@ namespace OpenTelemetry.Context.Propagation.Tests { var carrier = new Dictionary(); var activityContext = new ActivityContext(TraceId, SpanId, TraceOptions); - this.b3FormatSingleHeader.Inject(new PropagationContext(activityContext, default), carrier, Setter); - this.ContainsExactly(carrier, new Dictionary { { B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" } }); + this.b3PropagatorSingleHeader.Inject(new PropagationContext(activityContext, default), carrier, Setter); + this.ContainsExactly(carrier, new Dictionary { { B3Propagator.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" } }); } [Fact] @@ -219,8 +219,8 @@ namespace OpenTelemetry.Context.Propagation.Tests var carrier = new Dictionary(); var activityContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None); this.output.WriteLine(activityContext.ToString()); - this.b3FormatSingleHeader.Inject(new PropagationContext(activityContext, default), carrier, Setter); - this.ContainsExactly(carrier, new Dictionary { { B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}" } }); + this.b3PropagatorSingleHeader.Inject(new PropagationContext(activityContext, default), carrier, Setter); + this.ContainsExactly(carrier, new Dictionary { { B3Propagator.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}" } }); } [Fact] @@ -228,10 +228,10 @@ namespace OpenTelemetry.Context.Propagation.Tests { var headersNotSampled = new Dictionary { - { B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}" }, + { B3Propagator.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}" }, }; var activityContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None); - Assert.Equal(new PropagationContext(activityContext, default), this.b3FormatSingleHeader.Extract(default, headersNotSampled, Getter)); + Assert.Equal(new PropagationContext(activityContext, default), this.b3PropagatorSingleHeader.Extract(default, headersNotSampled, Getter)); } [Fact] @@ -239,12 +239,12 @@ namespace OpenTelemetry.Context.Propagation.Tests { var headersSampled = new Dictionary { - { B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" }, + { B3Propagator.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" }, }; Assert.Equal( new PropagationContext(new ActivityContext(TraceId, SpanId, TraceOptions), default), - this.b3FormatSingleHeader.Extract(default, headersSampled, Getter)); + this.b3PropagatorSingleHeader.Extract(default, headersSampled, Getter)); } [Fact] @@ -252,12 +252,12 @@ namespace OpenTelemetry.Context.Propagation.Tests { var headersNotSampled = new Dictionary { - { B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-0" }, + { B3Propagator.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-0" }, }; Assert.Equal( new PropagationContext(new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None), default), - this.b3FormatSingleHeader.Extract(default, headersNotSampled, Getter)); + this.b3PropagatorSingleHeader.Extract(default, headersNotSampled, Getter)); } [Fact] @@ -265,10 +265,10 @@ namespace OpenTelemetry.Context.Propagation.Tests { var headersFlagSampled = new Dictionary { - { B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" }, + { B3Propagator.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" }, }; var activityContext = new ActivityContext(TraceId, SpanId, TraceOptions); - Assert.Equal(new PropagationContext(activityContext, default), this.b3FormatSingleHeader.Extract(default, headersFlagSampled, Getter)); + Assert.Equal(new PropagationContext(activityContext, default), this.b3PropagatorSingleHeader.Extract(default, headersFlagSampled, Getter)); } [Fact] @@ -276,10 +276,10 @@ namespace OpenTelemetry.Context.Propagation.Tests { var headersFlagNotSampled = new Dictionary { - { B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-0" }, + { B3Propagator.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-0" }, }; var activityContext = new ActivityContext(TraceId, SpanId, ActivityTraceFlags.None); - Assert.Equal(new PropagationContext(activityContext, default), this.b3FormatSingleHeader.Extract(default, headersFlagNotSampled, Getter)); + Assert.Equal(new PropagationContext(activityContext, default), this.b3PropagatorSingleHeader.Extract(default, headersFlagNotSampled, Getter)); } [Fact] @@ -287,10 +287,10 @@ namespace OpenTelemetry.Context.Propagation.Tests { var headersEightBytes = new Dictionary { - { B3Format.XB3Combined, $"{TraceIdBase16EightBytes}-{SpanIdBase16}-1" }, + { B3Propagator.XB3Combined, $"{TraceIdBase16EightBytes}-{SpanIdBase16}-1" }, }; var activityContext = new ActivityContext(TraceIdEightBytes, SpanId, TraceOptions); - Assert.Equal(new PropagationContext(activityContext, default), this.b3FormatSingleHeader.Extract(default, headersEightBytes, Getter)); + Assert.Equal(new PropagationContext(activityContext, default), this.b3PropagatorSingleHeader.Extract(default, headersEightBytes, Getter)); } [Fact] @@ -298,10 +298,10 @@ namespace OpenTelemetry.Context.Propagation.Tests { var headersEightBytes = new Dictionary { - { B3Format.XB3Combined, $"{TraceIdBase16EightBytes}-{SpanIdBase16}" }, + { B3Propagator.XB3Combined, $"{TraceIdBase16EightBytes}-{SpanIdBase16}" }, }; var activityContext = new ActivityContext(TraceIdEightBytes, SpanId, ActivityTraceFlags.None); - Assert.Equal(new PropagationContext(activityContext, default), this.b3FormatSingleHeader.Extract(default, headersEightBytes, Getter)); + Assert.Equal(new PropagationContext(activityContext, default), this.b3PropagatorSingleHeader.Extract(default, headersEightBytes, Getter)); } [Fact] @@ -309,9 +309,9 @@ namespace OpenTelemetry.Context.Propagation.Tests { var invalidHeaders = new Dictionary { - { B3Format.XB3Combined, $"{InvalidId}-{SpanIdBase16}" }, + { B3Propagator.XB3Combined, $"{InvalidId}-{SpanIdBase16}" }, }; - Assert.Equal(default, this.b3FormatSingleHeader.Extract(default, invalidHeaders, Getter)); + Assert.Equal(default, this.b3PropagatorSingleHeader.Extract(default, invalidHeaders, Getter)); } [Fact] @@ -319,17 +319,17 @@ namespace OpenTelemetry.Context.Propagation.Tests { var invalidHeaders = new Dictionary { - { B3Format.XB3Combined, $"{InvalidSizeId}-{SpanIdBase16}" }, + { B3Propagator.XB3Combined, $"{InvalidSizeId}-{SpanIdBase16}" }, }; - Assert.Equal(default, this.b3FormatSingleHeader.Extract(default, invalidHeaders, Getter)); + Assert.Equal(default, this.b3PropagatorSingleHeader.Extract(default, invalidHeaders, Getter)); } [Fact] public void ParseMissingTraceId_SingleHeader() { - var invalidHeaders = new Dictionary { { B3Format.XB3Combined, $"-{SpanIdBase16}" } }; - Assert.Equal(default, this.b3FormatSingleHeader.Extract(default, invalidHeaders, Getter)); + var invalidHeaders = new Dictionary { { B3Propagator.XB3Combined, $"-{SpanIdBase16}" } }; + Assert.Equal(default, this.b3PropagatorSingleHeader.Extract(default, invalidHeaders, Getter)); } [Fact] @@ -337,9 +337,9 @@ namespace OpenTelemetry.Context.Propagation.Tests { var invalidHeaders = new Dictionary { - { B3Format.XB3Combined, $"{TraceIdBase16}-{InvalidId}" }, + { B3Propagator.XB3Combined, $"{TraceIdBase16}-{InvalidId}" }, }; - Assert.Equal(default, this.b3FormatSingleHeader.Extract(default, invalidHeaders, Getter)); + Assert.Equal(default, this.b3PropagatorSingleHeader.Extract(default, invalidHeaders, Getter)); } [Fact] @@ -347,24 +347,24 @@ namespace OpenTelemetry.Context.Propagation.Tests { var invalidHeaders = new Dictionary { - { B3Format.XB3Combined, $"{TraceIdBase16}-{InvalidSizeId}" }, + { B3Propagator.XB3Combined, $"{TraceIdBase16}-{InvalidSizeId}" }, }; - Assert.Equal(default, this.b3FormatSingleHeader.Extract(default, invalidHeaders, Getter)); + Assert.Equal(default, this.b3PropagatorSingleHeader.Extract(default, invalidHeaders, Getter)); } [Fact] public void ParseMissingSpanId_SingleHeader() { - var invalidHeaders = new Dictionary { { B3Format.XB3Combined, $"{TraceIdBase16}-" } }; - Assert.Equal(default, this.b3FormatSingleHeader.Extract(default, invalidHeaders, Getter)); + var invalidHeaders = new Dictionary { { B3Propagator.XB3Combined, $"{TraceIdBase16}-" } }; + Assert.Equal(default, this.b3PropagatorSingleHeader.Extract(default, invalidHeaders, Getter)); } [Fact] public void Fields_list() { this.ContainsExactly( - this.b3Format.Fields, - new List { B3Format.XB3TraceId, B3Format.XB3SpanId, B3Format.XB3ParentSpanId, B3Format.XB3Sampled, B3Format.XB3Flags }); + this.b3propagator.Fields, + new List { B3Propagator.XB3TraceId, B3Propagator.XB3SpanId, B3Propagator.XB3ParentSpanId, B3Propagator.XB3Sampled, B3Propagator.XB3Flags }); } private void ContainsExactly(ISet list, List items) diff --git a/test/OpenTelemetry.Tests/Trace/Propagation/BaggageFormatTest.cs b/test/OpenTelemetry.Tests/Trace/Propagation/BaggagePropagatorTest.cs similarity index 86% rename from test/OpenTelemetry.Tests/Trace/Propagation/BaggageFormatTest.cs rename to test/OpenTelemetry.Tests/Trace/Propagation/BaggagePropagatorTest.cs index 6b37bc1e6..86b855767 100644 --- a/test/OpenTelemetry.Tests/Trace/Propagation/BaggageFormatTest.cs +++ b/test/OpenTelemetry.Tests/Trace/Propagation/BaggagePropagatorTest.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // + using System; using System.Collections.Generic; using System.Linq; @@ -20,7 +21,7 @@ using Xunit; namespace OpenTelemetry.Context.Propagation.Tests { - public class BaggageFormatTest + public class BaggagePropagatorTest { private static readonly Func, string, IEnumerable> Getter = (d, k) => @@ -40,12 +41,12 @@ namespace OpenTelemetry.Context.Propagation.Tests carrier[name] = value; }; - private readonly BaggageFormat baggage = new BaggageFormat(); + private readonly BaggagePropagator baggage = new BaggagePropagator(); [Fact] public void ValidateFieldsProperty() { - Assert.Equal(new HashSet { BaggageFormat.BaggageHeaderName }, this.baggage.Fields); + Assert.Equal(new HashSet { BaggagePropagator.BaggageHeaderName }, this.baggage.Fields); Assert.Single(this.baggage.Fields); } @@ -77,7 +78,7 @@ namespace OpenTelemetry.Context.Propagation.Tests { var carrier = new Dictionary { - { BaggageFormat.BaggageHeaderName, "name=test" }, + { BaggagePropagator.BaggageHeaderName, "name=test" }, }; var propagationContext = this.baggage.Extract(default, carrier, Getter); Assert.False(propagationContext == default); @@ -94,9 +95,9 @@ namespace OpenTelemetry.Context.Propagation.Tests { var carrier = new List> { - new KeyValuePair(BaggageFormat.BaggageHeaderName, "name1=test1"), - new KeyValuePair(BaggageFormat.BaggageHeaderName, "name2=test2"), - new KeyValuePair(BaggageFormat.BaggageHeaderName, "name2=test2"), + new KeyValuePair(BaggagePropagator.BaggageHeaderName, "name1=test1"), + new KeyValuePair(BaggagePropagator.BaggageHeaderName, "name2=test2"), + new KeyValuePair(BaggagePropagator.BaggageHeaderName, "name2=test2"), }; var propagationContext = this.baggage.Extract(default, carrier, GetterList); @@ -120,7 +121,7 @@ namespace OpenTelemetry.Context.Propagation.Tests { var carrier = new Dictionary { - { BaggageFormat.BaggageHeaderName, $"name={new string('x', 8186)},clientId=1234" }, + { BaggagePropagator.BaggageHeaderName, $"name={new string('x', 8186)},clientId=1234" }, }; var propagationContext = this.baggage.Extract(default, carrier, Getter); Assert.False(propagationContext == default); @@ -156,7 +157,7 @@ namespace OpenTelemetry.Context.Propagation.Tests this.baggage.Inject(propagationContext, carrier, Setter); Assert.Single(carrier); - Assert.Equal("key1=value1,key2=value2", carrier[BaggageFormat.BaggageHeaderName]); + Assert.Equal("key1=value1,key2=value2", carrier[BaggagePropagator.BaggageHeaderName]); } } } diff --git a/test/OpenTelemetry.Tests/Trace/Propagation/CompositePropagatorTest.cs b/test/OpenTelemetry.Tests/Trace/Propagation/CompositePropagatorTest.cs index 1a2c1d39c..d31ee34a2 100644 --- a/test/OpenTelemetry.Tests/Trace/Propagation/CompositePropagatorTest.cs +++ b/test/OpenTelemetry.Tests/Trace/Propagation/CompositePropagatorTest.cs @@ -108,8 +108,8 @@ namespace OpenTelemetry.Context.Propagation.Tests { var compositePropagator = new CompositePropagator(new List { - new TraceContextFormat(), - new BaggageFormat(), + new TextMapPropagator(), + new BaggagePropagator(), }); var activityContext = new ActivityContext(this.traceId, this.spanId, ActivityTraceFlags.Recorded, traceState: null, isRemote: true); diff --git a/test/OpenTelemetry.Tests/Trace/Propagation/TestPropagator.cs b/test/OpenTelemetry.Tests/Trace/Propagation/TestPropagator.cs index 770b189b2..c13d1f7a0 100644 --- a/test/OpenTelemetry.Tests/Trace/Propagation/TestPropagator.cs +++ b/test/OpenTelemetry.Tests/Trace/Propagation/TestPropagator.cs @@ -49,7 +49,7 @@ namespace OpenTelemetry.Context.Propagation.Tests return context; } - var traceparentParsed = TraceContextFormat.TryExtractTraceparent(id.First(), out var traceId, out var spanId, out var traceoptions); + var traceparentParsed = TextMapPropagator.TryExtractTraceparent(id.First(), out var traceId, out var spanId, out var traceoptions); if (!traceparentParsed) { return context; @@ -59,7 +59,7 @@ namespace OpenTelemetry.Context.Propagation.Tests IEnumerable tracestateCollection = getter(carrier, this.stateHeaderName); if (tracestateCollection?.Any() ?? false) { - TraceContextFormat.TryExtractTracestate(tracestateCollection.ToArray(), out tracestate); + TextMapPropagator.TryExtractTracestate(tracestateCollection.ToArray(), out tracestate); } return new PropagationContext( diff --git a/test/OpenTelemetry.Tests/Trace/Propagation/TraceContextTest.cs b/test/OpenTelemetry.Tests/Trace/Propagation/TextMapPropagatorTest.cs similarity index 85% rename from test/OpenTelemetry.Tests/Trace/Propagation/TraceContextTest.cs rename to test/OpenTelemetry.Tests/Trace/Propagation/TextMapPropagatorTest.cs index 63bdd97cc..acb461eed 100644 --- a/test/OpenTelemetry.Tests/Trace/Propagation/TraceContextTest.cs +++ b/test/OpenTelemetry.Tests/Trace/Propagation/TextMapPropagatorTest.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,7 @@ using Xunit; namespace OpenTelemetry.Context.Propagation.Tests { - public class TraceContextTest + public class TextMapPropagatorTest { private const string TraceParent = "traceparent"; private const string TraceState = "tracestate"; @@ -44,7 +44,7 @@ namespace OpenTelemetry.Context.Propagation.Tests }; [Fact] - public void TraceContextFormatCanParseExampleFromSpec() + public void CanParseExampleFromSpec() { var headers = new Dictionary { @@ -52,7 +52,7 @@ namespace OpenTelemetry.Context.Propagation.Tests { TraceState, $"congo=lZWRzIHRoNhcm5hbCBwbGVhc3VyZS4,rojo=00-{TraceId}-00f067aa0ba902b7-01" }, }; - var f = new TraceContextFormat(); + var f = new TextMapPropagator(); var ctx = f.Extract(default, headers, Getter); Assert.Equal(ActivityTraceId.CreateFromString(TraceId.AsSpan()), ctx.ActivityContext.TraceId); @@ -66,14 +66,14 @@ namespace OpenTelemetry.Context.Propagation.Tests } [Fact] - public void TraceContextFormatNotSampled() + public void NotSampled() { var headers = new Dictionary { { TraceParent, $"00-{TraceId}-{SpanId}-00" }, }; - var f = new TraceContextFormat(); + var f = new TextMapPropagator(); var ctx = f.Extract(default, headers, Getter); Assert.Equal(ActivityTraceId.CreateFromString(TraceId.AsSpan()), ctx.ActivityContext.TraceId); @@ -85,46 +85,46 @@ namespace OpenTelemetry.Context.Propagation.Tests } [Fact] - public void TraceContextFormat_IsBlankIfNoHeader() + public void IsBlankIfNoHeader() { var headers = new Dictionary(); - var f = new TraceContextFormat(); + var f = new TextMapPropagator(); var ctx = f.Extract(default, headers, Getter); Assert.False(ctx.ActivityContext.IsValid()); } [Fact] - public void TraceContextFormat_IsBlankIfInvalid() + public void IsBlankIfInvalid() { var headers = new Dictionary { { TraceParent, $"00-xyz7651916cd43dd8448eb211c80319c-{SpanId}-01" }, }; - var f = new TraceContextFormat(); + var f = new TextMapPropagator(); var ctx = f.Extract(default, headers, Getter); Assert.False(ctx.ActivityContext.IsValid()); } [Fact] - public void TraceContextFormat_TracestateToStringEmpty() + public void TracestateToStringEmpty() { var headers = new Dictionary { { TraceParent, $"00-{TraceId}-{SpanId}-01" }, }; - var f = new TraceContextFormat(); + var f = new TextMapPropagator(); var ctx = f.Extract(default, headers, Getter); Assert.Null(ctx.ActivityContext.TraceState); } [Fact] - public void TraceContextFormat_TracestateToString() + public void TracestateToString() { var headers = new Dictionary { @@ -132,14 +132,14 @@ namespace OpenTelemetry.Context.Propagation.Tests { TraceState, "k1=v1,k2=v2,k3=v3" }, }; - var f = new TraceContextFormat(); + var f = new TextMapPropagator(); var ctx = f.Extract(default, headers, Getter); Assert.Equal("k1=v1,k2=v2,k3=v3", ctx.ActivityContext.TraceState); } [Fact] - public void TraceContextFormat_Inject_NoTracestate() + public void Inject_NoTracestate() { var traceId = ActivityTraceId.CreateRandom(); var spanId = ActivitySpanId.CreateRandom(); @@ -151,14 +151,14 @@ namespace OpenTelemetry.Context.Propagation.Tests var activityContext = new ActivityContext(traceId, spanId, ActivityTraceFlags.Recorded, traceState: null); PropagationContext propagationContext = new PropagationContext(activityContext, default); var carrier = new Dictionary(); - var f = new TraceContextFormat(); + var f = new TextMapPropagator(); f.Inject(propagationContext, carrier, Setter); Assert.Equal(expectedHeaders, carrier); } [Fact] - public void TraceContextFormat_Inject_WithTracestate() + public void Inject_WithTracestate() { var traceId = ActivityTraceId.CreateRandom(); var spanId = ActivitySpanId.CreateRandom(); @@ -171,7 +171,7 @@ namespace OpenTelemetry.Context.Propagation.Tests var activityContext = new ActivityContext(traceId, spanId, ActivityTraceFlags.Recorded, expectedHeaders[TraceState]); PropagationContext propagationContext = new PropagationContext(activityContext, default); var carrier = new Dictionary(); - var f = new TraceContextFormat(); + var f = new TextMapPropagator(); f.Inject(propagationContext, carrier, Setter); Assert.Equal(expectedHeaders, carrier);