From a2008c1e5b2f7fbe9a5f2f29405a48d1c0a8d22b Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 30 Oct 2020 13:30:12 -0700 Subject: [PATCH 01/12] Add GlobalPropagators API and have instrumentation default to it --- .../Propagation/NoOpTextMapPropagator.cs | 37 +++++++++++++++ .../Context/Propagation/Propagators.cs | 34 ++++++++++++++ .../AspNetInstrumentationOptions.cs | 9 ++-- .../AspNetCoreInstrumentationOptions.cs | 9 ++-- .../HttpClientInstrumentationOptions.cs | 9 ++-- .../Logs/OpenTelemetryLoggerProvider.cs | 7 +++ src/OpenTelemetry/Sdk.cs | 10 ++++ .../BasicTests.cs | 15 ++++++ .../Context/PropagatorsTest.cs | 46 +++++++++++++++++++ .../Propagation => Shared}/TestPropagator.cs | 0 10 files changed, 158 insertions(+), 18 deletions(-) create mode 100644 src/OpenTelemetry.Api/Context/Propagation/NoOpTextMapPropagator.cs create mode 100644 src/OpenTelemetry.Api/Context/Propagation/Propagators.cs create mode 100644 test/OpenTelemetry.Tests/Context/PropagatorsTest.cs rename test/OpenTelemetry.Tests/{Trace/Propagation => Shared}/TestPropagator.cs (100%) diff --git a/src/OpenTelemetry.Api/Context/Propagation/NoOpTextMapPropagator.cs b/src/OpenTelemetry.Api/Context/Propagation/NoOpTextMapPropagator.cs new file mode 100644 index 00000000000..70db00a6e1c --- /dev/null +++ b/src/OpenTelemetry.Api/Context/Propagation/NoOpTextMapPropagator.cs @@ -0,0 +1,37 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using System.Collections.Generic; + +namespace OpenTelemetry.Context.Propagation +{ + internal class NoOpTextMapPropagator : TextMapPropagator + { + private static PropagationContext defaultPropagationContext = default; + + public override ISet Fields => null; + + public override PropagationContext Extract(PropagationContext context, T carrier, Func> getter) + { + return defaultPropagationContext; + } + + public override void Inject(PropagationContext context, T carrier, Action setter) + { + } + } +} diff --git a/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs b/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs new file mode 100644 index 00000000000..45383ea3e0d --- /dev/null +++ b/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs @@ -0,0 +1,34 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +namespace OpenTelemetry.Context.Propagation +{ + /// + /// Propagators allow setting the global default Propagators. + /// + public static class Propagators + { + /// + /// Gets or sets the Default TextMapPropagator to be used. + /// + public static TextMapPropagator DefaultTextMapPropagator { get; set; } = new NoOpTextMapPropagator(); + + internal static void Reset() + { + DefaultTextMapPropagator = new NoOpTextMapPropagator(); + } + } +} diff --git a/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentationOptions.cs index e53b92d6382..615f7e1fad7 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentationOptions.cs @@ -27,13 +27,10 @@ namespace OpenTelemetry.Instrumentation.AspNet public class AspNetInstrumentationOptions { /// - /// Gets or sets for context propagation. Default value: with & . + /// Gets or sets for context propagation. + /// By default, will be used. /// - public TextMapPropagator Propagator { get; set; } = new CompositeTextMapPropagator(new TextMapPropagator[] - { - new TraceContextPropagator(), - new BaggagePropagator(), - }); + public TextMapPropagator Propagator { get; set; } = Propagators.DefaultTextMapPropagator; /// /// Gets or sets a Filter function to filter instrumentation for requests on a per request basis. diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs index e07372fd60d..da3b9a908f0 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentationOptions.cs @@ -27,13 +27,10 @@ namespace OpenTelemetry.Instrumentation.AspNetCore public class AspNetCoreInstrumentationOptions { /// - /// Gets or sets for context propagation. Default value: with & . + /// Gets or sets for context propagation. + /// By default, will be used. /// - public TextMapPropagator Propagator { get; set; } = new CompositeTextMapPropagator(new TextMapPropagator[] - { - new TraceContextPropagator(), - new BaggagePropagator(), - }); + public TextMapPropagator Propagator { get; set; } = Propagators.DefaultTextMapPropagator; /// /// Gets or sets a Filter function to filter instrumentation for requests on a per request basis. diff --git a/src/OpenTelemetry.Instrumentation.Http/HttpClientInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.Http/HttpClientInstrumentationOptions.cs index da4293c3b64..eaf8fd1dcf3 100644 --- a/src/OpenTelemetry.Instrumentation.Http/HttpClientInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.Http/HttpClientInstrumentationOptions.cs @@ -35,13 +35,10 @@ public class HttpClientInstrumentationOptions public bool SetHttpFlavor { get; set; } /// - /// Gets or sets for context propagation. Default value: with & . + /// Gets or sets for context propagation. + /// By default, will be used. /// - public TextMapPropagator Propagator { get; set; } = new CompositeTextMapPropagator(new TextMapPropagator[] - { - new TraceContextPropagator(), - new BaggagePropagator(), - }); + public TextMapPropagator Propagator { get; set; } = Propagators.DefaultTextMapPropagator; /// /// Gets or sets a Filter function to filter instrumentation for requests on a per request basis. diff --git a/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs b/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs index 9c1799bee1b..261f63a2505 100644 --- a/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs +++ b/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs @@ -31,6 +31,13 @@ public class OpenTelemetryLoggerProvider : ILoggerProvider, ISupportExternalScop private bool disposed; private IExternalScopeProvider scopeProvider; + static OpenTelemetryLoggerProvider() + { + // Accessing Sdk class is just to trigger its static ctor, + // which sets default Propagators. + _ = Sdk.SuppressInstrumentation; + } + public OpenTelemetryLoggerProvider(IOptionsMonitor options) : this(options?.CurrentValue) { diff --git a/src/OpenTelemetry/Sdk.cs b/src/OpenTelemetry/Sdk.cs index 30fc0e3a4e9..62498ba7d15 100644 --- a/src/OpenTelemetry/Sdk.cs +++ b/src/OpenTelemetry/Sdk.cs @@ -14,6 +14,7 @@ // limitations under the License. // +using OpenTelemetry.Context.Propagation; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; @@ -24,6 +25,15 @@ namespace OpenTelemetry /// public static class Sdk { + static Sdk() + { + Propagators.DefaultTextMapPropagator = new CompositeTextMapPropagator(new TextMapPropagator[] + { + new TraceContextPropagator(), + new BaggagePropagator(), + }); + } + /// /// Gets a value indicating whether instrumentation is suppressed (disabled). /// diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs index 66572aac705..b343af26f11 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs @@ -58,6 +58,21 @@ public void AddAspNetCoreInstrumentation_BadArgs() Assert.Throws(() => builder.AddAspNetCoreInstrumentation()); } + [Fact] + public void DefaultPropagatorIsFromPropagators() + { + var options = new AspNetCoreInstrumentationOptions(); + Assert.Same(Propagators.DefaultTextMapPropagator, options.Propagator); + } + + [Fact] + public void PropagatorSetDoesNotAffectGlobalPropagators() + { + var options = new AspNetCoreInstrumentationOptions(); + options.Propagator = new TraceContextPropagator(); + Assert.NotSame(Propagators.DefaultTextMapPropagator, options.Propagator); + } + [Fact] public async Task StatusIsUnsetOn200Response() { diff --git a/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs b/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs new file mode 100644 index 00000000000..24e4b054958 --- /dev/null +++ b/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs @@ -0,0 +1,46 @@ +// +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using OpenTelemetry.Context.Propagation; +using OpenTelemetry.Context.Propagation.Tests; +using Xunit; + +namespace OpenTelemetry.Context.Tests +{ + public class PropagatorsTest : IDisposable + { + [Fact] + public static void DefaultTextMapPropagatorIsNoop() + { + Assert.IsType(Propagators.DefaultTextMapPropagator); + Assert.Same(Propagators.DefaultTextMapPropagator, Propagators.DefaultTextMapPropagator); + } + + [Fact] + public static void CanSetPropagator() + { + var testPropagator = new TestPropagator(string.Empty, string.Empty); + Propagators.DefaultTextMapPropagator = testPropagator; + Assert.Same(testPropagator, Propagators.DefaultTextMapPropagator); + } + + public void Dispose() + { + Propagators.Reset(); + } + } +} diff --git a/test/OpenTelemetry.Tests/Trace/Propagation/TestPropagator.cs b/test/OpenTelemetry.Tests/Shared/TestPropagator.cs similarity index 100% rename from test/OpenTelemetry.Tests/Trace/Propagation/TestPropagator.cs rename to test/OpenTelemetry.Tests/Shared/TestPropagator.cs From 7d4a097f2254bf1e508619d25566ef5f191ea01b Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 30 Oct 2020 13:38:26 -0700 Subject: [PATCH 02/12] changelog --- src/OpenTelemetry.Api/CHANGELOG.md | 2 ++ src/OpenTelemetry.Api/Context/Propagation/Propagators.cs | 6 ++++-- src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md | 2 ++ src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md | 2 ++ src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md | 2 ++ 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Api/CHANGELOG.md b/src/OpenTelemetry.Api/CHANGELOG.md index 3792ecf50fc..52d89e2dded 100644 --- a/src/OpenTelemetry.Api/CHANGELOG.md +++ b/src/OpenTelemetry.Api/CHANGELOG.md @@ -15,6 +15,8 @@ to CompositeTextMapPropagator. IPropagator is renamed to TextMapPropagator and changed from interface to abstract class. ([#1427](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1427)) +* Added GlobalPropagators API via Propagators.DefaultTextMapPropagator. + ([#1427](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1428)) ## 0.7.0-beta.1 diff --git a/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs b/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs index 45383ea3e0d..3770f32ec60 100644 --- a/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs +++ b/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs @@ -21,14 +21,16 @@ namespace OpenTelemetry.Context.Propagation /// public static class Propagators { + private static TextMapPropagator noop = new NoOpTextMapPropagator(); + /// /// Gets or sets the Default TextMapPropagator to be used. /// - public static TextMapPropagator DefaultTextMapPropagator { get; set; } = new NoOpTextMapPropagator(); + public static TextMapPropagator DefaultTextMapPropagator { get; set; } = noop; internal static void Reset() { - DefaultTextMapPropagator = new NoOpTextMapPropagator(); + DefaultTextMapPropagator = noop; } } } diff --git a/src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md index 5bf0cc5b2ae..dd2c46a1853 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md @@ -6,6 +6,8 @@ to CompositeTextMapPropagator. IPropagator is renamed to TextMapPropagator and changed from interface to abstract class. ([#1427](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1427)) +* Propagators.DefaultTextMapPropagator will be used as the default Propagator + ([#1427](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1428)) ## 0.7.0-beta.1 diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md index 973f95d0f2f..0de5b6a4869 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md @@ -14,6 +14,8 @@ to CompositeTextMapPropagator. IPropagator is renamed to TextMapPropagator and changed from interface to abstract class. ([#1427](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1427)) +* Propagators.DefaultTextMapPropagator will be used as the default Propagator + ([#1427](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1428)) ## 0.7.0-beta.1 diff --git a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md index e42f76fb8ec..0e4d8e4a630 100644 --- a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md @@ -10,6 +10,8 @@ to CompositeTextMapPropagator. IPropagator is renamed to TextMapPropagator and changed from interface to abstract class. ([#1427](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1427)) +* Propagators.DefaultTextMapPropagator will be used as the default Propagator + ([#1427](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1428)) ## 0.7.0-beta.1 From 655753ac8967c717ea428b534e50be8cea41a5f2 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 30 Oct 2020 13:39:21 -0700 Subject: [PATCH 03/12] fix name --- .../Context/Propagation/NoOpTextMapPropagator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Api/Context/Propagation/NoOpTextMapPropagator.cs b/src/OpenTelemetry.Api/Context/Propagation/NoOpTextMapPropagator.cs index 70db00a6e1c..97f6b09a2e5 100644 --- a/src/OpenTelemetry.Api/Context/Propagation/NoOpTextMapPropagator.cs +++ b/src/OpenTelemetry.Api/Context/Propagation/NoOpTextMapPropagator.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); From dd21bef1407bbc44378bedd7f319db0e7799d70c Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 30 Oct 2020 13:55:29 -0700 Subject: [PATCH 04/12] reset after --- test/OpenTelemetry.Tests/Context/PropagatorsTest.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs b/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs index 24e4b054958..71104bb6d36 100644 --- a/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs +++ b/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs @@ -23,6 +23,11 @@ namespace OpenTelemetry.Context.Tests { public class PropagatorsTest : IDisposable { + public PropagatorsTest() + { + Propagators.Reset(); + } + [Fact] public static void DefaultTextMapPropagatorIsNoop() { From df433bea8b79ffb57ec6854402c4d745a718a494 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 30 Oct 2020 14:01:03 -0700 Subject: [PATCH 05/12] min comment address --- .../Context/Propagation/NoOpTextMapPropagator.cs | 8 ++++---- src/OpenTelemetry.Api/Context/Propagation/Propagators.cs | 6 +++--- test/OpenTelemetry.Tests/Context/PropagatorsTest.cs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/OpenTelemetry.Api/Context/Propagation/NoOpTextMapPropagator.cs b/src/OpenTelemetry.Api/Context/Propagation/NoOpTextMapPropagator.cs index 97f6b09a2e5..8060df2977e 100644 --- a/src/OpenTelemetry.Api/Context/Propagation/NoOpTextMapPropagator.cs +++ b/src/OpenTelemetry.Api/Context/Propagation/NoOpTextMapPropagator.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,15 +19,15 @@ namespace OpenTelemetry.Context.Propagation { - internal class NoOpTextMapPropagator : TextMapPropagator + internal class NoopTextMapPropagator : TextMapPropagator { - private static PropagationContext defaultPropagationContext = default; + private static readonly PropagationContext DefaultPropagationContext = default; public override ISet Fields => null; public override PropagationContext Extract(PropagationContext context, T carrier, Func> getter) { - return defaultPropagationContext; + return DefaultPropagationContext; } public override void Inject(PropagationContext context, T carrier, Action setter) diff --git a/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs b/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs index 3770f32ec60..88bd2b38c45 100644 --- a/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs +++ b/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs @@ -21,16 +21,16 @@ namespace OpenTelemetry.Context.Propagation /// public static class Propagators { - private static TextMapPropagator noop = new NoOpTextMapPropagator(); + private static readonly TextMapPropagator Noop = new NoopTextMapPropagator(); /// /// Gets or sets the Default TextMapPropagator to be used. /// - public static TextMapPropagator DefaultTextMapPropagator { get; set; } = noop; + public static TextMapPropagator DefaultTextMapPropagator { get; set; } = Noop; internal static void Reset() { - DefaultTextMapPropagator = noop; + DefaultTextMapPropagator = Noop; } } } diff --git a/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs b/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs index 71104bb6d36..44824a655a8 100644 --- a/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs +++ b/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs @@ -31,7 +31,7 @@ public PropagatorsTest() [Fact] public static void DefaultTextMapPropagatorIsNoop() { - Assert.IsType(Propagators.DefaultTextMapPropagator); + Assert.IsType(Propagators.DefaultTextMapPropagator); Assert.Same(Propagators.DefaultTextMapPropagator, Propagators.DefaultTextMapPropagator); } From 5d6989c423c4b3068fb6dc716f53356929531cd1 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 30 Oct 2020 14:04:30 -0700 Subject: [PATCH 06/12] move id format to same place as context propagator --- src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs | 2 +- src/OpenTelemetry/Sdk.cs | 4 ++++ src/OpenTelemetry/Trace/TracerProviderSdk.cs | 6 ------ 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs b/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs index 261f63a2505..abbc3e4103e 100644 --- a/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs +++ b/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs @@ -34,7 +34,7 @@ public class OpenTelemetryLoggerProvider : ILoggerProvider, ISupportExternalScop static OpenTelemetryLoggerProvider() { // Accessing Sdk class is just to trigger its static ctor, - // which sets default Propagators. + // which sets default Propagators and default Activity Id format _ = Sdk.SuppressInstrumentation; } diff --git a/src/OpenTelemetry/Sdk.cs b/src/OpenTelemetry/Sdk.cs index 62498ba7d15..d8725ba7329 100644 --- a/src/OpenTelemetry/Sdk.cs +++ b/src/OpenTelemetry/Sdk.cs @@ -14,6 +14,7 @@ // limitations under the License. // +using System.Diagnostics; using OpenTelemetry.Context.Propagation; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; @@ -32,6 +33,9 @@ static Sdk() new TraceContextPropagator(), new BaggagePropagator(), }); + + Activity.DefaultIdFormat = ActivityIdFormat.W3C; + Activity.ForceDefaultIdFormat = true; } /// diff --git a/src/OpenTelemetry/Trace/TracerProviderSdk.cs b/src/OpenTelemetry/Trace/TracerProviderSdk.cs index 3fdca25f7db..2ee6ad57ccb 100644 --- a/src/OpenTelemetry/Trace/TracerProviderSdk.cs +++ b/src/OpenTelemetry/Trace/TracerProviderSdk.cs @@ -34,12 +34,6 @@ internal class TracerProviderSdk : TracerProvider private readonly ActivitySourceAdapter adapter; private BaseProcessor processor; - static TracerProviderSdk() - { - Activity.DefaultIdFormat = ActivityIdFormat.W3C; - Activity.ForceDefaultIdFormat = true; - } - internal TracerProviderSdk( Resource resource, IEnumerable sources, From d42da65beab21d79a996508a738463c83b7801b6 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 30 Oct 2020 14:51:59 -0700 Subject: [PATCH 07/12] renam --- .../Propagation/{NoOpTextMapPropagator.cs => NoopPropagator.cs} | 2 +- src/OpenTelemetry.Api/Context/Propagation/Propagators.cs | 2 +- test/OpenTelemetry.Tests/Context/PropagatorsTest.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/OpenTelemetry.Api/Context/Propagation/{NoOpTextMapPropagator.cs => NoopPropagator.cs} (95%) diff --git a/src/OpenTelemetry.Api/Context/Propagation/NoOpTextMapPropagator.cs b/src/OpenTelemetry.Api/Context/Propagation/NoopPropagator.cs similarity index 95% rename from src/OpenTelemetry.Api/Context/Propagation/NoOpTextMapPropagator.cs rename to src/OpenTelemetry.Api/Context/Propagation/NoopPropagator.cs index 8060df2977e..25bd38d1509 100644 --- a/src/OpenTelemetry.Api/Context/Propagation/NoOpTextMapPropagator.cs +++ b/src/OpenTelemetry.Api/Context/Propagation/NoopPropagator.cs @@ -19,7 +19,7 @@ namespace OpenTelemetry.Context.Propagation { - internal class NoopTextMapPropagator : TextMapPropagator + internal class NoopPropagator : TextMapPropagator { private static readonly PropagationContext DefaultPropagationContext = default; diff --git a/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs b/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs index 88bd2b38c45..b7b0b7c0be7 100644 --- a/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs +++ b/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs @@ -21,7 +21,7 @@ namespace OpenTelemetry.Context.Propagation /// public static class Propagators { - private static readonly TextMapPropagator Noop = new NoopTextMapPropagator(); + private static readonly TextMapPropagator Noop = new NoopPropagator(); /// /// Gets or sets the Default TextMapPropagator to be used. diff --git a/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs b/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs index 44824a655a8..63ee9cd9656 100644 --- a/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs +++ b/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs @@ -31,7 +31,7 @@ public PropagatorsTest() [Fact] public static void DefaultTextMapPropagatorIsNoop() { - Assert.IsType(Propagators.DefaultTextMapPropagator); + Assert.IsType(Propagators.DefaultTextMapPropagator); Assert.Same(Propagators.DefaultTextMapPropagator, Propagators.DefaultTextMapPropagator); } From 51de2ae9a90f73d733b446b504d66a1826f8ca30 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 30 Oct 2020 15:02:47 -0700 Subject: [PATCH 08/12] renai --- .../Propagation/{NoopPropagator.cs => NoopTextMapPropagator.cs} | 2 +- src/OpenTelemetry.Api/Context/Propagation/Propagators.cs | 2 +- test/OpenTelemetry.Tests/Context/PropagatorsTest.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/OpenTelemetry.Api/Context/Propagation/{NoopPropagator.cs => NoopTextMapPropagator.cs} (95%) diff --git a/src/OpenTelemetry.Api/Context/Propagation/NoopPropagator.cs b/src/OpenTelemetry.Api/Context/Propagation/NoopTextMapPropagator.cs similarity index 95% rename from src/OpenTelemetry.Api/Context/Propagation/NoopPropagator.cs rename to src/OpenTelemetry.Api/Context/Propagation/NoopTextMapPropagator.cs index 25bd38d1509..8060df2977e 100644 --- a/src/OpenTelemetry.Api/Context/Propagation/NoopPropagator.cs +++ b/src/OpenTelemetry.Api/Context/Propagation/NoopTextMapPropagator.cs @@ -19,7 +19,7 @@ namespace OpenTelemetry.Context.Propagation { - internal class NoopPropagator : TextMapPropagator + internal class NoopTextMapPropagator : TextMapPropagator { private static readonly PropagationContext DefaultPropagationContext = default; diff --git a/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs b/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs index b7b0b7c0be7..88bd2b38c45 100644 --- a/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs +++ b/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs @@ -21,7 +21,7 @@ namespace OpenTelemetry.Context.Propagation /// public static class Propagators { - private static readonly TextMapPropagator Noop = new NoopPropagator(); + private static readonly TextMapPropagator Noop = new NoopTextMapPropagator(); /// /// Gets or sets the Default TextMapPropagator to be used. diff --git a/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs b/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs index 63ee9cd9656..44824a655a8 100644 --- a/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs +++ b/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs @@ -31,7 +31,7 @@ public PropagatorsTest() [Fact] public static void DefaultTextMapPropagatorIsNoop() { - Assert.IsType(Propagators.DefaultTextMapPropagator); + Assert.IsType(Propagators.DefaultTextMapPropagator); Assert.Same(Propagators.DefaultTextMapPropagator, Propagators.DefaultTextMapPropagator); } From 08a5c63fcfbb7ffe68242123ecbc97843871a636 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 30 Oct 2020 15:45:31 -0700 Subject: [PATCH 09/12] text initialize correctly --- test/OpenTelemetry.Tests/Context/PropagatorsTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs b/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs index 44824a655a8..c6765568a4e 100644 --- a/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs +++ b/test/OpenTelemetry.Tests/Context/PropagatorsTest.cs @@ -29,14 +29,14 @@ public PropagatorsTest() } [Fact] - public static void DefaultTextMapPropagatorIsNoop() + public void DefaultTextMapPropagatorIsNoop() { Assert.IsType(Propagators.DefaultTextMapPropagator); Assert.Same(Propagators.DefaultTextMapPropagator, Propagators.DefaultTextMapPropagator); } [Fact] - public static void CanSetPropagator() + public void CanSetPropagator() { var testPropagator = new TestPropagator(string.Empty, string.Empty); Propagators.DefaultTextMapPropagator = testPropagator; From 9756c1161feca8d04d3e4b17883a9f9d550f15a8 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Mon, 2 Nov 2020 09:55:17 -0800 Subject: [PATCH 10/12] modify microsoervice example to pick global propagator --- examples/MicroserviceExample/Utils/Messaging/MessageSender.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/MicroserviceExample/Utils/Messaging/MessageSender.cs b/examples/MicroserviceExample/Utils/Messaging/MessageSender.cs index e8715ad79b3..b87ecec04f4 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 TextMapPropagator Propagator = new TraceContextPropagator(); + private static readonly TextMapPropagator Propagator = Propagators.DefaultTextMapPropagator; private readonly ILogger logger; private readonly IConnection connection; From b24435bcd6c7a88f5879c5df755dfd660d668099 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Mon, 2 Nov 2020 12:27:06 -0800 Subject: [PATCH 11/12] make Global propagator get only in api --- src/OpenTelemetry.Api/Context/Propagation/Propagators.cs | 7 +++++-- .../AspNetInstrumentationOptions.cs | 2 +- .../Implementation/HttpInListener.cs | 8 +++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs b/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs index 88bd2b38c45..645cd600bce 100644 --- a/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs +++ b/src/OpenTelemetry.Api/Context/Propagation/Propagators.cs @@ -24,9 +24,12 @@ public static class Propagators private static readonly TextMapPropagator Noop = new NoopTextMapPropagator(); /// - /// Gets or sets the Default TextMapPropagator to be used. + /// Gets the Default TextMapPropagator to be used. /// - public static TextMapPropagator DefaultTextMapPropagator { get; set; } = Noop; + /// + /// Setting this can be done only from Sdk. + /// + public static TextMapPropagator DefaultTextMapPropagator { get; internal set; } = Noop; internal static void Reset() { diff --git a/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentationOptions.cs index 615f7e1fad7..c0c97345e72 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentationOptions.cs @@ -30,7 +30,7 @@ public class AspNetInstrumentationOptions /// Gets or sets for context propagation. /// By default, will be used. /// - public TextMapPropagator Propagator { get; set; } = Propagators.DefaultTextMapPropagator; + public TextMapPropagator Propagator { get; set; } /// /// Gets or sets a Filter function to filter instrumentation for requests on a per request basis. diff --git a/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs index d1e5c99f6e3..ac7d3636704 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs @@ -69,10 +69,11 @@ public override void OnStartActivity(Activity activity, object payload) var request = context.Request; var requestValues = request.Unvalidated; + var textMapPropagator = this.options.Propagator ?? Propagators.DefaultTextMapPropagator; - if (!(this.options.Propagator is TraceContextPropagator)) + if (!(textMapPropagator is TraceContextPropagator)) { - var ctx = this.options.Propagator.Extract(default, request, HttpRequestHeaderValuesGetter); + var ctx = textMapPropagator.Extract(default, request, HttpRequestHeaderValuesGetter); if (ctx.ActivityContext.IsValid() && ctx.ActivityContext != new ActivityContext(activity.TraceId, activity.ParentSpanId, activity.ActivityTraceFlags, activity.TraceStateString, true)) @@ -139,7 +140,8 @@ public override void OnStopActivity(Activity activity, object payload) Activity activityToEnrich = activity; Activity createdActivity = null; - bool isCustomPropagator = !(this.options.Propagator is TraceContextPropagator); + var textMapPropagator = this.options.Propagator ?? Propagators.DefaultTextMapPropagator; + bool isCustomPropagator = !(textMapPropagator is TraceContextPropagator); if (isCustomPropagator) { From 445f40e1ec3838fbf3c5be762c1cbb2e1741e658 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Mon, 2 Nov 2020 14:22:46 -0800 Subject: [PATCH 12/12] Add SetDefaultPropagato to SDK --- src/OpenTelemetry/Sdk.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/OpenTelemetry/Sdk.cs b/src/OpenTelemetry/Sdk.cs index d8725ba7329..aa91e985150 100644 --- a/src/OpenTelemetry/Sdk.cs +++ b/src/OpenTelemetry/Sdk.cs @@ -43,6 +43,15 @@ static Sdk() /// public static bool SuppressInstrumentation => SuppressInstrumentationScope.IsSuppressed; + /// + /// Sets the Default TextMapPropagator. + /// + /// TextMapPropagator to be set as default. + public static void SetDefaultTextMapPropagator(TextMapPropagator textMapPropagator) + { + Propagators.DefaultTextMapPropagator = textMapPropagator; + } + /// /// Creates MeterProviderBuilder which should be used to build MeterProvider. ///