From bb2ec764b79b2915ca314123669c7c81cde2c372 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Wed, 4 Nov 2020 12:00:56 -0800 Subject: [PATCH 01/12] Introduces the concept of IProviderContainer which allows injection of a TracerProvider into lower levels (Processor, Exporter, etc.). --- .../JaegerExporter.cs | 20 +++---- src/OpenTelemetry/BaseExportProcessor.cs | 10 ++++ src/OpenTelemetry/BaseProcessor.cs | 9 ++++ src/OpenTelemetry/IProviderContainer.cs | 31 +++++++++++ src/OpenTelemetry/Trace/ActivityExtensions.cs | 53 ------------------- .../Trace/ActivitySourceAdapter.cs | 6 +-- .../Trace/TracerProviderExtensions.cs | 11 ++++ src/OpenTelemetry/Trace/TracerProviderSdk.cs | 10 ++-- .../JaegerExporterTests.cs | 26 ++++----- 9 files changed, 91 insertions(+), 85 deletions(-) create mode 100644 src/OpenTelemetry/IProviderContainer.cs delete mode 100644 src/OpenTelemetry/Trace/ActivityExtensions.cs diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs index 4f89a3e8e6b..776b8ee75e5 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs @@ -27,7 +27,7 @@ namespace OpenTelemetry.Exporter.Jaeger { - public class JaegerExporter : BaseExporter + public class JaegerExporter : BaseExporter, IProviderContainer { private readonly int maxPayloadSizeInBytes; private readonly TProtocolFactory protocolFactory; @@ -67,11 +67,6 @@ public override ExportResult Export(in Batch activityBatch) { foreach (var activity in activityBatch) { - if (this.processCache == null) - { - this.ApplyLibraryResource(activity.GetResource()); - } - this.AppendSpan(activity.ToJaegerSpan()); } @@ -87,18 +82,23 @@ public override ExportResult Export(in Batch activityBatch) } } - internal void ApplyLibraryResource(Resource libraryResource) + void IProviderContainer.SetProvider(TracerProvider tracerProvider) + { + this.SetResource(tracerProvider.GetResource()); + } + + internal void SetResource(Resource resource) { - if (libraryResource is null) + if (resource is null) { - throw new ArgumentNullException(nameof(libraryResource)); + throw new ArgumentNullException(nameof(resource)); } var process = this.Process; string serviceName = null; string serviceNamespace = null; - foreach (var label in libraryResource.Attributes) + foreach (var label in resource.Attributes) { string key = label.Key; diff --git a/src/OpenTelemetry/BaseExportProcessor.cs b/src/OpenTelemetry/BaseExportProcessor.cs index b9ed83bc4c3..819dac3f971 100644 --- a/src/OpenTelemetry/BaseExportProcessor.cs +++ b/src/OpenTelemetry/BaseExportProcessor.cs @@ -16,6 +16,7 @@ using System; using OpenTelemetry.Internal; +using OpenTelemetry.Trace; namespace OpenTelemetry { @@ -46,6 +47,15 @@ public sealed override void OnStart(T data) /// public abstract override void OnEnd(T data); + /// + internal override void SetTracerProvider(TracerProvider tracerProvider) + { + if (this.exporter is IProviderContainer providerContainer) + { + providerContainer.SetProvider(tracerProvider); + } + } + /// protected override bool OnShutdown(int timeoutMilliseconds) { diff --git a/src/OpenTelemetry/BaseProcessor.cs b/src/OpenTelemetry/BaseProcessor.cs index 5e6b5a538fa..9805d3c28e2 100644 --- a/src/OpenTelemetry/BaseProcessor.cs +++ b/src/OpenTelemetry/BaseProcessor.cs @@ -17,6 +17,7 @@ using System; using System.Threading; using OpenTelemetry.Internal; +using OpenTelemetry.Trace; namespace OpenTelemetry { @@ -141,6 +142,14 @@ public void Dispose() GC.SuppressFinalize(this); } + /// + /// Set the parent . + /// + /// . + internal virtual void SetTracerProvider(TracerProvider tracerProvider) + { + } + /// /// Called by ForceFlush. This function should block the current /// thread until flush completed, shutdown signaled or timed out. diff --git a/src/OpenTelemetry/IProviderContainer.cs b/src/OpenTelemetry/IProviderContainer.cs new file mode 100644 index 00000000000..c808ab032f8 --- /dev/null +++ b/src/OpenTelemetry/IProviderContainer.cs @@ -0,0 +1,31 @@ +// +// 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 +{ + /// + /// Represents a provider container. + /// + /// The provider type. + public interface IProviderContainer + { + /// + /// Sets the provider in the container. + /// + /// Provider instance. + void SetProvider(T provider); + } +} diff --git a/src/OpenTelemetry/Trace/ActivityExtensions.cs b/src/OpenTelemetry/Trace/ActivityExtensions.cs deleted file mode 100644 index b6d339c34b4..00000000000 --- a/src/OpenTelemetry/Trace/ActivityExtensions.cs +++ /dev/null @@ -1,53 +0,0 @@ -// -// 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.Diagnostics; -using System.Runtime.CompilerServices; -using OpenTelemetry.Resources; - -namespace OpenTelemetry.Trace -{ - /// - /// Extension methods on Activity. - /// - public static class ActivityExtensions - { - internal const string ResourcePropertyName = "OTel.Resource"; - - /// - /// Gets the Resource associated with the Activity. - /// - /// Activity instance. - /// The resource. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Resource GetResource(this Activity activity) - { - return activity?.GetCustomProperty(ResourcePropertyName) is Resource res - ? res - : Resource.Empty; - } - - /// - /// Sets the Resource associated with the Activity. - /// - /// Activity instance. - /// Resource to set to. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void SetResource(this Activity activity, Resource resource) - { - activity.SetCustomProperty(ResourcePropertyName, resource); - } - } -} diff --git a/src/OpenTelemetry/Trace/ActivitySourceAdapter.cs b/src/OpenTelemetry/Trace/ActivitySourceAdapter.cs index b39184d72b0..b306be85e0b 100644 --- a/src/OpenTelemetry/Trace/ActivitySourceAdapter.cs +++ b/src/OpenTelemetry/Trace/ActivitySourceAdapter.cs @@ -18,7 +18,6 @@ using System.Diagnostics; using System.Linq.Expressions; using OpenTelemetry.Internal; -using OpenTelemetry.Resources; namespace OpenTelemetry.Trace { @@ -41,14 +40,12 @@ public class ActivitySourceAdapter { private static readonly Action SetKindProperty = CreateActivityKindSetter(); private readonly Sampler sampler; - private readonly Resource resource; private readonly Action getRequestedDataAction; private BaseProcessor activityProcessor; - internal ActivitySourceAdapter(Sampler sampler, BaseProcessor activityProcessor, Resource resource) + internal ActivitySourceAdapter(Sampler sampler, BaseProcessor activityProcessor) { this.sampler = sampler ?? throw new ArgumentNullException(nameof(sampler)); - this.resource = resource ?? throw new ArgumentNullException(nameof(resource)); if (this.sampler is AlwaysOnSampler) { this.getRequestedDataAction = this.RunGetRequestedDataAlwaysOnSampler; @@ -83,7 +80,6 @@ public void Start(Activity activity, ActivityKind kind) this.getRequestedDataAction(activity); if (activity.IsAllDataRequested) { - activity.SetResource(this.resource); this.activityProcessor?.OnStart(activity); } } diff --git a/src/OpenTelemetry/Trace/TracerProviderExtensions.cs b/src/OpenTelemetry/Trace/TracerProviderExtensions.cs index f503cb59f97..ef99aaf4f3b 100644 --- a/src/OpenTelemetry/Trace/TracerProviderExtensions.cs +++ b/src/OpenTelemetry/Trace/TracerProviderExtensions.cs @@ -16,6 +16,7 @@ using System; using System.Diagnostics; +using OpenTelemetry.Resources; namespace OpenTelemetry.Trace { @@ -42,5 +43,15 @@ public static TracerProvider AddProcessor(this TracerProvider provider, BaseProc return trait.AddProcessor(processor); } + + public static Resource GetResource(this TracerProvider tracerProvider) + { + if (tracerProvider is TracerProviderSdk tracerProviderSdk) + { + return tracerProviderSdk.Resource; + } + + return Resource.Empty; + } } } diff --git a/src/OpenTelemetry/Trace/TracerProviderSdk.cs b/src/OpenTelemetry/Trace/TracerProviderSdk.cs index 2ee6ad57ccb..23b81a15ee1 100644 --- a/src/OpenTelemetry/Trace/TracerProviderSdk.cs +++ b/src/OpenTelemetry/Trace/TracerProviderSdk.cs @@ -29,7 +29,6 @@ internal class TracerProviderSdk : TracerProvider { private readonly List instrumentations = new List(); private readonly ActivityListener listener; - private readonly Resource resource; private readonly Sampler sampler; private readonly ActivitySourceAdapter adapter; private BaseProcessor processor; @@ -41,17 +40,19 @@ internal TracerProviderSdk( Sampler sampler, List> processors) { - this.resource = resource; + this.Resource = resource; this.sampler = sampler; foreach (var processor in processors) { + processor.SetTracerProvider(this); + this.AddProcessor(processor); } if (instrumentationFactories.Any()) { - this.adapter = new ActivitySourceAdapter(sampler, this.processor, resource); + this.adapter = new ActivitySourceAdapter(sampler, this.processor); foreach (var instrumentationFactory in instrumentationFactories) { this.instrumentations.Add(instrumentationFactory.Factory(this.adapter)); @@ -72,7 +73,6 @@ internal TracerProviderSdk( if (SuppressInstrumentationScope.IncrementIfTriggered() == 0) { - activity.SetResource(this.resource); this.processor?.OnStart(activity); } }, @@ -156,6 +156,8 @@ internal TracerProviderSdk( this.listener = listener; } + internal Resource Resource { get; } + internal TracerProviderSdk AddProcessor(BaseProcessor processor) { if (processor == null) diff --git a/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterTests.cs b/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterTests.cs index a1874ca5719..7873a8ce68e 100644 --- a/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterTests.cs @@ -46,33 +46,33 @@ public void JaegerTraceExporter_ctor_NullServiceNameAllowed() } [Fact] - public void JaegerTraceExporter_ApplyLibraryResource_UpdatesServiceName() + public void JaegerTraceExporter_SetResource_UpdatesServiceName() { using var jaegerTraceExporter = new JaegerExporter(new JaegerExporterOptions()); var process = jaegerTraceExporter.Process; process.ServiceName = "TestService"; - jaegerTraceExporter.ApplyLibraryResource(Resource.Empty); + jaegerTraceExporter.SetResource(Resource.Empty); Assert.Equal("TestService", process.ServiceName); - jaegerTraceExporter.ApplyLibraryResource(Resources.Resources.CreateServiceResource("MyService")); + jaegerTraceExporter.SetResource(Resources.Resources.CreateServiceResource("MyService")); Assert.Equal("MyService", process.ServiceName); - jaegerTraceExporter.ApplyLibraryResource(Resources.Resources.CreateServiceResource("MyService", serviceNamespace: "MyNamespace")); + jaegerTraceExporter.SetResource(Resources.Resources.CreateServiceResource("MyService", serviceNamespace: "MyNamespace")); Assert.Equal("MyNamespace.MyService", process.ServiceName); } [Fact] - public void JaegerTraceExporter_ApplyLibraryResource_CreatesTags() + public void JaegerTraceExporter_SetResource_CreatesTags() { using var jaegerTraceExporter = new JaegerExporter(new JaegerExporterOptions()); var process = jaegerTraceExporter.Process; - jaegerTraceExporter.ApplyLibraryResource(new Resource(new Dictionary + jaegerTraceExporter.SetResource(new Resource(new Dictionary { ["Tag"] = "value", })); @@ -83,14 +83,14 @@ public void JaegerTraceExporter_ApplyLibraryResource_CreatesTags() } [Fact] - public void JaegerTraceExporter_ApplyLibraryResource_CombinesTags() + public void JaegerTraceExporter_SetResource_CombinesTags() { using var jaegerTraceExporter = new JaegerExporter(new JaegerExporterOptions()); var process = jaegerTraceExporter.Process; process.Tags = new Dictionary { ["Tag1"] = new KeyValuePair("Tag1", "value1").ToJaegerTag() }; - jaegerTraceExporter.ApplyLibraryResource(new Resource(new Dictionary + jaegerTraceExporter.SetResource(new Resource(new Dictionary { ["Tag2"] = "value2", })); @@ -102,12 +102,12 @@ public void JaegerTraceExporter_ApplyLibraryResource_CombinesTags() } [Fact] - public void JaegerTraceExporter_ApplyLibraryResource_IgnoreLibraryResources() + public void JaegerTraceExporter_SetResource_IgnoreLibraryResources() { using var jaegerTraceExporter = new JaegerExporter(new JaegerExporterOptions()); var process = jaegerTraceExporter.Process; - jaegerTraceExporter.ApplyLibraryResource(new Resource(new Dictionary + jaegerTraceExporter.SetResource(new Resource(new Dictionary { [Resource.LibraryNameKey] = "libname", [Resource.LibraryVersionKey] = "libversion", @@ -121,7 +121,7 @@ public void JaegerTraceExporter_BuildBatchesToTransmit_DefaultBatch() { // Arrange using var jaegerExporter = new JaegerExporter(new JaegerExporterOptions { ServiceName = "TestService" }); - jaegerExporter.ApplyLibraryResource(Resource.Empty); + jaegerExporter.SetResource(Resource.Empty); // Act jaegerExporter.AppendSpan(CreateTestJaegerSpan()); @@ -141,7 +141,7 @@ public void JaegerTraceExporter_BuildBatchesToTransmit_MultipleBatches() { // Arrange using var jaegerExporter = new JaegerExporter(new JaegerExporterOptions { ServiceName = "TestService" }); - jaegerExporter.ApplyLibraryResource(Resource.Empty); + jaegerExporter.SetResource(Resource.Empty); // Act jaegerExporter.AppendSpan(CreateTestJaegerSpan()); @@ -172,7 +172,7 @@ public void JaegerTraceExporter_BuildBatchesToTransmit_FlushedBatch() { // Arrange using var jaegerExporter = new JaegerExporter(new JaegerExporterOptions { ServiceName = "TestService", MaxPayloadSizeInBytes = 1500 }); - jaegerExporter.ApplyLibraryResource(Resource.Empty); + jaegerExporter.SetResource(Resource.Empty); // Act jaegerExporter.AppendSpan(CreateTestJaegerSpan()); From 34d8cf21f232a5219846bca60dc2acfe6a4218d1 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Wed, 4 Nov 2020 12:58:40 -0800 Subject: [PATCH 02/12] Removed IProviderContainer and fixed the provider types. --- .../JaegerExporter.cs | 13 +++---- src/OpenTelemetry/BaseExportProcessor.cs | 16 ++++++--- src/OpenTelemetry/BaseExporter.cs | 34 +++++++++++++++++++ src/OpenTelemetry/BaseProcessor.cs | 13 +++++++ src/OpenTelemetry/IProviderContainer.cs | 31 ----------------- .../Logs/OpenTelemetryLoggerProvider.cs | 2 ++ 6 files changed, 68 insertions(+), 41 deletions(-) delete mode 100644 src/OpenTelemetry/IProviderContainer.cs diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs index 776b8ee75e5..27a04e964aa 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs @@ -27,7 +27,7 @@ namespace OpenTelemetry.Exporter.Jaeger { - public class JaegerExporter : BaseExporter, IProviderContainer + public class JaegerExporter : BaseExporter { private readonly int maxPayloadSizeInBytes; private readonly TProtocolFactory protocolFactory; @@ -82,11 +82,6 @@ public override ExportResult Export(in Batch activityBatch) } } - void IProviderContainer.SetProvider(TracerProvider tracerProvider) - { - this.SetResource(tracerProvider.GetResource()); - } - internal void SetResource(Resource resource) { if (resource is null) @@ -203,6 +198,12 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); } + /// + protected override void OnTracerProviderSet(TracerProvider tracerProvider) + { + this.SetResource(tracerProvider.GetResource()); + } + private void SendCurrentBatches(Batch workingBatch) { try diff --git a/src/OpenTelemetry/BaseExportProcessor.cs b/src/OpenTelemetry/BaseExportProcessor.cs index 819dac3f971..fa15466639c 100644 --- a/src/OpenTelemetry/BaseExportProcessor.cs +++ b/src/OpenTelemetry/BaseExportProcessor.cs @@ -16,6 +16,9 @@ using System; using OpenTelemetry.Internal; +#if NET461 || NETSTANDARD2_0 +using OpenTelemetry.Logs; +#endif using OpenTelemetry.Trace; namespace OpenTelemetry @@ -50,11 +53,16 @@ public sealed override void OnStart(T data) /// internal override void SetTracerProvider(TracerProvider tracerProvider) { - if (this.exporter is IProviderContainer providerContainer) - { - providerContainer.SetProvider(tracerProvider); - } + this.exporter.SetTracerProvider(tracerProvider); + } + +#if NET461 || NETSTANDARD2_0 + /// + internal override void SetLogProvider(OpenTelemetryLoggerProvider logProvider) + { + this.exporter.SetLogProvider(logProvider); } +#endif /// protected override bool OnShutdown(int timeoutMilliseconds) diff --git a/src/OpenTelemetry/BaseExporter.cs b/src/OpenTelemetry/BaseExporter.cs index 1b0d0c0c6d9..9748601554a 100644 --- a/src/OpenTelemetry/BaseExporter.cs +++ b/src/OpenTelemetry/BaseExporter.cs @@ -17,6 +17,10 @@ using System; using System.Threading; using OpenTelemetry.Internal; +#if NET461 || NETSTANDARD2_0 +using OpenTelemetry.Logs; +#endif +using OpenTelemetry.Trace; namespace OpenTelemetry { @@ -100,6 +104,18 @@ public void Dispose() GC.SuppressFinalize(this); } + internal void SetTracerProvider(TracerProvider tracerProvider) + { + this.OnTracerProviderSet(tracerProvider); + } + +#if NET461 || NETSTANDARD2_0 + internal void SetLogProvider(OpenTelemetryLoggerProvider logProvider) + { + this.OnLogProviderSet(logProvider); + } +#endif + /// /// Called by Shutdown. This function should block the current /// thread until shutdown completed or timed out. @@ -132,5 +148,23 @@ protected virtual bool OnShutdown(int timeoutMilliseconds) protected virtual void Dispose(bool disposing) { } + + /// + /// Called when the parent is set on the exporter. + /// + /// . + protected virtual void OnTracerProviderSet(TracerProvider tracerProvider) + { + } + +#if NET461 || NETSTANDARD2_0 + /// + /// Called when the parent is set on the exporter. + /// + /// . + protected virtual void OnLogProviderSet(OpenTelemetryLoggerProvider logProvider) + { + } +#endif } } diff --git a/src/OpenTelemetry/BaseProcessor.cs b/src/OpenTelemetry/BaseProcessor.cs index 9805d3c28e2..fc3debf602b 100644 --- a/src/OpenTelemetry/BaseProcessor.cs +++ b/src/OpenTelemetry/BaseProcessor.cs @@ -17,6 +17,9 @@ using System; using System.Threading; using OpenTelemetry.Internal; +#if NET461 || NETSTANDARD2_0 +using OpenTelemetry.Logs; +#endif using OpenTelemetry.Trace; namespace OpenTelemetry @@ -150,6 +153,16 @@ internal virtual void SetTracerProvider(TracerProvider tracerProvider) { } +#if NET461 || NETSTANDARD2_0 + /// + /// Set the parent . + /// + /// . + internal virtual void SetLogProvider(OpenTelemetryLoggerProvider logProvider) + { + } +#endif + /// /// Called by ForceFlush. This function should block the current /// thread until flush completed, shutdown signaled or timed out. diff --git a/src/OpenTelemetry/IProviderContainer.cs b/src/OpenTelemetry/IProviderContainer.cs deleted file mode 100644 index c808ab032f8..00000000000 --- a/src/OpenTelemetry/IProviderContainer.cs +++ /dev/null @@ -1,31 +0,0 @@ -// -// 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 -{ - /// - /// Represents a provider container. - /// - /// The provider type. - public interface IProviderContainer - { - /// - /// Sets the provider in the container. - /// - /// Provider instance. - void SetProvider(T provider); - } -} diff --git a/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs b/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs index abbc3e4103e..aa3fc13b655 100644 --- a/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs +++ b/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs @@ -50,6 +50,8 @@ internal OpenTelemetryLoggerProvider(OpenTelemetryLoggerOptions options) foreach (var processor in options.Processors) { + processor.SetLogProvider(this); + this.AddProcessor(processor); } } From ee272b4dd9c8985a3c5fa6b064f942508d697d45 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Wed, 4 Nov 2020 13:39:32 -0800 Subject: [PATCH 03/12] Removed log provider example. --- src/OpenTelemetry/BaseExportProcessor.cs | 11 ---------- src/OpenTelemetry/BaseExporter.cs | 20 ------------------- src/OpenTelemetry/BaseProcessor.cs | 13 ------------ .../Logs/OpenTelemetryLoggerProvider.cs | 2 -- 4 files changed, 46 deletions(-) diff --git a/src/OpenTelemetry/BaseExportProcessor.cs b/src/OpenTelemetry/BaseExportProcessor.cs index fa15466639c..7a9ca0734b9 100644 --- a/src/OpenTelemetry/BaseExportProcessor.cs +++ b/src/OpenTelemetry/BaseExportProcessor.cs @@ -16,9 +16,6 @@ using System; using OpenTelemetry.Internal; -#if NET461 || NETSTANDARD2_0 -using OpenTelemetry.Logs; -#endif using OpenTelemetry.Trace; namespace OpenTelemetry @@ -56,14 +53,6 @@ internal override void SetTracerProvider(TracerProvider tracerProvider) this.exporter.SetTracerProvider(tracerProvider); } -#if NET461 || NETSTANDARD2_0 - /// - internal override void SetLogProvider(OpenTelemetryLoggerProvider logProvider) - { - this.exporter.SetLogProvider(logProvider); - } -#endif - /// protected override bool OnShutdown(int timeoutMilliseconds) { diff --git a/src/OpenTelemetry/BaseExporter.cs b/src/OpenTelemetry/BaseExporter.cs index 9748601554a..4201c982d8b 100644 --- a/src/OpenTelemetry/BaseExporter.cs +++ b/src/OpenTelemetry/BaseExporter.cs @@ -17,9 +17,6 @@ using System; using System.Threading; using OpenTelemetry.Internal; -#if NET461 || NETSTANDARD2_0 -using OpenTelemetry.Logs; -#endif using OpenTelemetry.Trace; namespace OpenTelemetry @@ -109,13 +106,6 @@ internal void SetTracerProvider(TracerProvider tracerProvider) this.OnTracerProviderSet(tracerProvider); } -#if NET461 || NETSTANDARD2_0 - internal void SetLogProvider(OpenTelemetryLoggerProvider logProvider) - { - this.OnLogProviderSet(logProvider); - } -#endif - /// /// Called by Shutdown. This function should block the current /// thread until shutdown completed or timed out. @@ -156,15 +146,5 @@ protected virtual void Dispose(bool disposing) protected virtual void OnTracerProviderSet(TracerProvider tracerProvider) { } - -#if NET461 || NETSTANDARD2_0 - /// - /// Called when the parent is set on the exporter. - /// - /// . - protected virtual void OnLogProviderSet(OpenTelemetryLoggerProvider logProvider) - { - } -#endif } } diff --git a/src/OpenTelemetry/BaseProcessor.cs b/src/OpenTelemetry/BaseProcessor.cs index fc3debf602b..9805d3c28e2 100644 --- a/src/OpenTelemetry/BaseProcessor.cs +++ b/src/OpenTelemetry/BaseProcessor.cs @@ -17,9 +17,6 @@ using System; using System.Threading; using OpenTelemetry.Internal; -#if NET461 || NETSTANDARD2_0 -using OpenTelemetry.Logs; -#endif using OpenTelemetry.Trace; namespace OpenTelemetry @@ -153,16 +150,6 @@ internal virtual void SetTracerProvider(TracerProvider tracerProvider) { } -#if NET461 || NETSTANDARD2_0 - /// - /// Set the parent . - /// - /// . - internal virtual void SetLogProvider(OpenTelemetryLoggerProvider logProvider) - { - } -#endif - /// /// Called by ForceFlush. This function should block the current /// thread until flush completed, shutdown signaled or timed out. diff --git a/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs b/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs index aa3fc13b655..abbc3e4103e 100644 --- a/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs +++ b/src/OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs @@ -50,8 +50,6 @@ internal OpenTelemetryLoggerProvider(OpenTelemetryLoggerOptions options) foreach (var processor in options.Processors) { - processor.SetLogProvider(this); - this.AddProcessor(processor); } } From 354ce67d512d0761fc5f02d9cb51ab314ee42e85 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Wed, 4 Nov 2020 15:10:56 -0800 Subject: [PATCH 04/12] Working on getting everything working with the new API. --- .../ConsoleExporter.cs | 8 ++- .../Implementation/ActivityExtensions.cs | 18 +++--- .../OtlpExporter.cs | 24 ++++---- .../ZipkinExporter.cs | 23 ++++---- .../OtlpExporterTest.cs | 38 ++++++------ .../ZipkinExporterTests.cs | 6 +- .../HttpInListenerTests.cs | 5 -- .../BasicTests.cs | 7 +-- .../GrpcTests.client.cs | 22 +++---- .../HttpClientTests.netcore31.cs | 4 -- .../HttpWebRequestTests.netfx.cs | 8 +-- .../Trace/ActivitySourceAdapterTest.cs | 23 +------- .../Trace/OpenTelemetrySdkTest.cs | 58 ------------------- 13 files changed, 73 insertions(+), 171 deletions(-) delete mode 100644 test/OpenTelemetry.Tests/Trace/OpenTelemetrySdkTest.cs diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs b/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs index 413c44b29d6..50ace926bc8 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs @@ -29,6 +29,7 @@ public class ConsoleExporter : BaseExporter where T : class { private readonly ConsoleExporterOptions options; + private TracerProvider tracerProvider; public ConsoleExporter(ConsoleExporterOptions options) { @@ -99,7 +100,7 @@ public override ExportResult Export(in Batch batch) } } - var resource = activity.GetResource(); + var resource = this.tracerProvider?.GetResource() ?? Resource.Empty; if (resource != Resource.Empty) { this.WriteLine("Resource associated with Activity:"); @@ -140,6 +141,11 @@ public override ExportResult Export(in Batch batch) return ExportResult.Success; } + protected override void OnTracerProviderSet(TracerProvider tracerProvider) + { + this.tracerProvider = tracerProvider; + } + private void WriteLine(string message) { if (this.options.Targets.HasFlag(ConsoleExporterOutputTargets.Console)) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs index 7039abdee0a..b08805b8d87 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ActivityExtensions.cs @@ -28,6 +28,7 @@ using OpenTelemetry.Trace; using OtlpCollector = Opentelemetry.Proto.Collector.Trace.V1; using OtlpCommon = Opentelemetry.Proto.Common.V1; +using OtlpResource = Opentelemetry.Proto.Resource.V1; using OtlpTrace = Opentelemetry.Proto.Trace.V1; namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation @@ -40,23 +41,18 @@ internal static class ActivityExtensions internal static void AddBatch( this OtlpCollector.ExportTraceServiceRequest request, - OtlpExporter otlpExporter, + OtlpResource.Resource processResource, in Batch activityBatch) { Dictionary spansByLibrary = new Dictionary(); - OtlpTrace.ResourceSpans resourceSpans = null; + OtlpTrace.ResourceSpans resourceSpans = new OtlpTrace.ResourceSpans + { + Resource = processResource, + }; + request.ResourceSpans.Add(resourceSpans); foreach (var activity in activityBatch) { - if (resourceSpans == null) - { - resourceSpans = new OtlpTrace.ResourceSpans - { - Resource = otlpExporter.EnsureProcessResource(activity), - }; - request.ResourceSpans.Add(resourceSpans); - } - OtlpTrace.Span span = activity.ToOtlpSpan(); if (span == null) { diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs index 8bdcaa0dc4f..c83e9d1a0c2 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs @@ -18,7 +18,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Runtime.CompilerServices; using System.Threading.Tasks; using Grpc.Core; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; @@ -40,7 +39,6 @@ public class OtlpExporter : BaseExporter private readonly Channel channel; private readonly OtlpCollector.TraceService.ITraceServiceClient traceClient; private readonly Metadata headers; - private OtlpResource.Resource processResource; /// /// Initializes a new instance of the class. @@ -62,12 +60,14 @@ internal OtlpExporter(OtlpExporterOptions options, OtlpCollector.TraceService.IT } } + internal OtlpResource.Resource ProcessResource { get; private set; } + /// public override ExportResult Export(in Batch activityBatch) { OtlpCollector.ExportTraceServiceRequest request = new OtlpCollector.ExportTraceServiceRequest(); - request.AddBatch(this, activityBatch); + request.AddBatch(this.ProcessResource, activityBatch); try { @@ -87,17 +87,11 @@ public override ExportResult Export(in Batch activityBatch) return ExportResult.Success; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal OtlpResource.Resource EnsureProcessResource(Activity activity) + internal void SetResource(Resource resource) { - if (this.processResource != null) - { - return this.processResource; - } - OtlpResource.Resource processResource = new OtlpResource.Resource(); - foreach (KeyValuePair attribute in activity.GetResource().Attributes) + foreach (KeyValuePair attribute in resource.Attributes) { var oltpAttribute = attribute.ToOtlpAttribute(); if (oltpAttribute != null) @@ -121,7 +115,7 @@ internal OtlpResource.Resource EnsureProcessResource(Activity activity) }); } - return this.processResource = processResource; + this.ProcessResource = processResource; } /// @@ -134,5 +128,11 @@ protected override bool OnShutdown(int timeoutMilliseconds) return Task.WaitAny(new Task[] { this.channel.ShutdownAsync(), Task.Delay(timeoutMilliseconds) }) == 0; } + + /// + protected override void OnTracerProviderSet(TracerProvider tracerProvider) + { + this.SetResource(tracerProvider.GetResource()); + } } } diff --git a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs index 73ba3b283f3..2ed245ea7a0 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs @@ -27,7 +27,6 @@ #else using System.Text.Json; #endif -using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using OpenTelemetry.Exporter.Zipkin.Implementation; @@ -92,14 +91,8 @@ public override ExportResult Export(in Batch batch) } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal ZipkinEndpoint EnsureLocalEndpoint(Activity activity) + internal void SetResource(Resource resource) { - if (this.LocalEndpoint != null) - { - return this.LocalEndpoint; - } - var hostName = ResolveHostName(); string ipv4 = null; @@ -113,7 +106,7 @@ internal ZipkinEndpoint EnsureLocalEndpoint(Activity activity) string serviceName = null; string serviceNamespace = null; Dictionary tags = null; - foreach (var label in activity.GetResource().Attributes) + foreach (var label in resource.Attributes) { string key = label.Key; @@ -149,7 +142,7 @@ internal ZipkinEndpoint EnsureLocalEndpoint(Activity activity) serviceName = this.options.ServiceName; } - return this.LocalEndpoint = new ZipkinEndpoint( + this.LocalEndpoint = new ZipkinEndpoint( serviceName, ipv4, ipv6, @@ -157,6 +150,12 @@ internal ZipkinEndpoint EnsureLocalEndpoint(Activity activity) tags); } + /// + protected override void OnTracerProviderSet(TracerProvider tracerProvider) + { + this.SetResource(tracerProvider.GetResource()); + } + private static string ResolveHostAddress(string hostName, AddressFamily family) { string result = null; @@ -257,9 +256,7 @@ protected override Task SerializeToStreamAsync(Stream stream, TransportContext c foreach (var activity in this.batch) { - var localEndpoint = this.exporter.EnsureLocalEndpoint(activity); - - var zipkinSpan = activity.ToZipkinSpan(localEndpoint, this.exporter.options.UseShortTraceIds); + var zipkinSpan = activity.ToZipkinSpan(this.exporter.LocalEndpoint, this.exporter.options.UseShortTraceIds); zipkinSpan.Write(this.writer); diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterTest.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterTest.cs index 52a9d934e4d..c5ffa3d0794 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterTest.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterTest.cs @@ -70,23 +70,28 @@ public void ToOtlpResourceSpansTest(bool addResource, string optionsServiceName) new ActivitySource("odd", "1.3.5"), }; - var builder = Sdk.CreateTracerProviderBuilder() - .AddSource(sources[0].Name) - .AddSource(sources[1].Name); + using var exporter = new OtlpExporter( + new OtlpExporterOptions + { + ServiceName = optionsServiceName, + }, + new NoopTraceServiceClient()); - Resources.Resource resource = null; if (addResource) { - resource = new Resources.Resource( - new List> - { - new KeyValuePair(Resources.Resource.ServiceNameKey, "service-name"), - new KeyValuePair(Resources.Resource.ServiceNamespaceKey, "ns1"), - }); - - builder.SetResource(resource); + exporter.SetResource( + new Resources.Resource( + new List> + { + new KeyValuePair(Resources.Resource.ServiceNameKey, "service-name"), + new KeyValuePair(Resources.Resource.ServiceNamespaceKey, "ns1"), + })); } + var builder = Sdk.CreateTracerProviderBuilder() + .AddSource(sources[0].Name) + .AddSource(sources[1].Name); + using var openTelemetrySdk = builder.Build(); var processor = new BatchExportProcessor(new TestExporter(RunTest)); @@ -109,14 +114,7 @@ void RunTest(Batch batch) { var request = new OtlpCollector.ExportTraceServiceRequest(); - request.AddBatch( - new OtlpExporter( - new OtlpExporterOptions - { - ServiceName = optionsServiceName, - }, - new NoopTraceServiceClient()), - batch); + request.AddBatch(exporter.ProcessResource, batch); Assert.Single(request.ResourceSpans); var oltpResource = request.ResourceSpans.First().Resource; diff --git a/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs b/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs index ec4b19bc233..ef18ea9a344 100644 --- a/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs @@ -155,7 +155,7 @@ public void IntegrationTest(bool useShortTraceIds, bool useTestResource, bool is { serviceName = "MyService"; - activity.SetResource(new Resource(new Dictionary + exporter.SetResource(new Resource(new Dictionary { [Resource.ServiceNameKey] = serviceName, ["service.tag"] = "hello world", @@ -163,6 +163,10 @@ public void IntegrationTest(bool useShortTraceIds, bool useTestResource, bool is resoureTags = "\"service.tag\":\"hello world\","; } + else + { + exporter.SetResource(Resource.Empty); + } var processor = new SimpleExportProcessor(exporter); diff --git a/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs b/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs index bf4c110a454..77fbb319538 100644 --- a/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs @@ -67,8 +67,6 @@ public void AspNetRequestsAreCollectedSuccessfully( string filter = null, bool restoreCurrentActivity = false) { - var expectedResource = Resources.Resources.CreateServiceResource("test-service"); - IDisposable openTelemetry = null; RouteData routeData; switch (routeType) @@ -166,7 +164,6 @@ public void AspNetRequestsAreCollectedSuccessfully( options.Enrich = ActivityEnrichment; }) - .SetResource(expectedResource) .AddProcessor(activityProcessor.Object).Build()) { activity.Start(); @@ -260,8 +257,6 @@ public void AspNetRequestsAreCollectedSuccessfully( Assert.Equal(HttpContext.Current.Request.HttpMethod, span.GetTagValue(SemanticConventions.AttributeHttpMethod) as string); Assert.Equal(HttpContext.Current.Request.Path, span.GetTagValue(SpanAttributeConstants.HttpPathKey) as string); Assert.Equal(HttpContext.Current.Request.UserAgent, span.GetTagValue(SemanticConventions.AttributeHttpUserAgent) as string); - - Assert.Equal(expectedResource, span.GetResource()); } private static void ActivityEnrichment(Activity activity, string method, object obj) diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs index 77ffb9f2271..da275a7edde 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs @@ -99,7 +99,6 @@ void ConfigureTestServices(IServiceCollection services) [InlineData(false)] public async Task SuccessfulTemplateControllerCallGeneratesASpan(bool shouldEnrich) { - var expectedResource = Resources.Resources.CreateServiceResource("test-service"); var activityProcessor = new Mock>(); void ConfigureTestServices(IServiceCollection services) { @@ -111,7 +110,6 @@ void ConfigureTestServices(IServiceCollection services) options.Enrich = ActivityEnrichment; } }) - .SetResource(expectedResource) .AddProcessor(activityProcessor.Object) .Build(); } @@ -134,7 +132,7 @@ void ConfigureTestServices(IServiceCollection services) Assert.Equal(2, activityProcessor.Invocations.Count); // begin and end was called var activity = (Activity)activityProcessor.Invocations[1].Arguments[0]; - ValidateAspNetCoreActivity(activity, "/api/values", expectedResource); + ValidateAspNetCoreActivity(activity, "/api/values"); } [Fact] @@ -354,11 +352,10 @@ private static void WaitForProcessorInvocations(Mock> ac TimeSpan.FromSeconds(1))); } - private static void ValidateAspNetCoreActivity(Activity activityToValidate, string expectedHttpPath, Resources.Resource expectedResource) + private static void ValidateAspNetCoreActivity(Activity activityToValidate, string expectedHttpPath) { Assert.Equal(ActivityKind.Server, activityToValidate.Kind); Assert.Equal(expectedHttpPath, activityToValidate.GetTagValue(SpanAttributeConstants.HttpPathKey) as string); - Assert.Equal(expectedResource, activityToValidate.GetResource()); } private static void ActivityEnrichment(Activity activity, string method, object obj) diff --git a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs index df53a03041e..123949789da 100644 --- a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs +++ b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs @@ -41,7 +41,6 @@ public void GrpcClientCallsAreCollectedSuccessfully(string baseAddress, bool sho var uri = new Uri($"{baseAddress}:{this.server.Port}"); var uriHostNameType = Uri.CheckHostName(uri.Host); - var expectedResource = Resources.Resources.CreateServiceResource("test-service"); var processor = new Mock>(); var parent = new Activity("parent") @@ -56,7 +55,6 @@ public void GrpcClientCallsAreCollectedSuccessfully(string baseAddress, bool sho options.Enrich = ActivityEnrichment; } }) - .SetResource(expectedResource) .AddProcessor(processor.Object) .Build()) { @@ -68,7 +66,7 @@ public void GrpcClientCallsAreCollectedSuccessfully(string baseAddress, bool sho Assert.Equal(4, processor.Invocations.Count); // OnStart/OnEnd/OnShutdown/Dispose called. var activity = (Activity)processor.Invocations[1].Arguments[0]; - ValidateGrpcActivity(activity, expectedResource); + ValidateGrpcActivity(activity); Assert.Equal(parent.TraceId, activity.Context.TraceId); Assert.Equal(parent.SpanId, activity.ParentSpanId); Assert.NotEqual(parent.SpanId, activity.Context.SpanId); @@ -92,7 +90,6 @@ public void GrpcClientCallsAreCollectedSuccessfully(string baseAddress, bool sho Assert.Equal(uri.Port, activity.GetTagValue(SemanticConventions.AttributeNetPeerPort)); Assert.Equal(Status.Unset, activity.GetStatus()); - Assert.Equal(expectedResource, activity.GetResource()); // Tags added by the library then removed from the instrumentation Assert.Null(activity.GetTagValue(GrpcTagHelper.GrpcMethodTagName)); @@ -105,7 +102,6 @@ public void GrpcClientCallsAreCollectedSuccessfully(string baseAddress, bool sho public void GrpcAndHttpClientInstrumentationIsInvoked(bool shouldEnrich) { var uri = new Uri($"http://localhost:{this.server.Port}"); - var expectedResource = Resources.Resources.CreateServiceResource("test-service"); var processor = new Mock>(); var parent = new Activity("parent") @@ -113,7 +109,6 @@ public void GrpcAndHttpClientInstrumentationIsInvoked(bool shouldEnrich) using (Sdk.CreateTracerProviderBuilder() .SetSampler(new AlwaysOnSampler()) - .SetResource(expectedResource) .AddGrpcClientInstrumentation(options => { if (shouldEnrich) @@ -134,7 +129,7 @@ public void GrpcAndHttpClientInstrumentationIsInvoked(bool shouldEnrich) var httpSpan = (Activity)processor.Invocations[2].Arguments[0]; var grpcSpan = (Activity)processor.Invocations[3].Arguments[0]; - ValidateGrpcActivity(grpcSpan, expectedResource); + ValidateGrpcActivity(grpcSpan); Assert.Equal($"greet.Greeter/SayHello", grpcSpan.DisplayName); Assert.Equal($"HTTP POST", httpSpan.DisplayName); Assert.Equal(grpcSpan.SpanId, httpSpan.ParentSpanId); @@ -146,7 +141,6 @@ public void GrpcAndHttpClientInstrumentationIsInvoked(bool shouldEnrich) public void GrpcAndHttpClientInstrumentationWithSuppressInstrumentation(bool shouldEnrich) { var uri = new Uri($"http://localhost:{this.server.Port}"); - var expectedResource = Resources.Resources.CreateServiceResource("test-service"); var processor = new Mock>(); var parent = new Activity("parent") @@ -154,7 +148,6 @@ public void GrpcAndHttpClientInstrumentationWithSuppressInstrumentation(bool sho using (Sdk.CreateTracerProviderBuilder() .SetSampler(new AlwaysOnSampler()) - .SetResource(expectedResource) .AddGrpcClientInstrumentation(o => { o.SuppressDownstreamInstrumentation = true; @@ -187,16 +180,16 @@ public void GrpcAndHttpClientInstrumentationWithSuppressInstrumentation(bool sho var grpcSpan3 = (Activity)processor.Invocations[5].Arguments[0]; var grpcSpan4 = (Activity)processor.Invocations[7].Arguments[0]; - ValidateGrpcActivity(grpcSpan1, expectedResource); + ValidateGrpcActivity(grpcSpan1); Assert.Equal($"greet.Greeter/SayHello", grpcSpan1.DisplayName); - ValidateGrpcActivity(grpcSpan2, expectedResource); + ValidateGrpcActivity(grpcSpan2); Assert.Equal($"greet.Greeter/SayHello", grpcSpan2.DisplayName); - ValidateGrpcActivity(grpcSpan3, expectedResource); + ValidateGrpcActivity(grpcSpan3); Assert.Equal($"greet.Greeter/SayHello", grpcSpan3.DisplayName); - ValidateGrpcActivity(grpcSpan4, expectedResource); + ValidateGrpcActivity(grpcSpan4); Assert.Equal($"greet.Greeter/SayHello", grpcSpan4.DisplayName); } @@ -207,10 +200,9 @@ public void Grpc_BadArgs() Assert.Throws(() => builder.AddGrpcClientInstrumentation()); } - private static void ValidateGrpcActivity(Activity activityToValidate, Resources.Resource expectedResource) + private static void ValidateGrpcActivity(Activity activityToValidate) { Assert.Equal(ActivityKind.Client, activityToValidate.Kind); - Assert.Equal(expectedResource, activityToValidate.GetResource()); } private static void ActivityEnrichment(Activity activity, string method, object obj) diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs index 2f75d8d6144..a754c220c95 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs @@ -50,7 +50,6 @@ public async Task HttpOutCallsAreCollectedSuccessfullyAsync(HttpTestData.HttpOut out var host, out var port); - var expectedResource = Resources.Resources.CreateServiceResource("test-service"); var processor = new Mock>(); tc.Url = HttpTestData.NormalizeValues(tc.Url, host, port); @@ -63,7 +62,6 @@ public async Task HttpOutCallsAreCollectedSuccessfullyAsync(HttpTestData.HttpOut opt.Enrich = ActivityEnrichment; }) .AddProcessor(processor.Object) - .SetResource(expectedResource) .Build()) { try @@ -125,8 +123,6 @@ public async Task HttpOutCallsAreCollectedSuccessfullyAsync(HttpTestData.HttpOut { Assert.Contains(activity.TagObjects, i => i.Key == kv.Key && i.Value.ToString().Equals(kv.Value, StringComparison.InvariantCultureIgnoreCase)); } - - Assert.Equal(expectedResource, activity.GetResource()); } [Fact] diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs index 75dd01b7a3e..af1629ac03b 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs @@ -22,7 +22,6 @@ using System.Net; using Moq; using Newtonsoft.Json; -using OpenTelemetry.Instrumentation.Http.Implementation; using OpenTelemetry.Tests; using OpenTelemetry.Trace; using Xunit; @@ -46,10 +45,8 @@ public void HttpOutCallsAreCollectedSuccessfully(HttpTestData.HttpOutTestCase tc out var host, out var port); - var expectedResource = Resources.Resources.CreateServiceResource("test-service"); var activityProcessor = new Mock>(); using var shutdownSignal = Sdk.CreateTracerProviderBuilder() - .SetResource(expectedResource) .AddProcessor(activityProcessor.Object) .AddHttpWebRequestInstrumentation(options => { @@ -88,7 +85,7 @@ public void HttpOutCallsAreCollectedSuccessfully(HttpTestData.HttpOutTestCase tc Assert.Equal(2, activityProcessor.Invocations.Count); // begin and end was called var activity = (Activity)activityProcessor.Invocations[1].Arguments[0]; - ValidateHttpWebRequestActivity(activity, expectedResource, tc.ResponseExpected); + ValidateHttpWebRequestActivity(activity); Assert.Equal(tc.SpanName, activity.DisplayName); var d = new Dictionary() @@ -165,10 +162,9 @@ public void DebugIndividualTest() this.HttpOutCallsAreCollectedSuccessfully(input); } - private static void ValidateHttpWebRequestActivity(Activity activityToValidate, Resources.Resource expectedResource, bool responseExpected) + private static void ValidateHttpWebRequestActivity(Activity activityToValidate) { Assert.Equal(ActivityKind.Client, activityToValidate.Kind); - Assert.Equal(expectedResource, activityToValidate.GetResource()); } private static void ActivityEnrichment(Activity activity, string method, object obj) diff --git a/test/OpenTelemetry.Tests/Trace/ActivitySourceAdapterTest.cs b/test/OpenTelemetry.Tests/Trace/ActivitySourceAdapterTest.cs index 72d5d3282ef..2bade8904c1 100644 --- a/test/OpenTelemetry.Tests/Trace/ActivitySourceAdapterTest.cs +++ b/test/OpenTelemetry.Tests/Trace/ActivitySourceAdapterTest.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using OpenTelemetry.Resources; using OpenTelemetry.Tests; using Xunit; @@ -27,7 +26,6 @@ public class ActivitySourceAdapterTest : IDisposable { private TestSampler testSampler; private TestActivityProcessor testProcessor; - private Resource testResource = Resources.Resources.CreateServiceResource("test-resource"); private ActivitySourceAdapter activitySourceAdapter; static ActivitySourceAdapterTest() @@ -40,33 +38,18 @@ public ActivitySourceAdapterTest() { this.testSampler = new TestSampler(); this.testProcessor = new TestActivityProcessor(); - this.activitySourceAdapter = new ActivitySourceAdapter(this.testSampler, this.testProcessor, this.testResource); + this.activitySourceAdapter = new ActivitySourceAdapter(this.testSampler, this.testProcessor); } [Fact] public void ActivitySourceAdapterValidatesConstructor() { // Sampler null - Assert.Throws(() => new ActivitySourceAdapter(null, this.testProcessor, this.testResource)); - - // Resource null - Assert.Throws(() => new ActivitySourceAdapter(this.testSampler, this.testProcessor, null)); + Assert.Throws(() => new ActivitySourceAdapter(null, this.testProcessor)); // Processor null. This is not expected to throw as processor can // be null and can be later added. - var adapter = new ActivitySourceAdapter(this.testSampler, null, this.testResource); - } - - [Fact] - public void ActivitySourceAdapterSetsResource() - { - var activity = new Activity("test"); - activity.Start(); - this.activitySourceAdapter.Start(activity, ActivityKind.Internal); - activity.Stop(); - this.activitySourceAdapter.Stop(activity); - - Assert.Equal(this.testResource, activity.GetResource()); + var adapter = new ActivitySourceAdapter(this.testSampler, null); } [Theory] diff --git a/test/OpenTelemetry.Tests/Trace/OpenTelemetrySdkTest.cs b/test/OpenTelemetry.Tests/Trace/OpenTelemetrySdkTest.cs deleted file mode 100644 index 917b34f4113..00000000000 --- a/test/OpenTelemetry.Tests/Trace/OpenTelemetrySdkTest.cs +++ /dev/null @@ -1,58 +0,0 @@ -// -// 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.Diagnostics; -using OpenTelemetry.Resources; -using Xunit; - -namespace OpenTelemetry.Trace.Tests -{ - public class OpenTelemetrySdkTest - { - [Fact] - public void ResourceGetsAssociatedWithActivity() - { - using var activitySource = new ActivitySource(nameof(this.ResourceGetsAssociatedWithActivity)); - var expectedResource = Resources.Resources.CreateServiceResource("ServiceNameAbc"); - - using var openTelemetry = Sdk.CreateTracerProviderBuilder() - .AddSource(nameof(this.ResourceGetsAssociatedWithActivity)) - .SetResource(expectedResource) - .Build(); - - using (var root = activitySource.StartActivity("root")) - { - Assert.Equal(expectedResource, root.GetResource()); - } - } - - [Fact] - public void DefaultResourceGetsAssociatedWithActivityIfNoneConfigured() - { - using var activitySource = new ActivitySource(nameof(this.ResourceGetsAssociatedWithActivity)); - var expectedResource = Resource.Empty; - - using var openTelemetry = Sdk.CreateTracerProviderBuilder() - .AddSource(nameof(this.ResourceGetsAssociatedWithActivity)) - .Build(); - - using (var root = activitySource.StartActivity("root")) - { - Assert.Equal(expectedResource, root.GetResource()); - } - } - } -} From 90c0a28f358503d3059c013ce25a313f5e38aa66 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Wed, 4 Nov 2020 16:51:09 -0800 Subject: [PATCH 05/12] Attempting to get all the tests passing. --- .../OtlpExporterTest.cs | 4 +++ .../HttpInListenerTests.cs | 8 ++--- .../BasicTests.cs | 36 +++++++++---------- ...stsCollectionsIsAccordingToTheSpecTests.cs | 6 ++-- .../GrpcTests.client.cs | 21 +++++------ .../HttpClientTests.Basic.netcore31.cs | 16 ++++----- .../HttpClientTests.netcore31.cs | 4 +-- .../HttpWebRequestTests.Basic.netfx.cs | 14 ++++---- .../HttpWebRequestTests.netfx.cs | 4 +-- .../SqlClientTests.cs | 8 ++--- .../SqlEventSourceTests.netfx.cs | 8 ++--- 11 files changed, 67 insertions(+), 62 deletions(-) diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterTest.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterTest.cs index c5ffa3d0794..d70becc737b 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterTest.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterTest.cs @@ -87,6 +87,10 @@ public void ToOtlpResourceSpansTest(bool addResource, string optionsServiceName) new KeyValuePair(Resources.Resource.ServiceNamespaceKey, "ns1"), })); } + else + { + exporter.SetResource(Resources.Resource.Empty); + } var builder = Sdk.CreateTracerProviderBuilder() .AddSource(sources[0].Name) diff --git a/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs b/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs index 77fbb319538..5cfc65b2dfc 100644 --- a/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs @@ -193,8 +193,8 @@ public void AspNetRequestsAreCollectedSuccessfully( if (HttpContext.Current.Request.Path == filter || filter == "{ThrowException}") { - // only Shutdown/Dispose are called because request was filtered. - Assert.Equal(2, activityProcessor.Invocations.Count); + // only SetTracerProvider/Shutdown/Dispose are called because request was filtered. + Assert.Equal(3, activityProcessor.Invocations.Count); return; } @@ -202,8 +202,8 @@ public void AspNetRequestsAreCollectedSuccessfully( var currentActivity = Activity.Current; Activity span; - Assert.Equal(4, activityProcessor.Invocations.Count); // OnStart/OnEnd/OnShutdown/Dispose called. - span = (Activity)activityProcessor.Invocations[1].Arguments[0]; + Assert.Equal(5, activityProcessor.Invocations.Count); // SetTracerProvider/OnStart/OnEnd/OnShutdown/Dispose called. + span = (Activity)activityProcessor.Invocations[2].Arguments[0]; Assert.Equal( carrierFormat == "TraceContext" || carrierFormat == "CustomContextMatchParent" diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs index da275a7edde..8c27cbecbdb 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs @@ -82,11 +82,11 @@ void ConfigureTestServices(IServiceCollection services) // Assert response.EnsureSuccessStatusCode(); // Status Code 200-299 - WaitForProcessorInvocations(activityProcessor, 2); + WaitForProcessorInvocations(activityProcessor, 3); } - Assert.Equal(2, activityProcessor.Invocations.Count); // begin and end was called - var activity = (Activity)activityProcessor.Invocations[1].Arguments[0]; + Assert.Equal(3, activityProcessor.Invocations.Count); // begin and end was called + var activity = (Activity)activityProcessor.Invocations[2].Arguments[0]; Assert.Equal(200, activity.GetTagValue(SemanticConventions.AttributeHttpStatusCode)); @@ -126,11 +126,11 @@ void ConfigureTestServices(IServiceCollection services) // Assert response.EnsureSuccessStatusCode(); // Status Code 200-299 - WaitForProcessorInvocations(activityProcessor, 2); + WaitForProcessorInvocations(activityProcessor, 3); } - Assert.Equal(2, activityProcessor.Invocations.Count); // begin and end was called - var activity = (Activity)activityProcessor.Invocations[1].Arguments[0]; + Assert.Equal(3, activityProcessor.Invocations.Count); // begin and end was called + var activity = (Activity)activityProcessor.Invocations[2].Arguments[0]; ValidateAspNetCoreActivity(activity, "/api/values"); } @@ -163,11 +163,11 @@ public async Task SuccessfulTemplateControllerCallUsesParentContext() // Assert response.EnsureSuccessStatusCode(); // Status Code 200-299 - WaitForProcessorInvocations(activityProcessor, 2); + WaitForProcessorInvocations(activityProcessor, 3); } - Assert.Equal(2, activityProcessor.Invocations.Count); // begin and end was called - var activity = (Activity)activityProcessor.Invocations[1].Arguments[0]; + Assert.Equal(3, activityProcessor.Invocations.Count); // begin and end was called + var activity = (Activity)activityProcessor.Invocations[2].Arguments[0]; #if !NETCOREAPP2_1 // ASP.NET Core after 2.x is W3C aware and hence Activity created by it @@ -219,12 +219,12 @@ public async Task CustomPropagator() var response = await client.GetAsync("/api/values/2"); response.EnsureSuccessStatusCode(); // Status Code 200-299 - WaitForProcessorInvocations(activityProcessor, 2); + WaitForProcessorInvocations(activityProcessor, 3); } // begin and end was called once each. - Assert.Equal(2, activityProcessor.Invocations.Count); - var activity = (Activity)activityProcessor.Invocations[1].Arguments[0]; + Assert.Equal(3, activityProcessor.Invocations.Count); + var activity = (Activity)activityProcessor.Invocations[2].Arguments[0]; Assert.Equal("ActivityCreatedByHttpInListener", activity.OperationName); Assert.Equal(ActivityKind.Server, activity.Kind); @@ -269,12 +269,12 @@ void ConfigureTestServices(IServiceCollection services) response1.EnsureSuccessStatusCode(); // Status Code 200-299 response2.EnsureSuccessStatusCode(); // Status Code 200-299 - WaitForProcessorInvocations(activityProcessor, 2); + WaitForProcessorInvocations(activityProcessor, 3); } // we should only create one span and never call processor with another - Assert.Equal(2, activityProcessor.Invocations.Count); // begin and end was called - var activity = (Activity)activityProcessor.Invocations[1].Arguments[0]; + Assert.Equal(3, activityProcessor.Invocations.Count); // begin and end was called + var activity = (Activity)activityProcessor.Invocations[2].Arguments[0]; Assert.Equal(ActivityKind.Server, activity.Kind); Assert.Equal("/api/values", activity.GetTagValue(SpanAttributeConstants.HttpPathKey) as string); @@ -321,13 +321,13 @@ void ConfigureTestServices(IServiceCollection services) Assert.Single(inMemoryEventListener.Events.Where((e) => e.EventId == 3)); } - WaitForProcessorInvocations(activityProcessor, 2); + WaitForProcessorInvocations(activityProcessor, 3); } // As InstrumentationFilter threw, we continue as if the // InstrumentationFilter did not exist. - Assert.Equal(2, activityProcessor.Invocations.Count); // begin and end was called - var activity = (Activity)activityProcessor.Invocations[1].Arguments[0]; + Assert.Equal(3, activityProcessor.Invocations.Count); // begin and end was called + var activity = (Activity)activityProcessor.Invocations[2].Arguments[0]; Assert.Equal(ActivityKind.Server, activity.Kind); Assert.Equal("/api/values", activity.GetTagValue(SpanAttributeConstants.HttpPathKey) as string); diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs index 872bb2fdd31..26625a0d582 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs @@ -86,7 +86,7 @@ public async Task SuccessfulTemplateControllerCallGeneratesASpan( for (var i = 0; i < 10; i++) { - if (processor.Invocations.Count == 2) + if (processor.Invocations.Count == 3) { break; } @@ -98,8 +98,8 @@ public async Task SuccessfulTemplateControllerCallGeneratesASpan( } } - Assert.Equal(2, processor.Invocations.Count); // begin and end was called - var activity = (Activity)processor.Invocations[1].Arguments[0]; + Assert.Equal(3, processor.Invocations.Count); // SetTracerProvider/Begin/End called + var activity = (Activity)processor.Invocations[2].Arguments[0]; Assert.Equal(ActivityKind.Server, activity.Kind); Assert.Equal("localhost", activity.GetTagValue(SemanticConventions.AttributeHttpHost)); diff --git a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs index 123949789da..dad8b077156 100644 --- a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs +++ b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs @@ -44,6 +44,7 @@ public void GrpcClientCallsAreCollectedSuccessfully(string baseAddress, bool sho var processor = new Mock>(); var parent = new Activity("parent") + .SetIdFormat(ActivityIdFormat.W3C) .Start(); using (Sdk.CreateTracerProviderBuilder() @@ -63,8 +64,8 @@ public void GrpcClientCallsAreCollectedSuccessfully(string baseAddress, bool sho var rs = client.SayHello(new HelloRequest()); } - Assert.Equal(4, processor.Invocations.Count); // OnStart/OnEnd/OnShutdown/Dispose called. - var activity = (Activity)processor.Invocations[1].Arguments[0]; + Assert.Equal(5, processor.Invocations.Count); // SetTracerProvider/OnStart/OnEnd/OnShutdown/Dispose called. + var activity = (Activity)processor.Invocations[2].Arguments[0]; ValidateGrpcActivity(activity); Assert.Equal(parent.TraceId, activity.Context.TraceId); @@ -125,9 +126,9 @@ public void GrpcAndHttpClientInstrumentationIsInvoked(bool shouldEnrich) var rs = client.SayHello(new HelloRequest()); } - Assert.Equal(6, processor.Invocations.Count); // OnStart/OnEnd (gRPC) + OnStart/OnEnd (HTTP) + OnShutdown/Dispose called. - var httpSpan = (Activity)processor.Invocations[2].Arguments[0]; - var grpcSpan = (Activity)processor.Invocations[3].Arguments[0]; + Assert.Equal(7, processor.Invocations.Count); // SetTracerProvider + OnStart/OnEnd (gRPC) + OnStart/OnEnd (HTTP) + OnShutdown/Dispose called. + var httpSpan = (Activity)processor.Invocations[3].Arguments[0]; + var grpcSpan = (Activity)processor.Invocations[4].Arguments[0]; ValidateGrpcActivity(grpcSpan); Assert.Equal($"greet.Greeter/SayHello", grpcSpan.DisplayName); @@ -174,11 +175,11 @@ public void GrpcAndHttpClientInstrumentationWithSuppressInstrumentation(bool sho }); } - Assert.Equal(10, processor.Invocations.Count); // OnStart/OnEnd (gRPC) * 4 + OnShutdown/Dispose called. - var grpcSpan1 = (Activity)processor.Invocations[1].Arguments[0]; - var grpcSpan2 = (Activity)processor.Invocations[3].Arguments[0]; - var grpcSpan3 = (Activity)processor.Invocations[5].Arguments[0]; - var grpcSpan4 = (Activity)processor.Invocations[7].Arguments[0]; + Assert.Equal(11, processor.Invocations.Count); // SetTracerProvider + OnStart/OnEnd (gRPC) * 4 + OnShutdown/Dispose called. + var grpcSpan1 = (Activity)processor.Invocations[2].Arguments[0]; + var grpcSpan2 = (Activity)processor.Invocations[4].Arguments[0]; + var grpcSpan3 = (Activity)processor.Invocations[6].Arguments[0]; + var grpcSpan4 = (Activity)processor.Invocations[8].Arguments[0]; ValidateGrpcActivity(grpcSpan1); Assert.Equal($"greet.Greeter/SayHello", grpcSpan1.DisplayName); diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.netcore31.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.netcore31.cs index b0a5f284e9f..f929d4e4c8e 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.netcore31.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.netcore31.cs @@ -106,8 +106,8 @@ public async Task HttpClientInstrumentationInjectsHeadersAsync(bool shouldEnrich await c.SendAsync(request); } - Assert.Equal(4, processor.Invocations.Count); // OnStart/OnEnd/OnShutdown/Dispose called. - var activity = (Activity)processor.Invocations[1].Arguments[0]; + Assert.Equal(5, processor.Invocations.Count); // SetTracerProvider/OnStart/OnEnd/OnShutdown/Dispose called. + var activity = (Activity)processor.Invocations[2].Arguments[0]; Assert.Equal(ActivityKind.Client, activity.Kind); Assert.Equal(parent.TraceId, activity.Context.TraceId); @@ -168,8 +168,8 @@ public async Task HttpClientInstrumentationInjectsHeadersAsync_CustomFormat(bool await c.SendAsync(request); } - Assert.Equal(4, processor.Invocations.Count); // OnStart/OnEnd/OnShutdown/Dispose called. - var activity = (Activity)processor.Invocations[1].Arguments[0]; + Assert.Equal(5, processor.Invocations.Count); // SetTracerProvider/OnStart/OnEnd/OnShutdown/Dispose called. + var activity = (Activity)processor.Invocations[2].Arguments[0]; Assert.Equal(ActivityKind.Client, activity.Kind); Assert.Equal(parent.TraceId, activity.Context.TraceId); @@ -251,7 +251,7 @@ public async Task HttpClientInstrumentationBacksOffIfAlreadyInstrumented() await c.SendAsync(request); } - Assert.Equal(2, processor.Invocations.Count); // OnShutdown/Dispose called. + Assert.Equal(3, processor.Invocations.Count); // SetTracerProvider/OnShutdown/Dispose called. } [Fact] @@ -268,7 +268,7 @@ public async void RequestNotCollectedWhenInstrumentationFilterApplied() await c.GetAsync(this.url); } - Assert.Equal(2, processor.Invocations.Count); // OnShutdown/Dispose called. + Assert.Equal(3, processor.Invocations.Count); // SetTracerProvider/OnShutdown/Dispose called. } [Fact] @@ -289,7 +289,7 @@ public async void RequestNotCollectedWhenInstrumentationFilterThrowsException() } } - Assert.Equal(2, processor.Invocations.Count); // OnShutdown/Dispose called. + Assert.Equal(3, processor.Invocations.Count); // SetTracerProvider/OnShutdown/Dispose called. } [Fact] @@ -314,7 +314,7 @@ public async Task HttpClientInstrumentationCorrelationAndBaggage() using var r = await c.GetAsync("https://opentelemetry.io/").ConfigureAwait(false); } - Assert.Equal(4, activityProcessor.Invocations.Count); + Assert.Equal(5, activityProcessor.Invocations.Count); } public void Dispose() diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs index a754c220c95..70e4a470b85 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs @@ -90,8 +90,8 @@ public async Task HttpOutCallsAreCollectedSuccessfullyAsync(HttpTestData.HttpOut } } - Assert.Equal(4, processor.Invocations.Count); // OnStart/OnEnd/OnShutdown/Dispose called. - var activity = (Activity)processor.Invocations[1].Arguments[0]; + Assert.Equal(5, processor.Invocations.Count); // SetTracerProvider/OnStart/OnEnd/OnShutdown/Dispose called. + var activity = (Activity)processor.Invocations[2].Arguments[0]; Assert.Equal(ActivityKind.Client, activity.Kind); Assert.Equal(tc.SpanName, activity.DisplayName); diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.netfx.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.netfx.cs index f1bfcfbd172..343184b2f63 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.netfx.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.netfx.cs @@ -78,8 +78,8 @@ public async Task HttpWebRequestInstrumentationInjectsHeadersAsync() using var response = await request.GetResponseAsync(); - Assert.Equal(2, activityProcessor.Invocations.Count); // begin and end was called - var activity = (Activity)activityProcessor.Invocations[1].Arguments[0]; + Assert.Equal(3, activityProcessor.Invocations.Count); // SetTracerProvider/Begin/End called + var activity = (Activity)activityProcessor.Invocations[2].Arguments[0]; Assert.Equal(parent.TraceId, activity.Context.TraceId); Assert.Equal(parent.SpanId, activity.ParentSpanId); @@ -128,7 +128,7 @@ public async Task HttpWebRequestInstrumentationInjectsHeadersAsyncWhenActivityIs // By default parentbasedsampler is used. // In this case, the parent is the manually created parentactivity, which will have TraceFlags as None. // This causes child to be not created. - Assert.Empty(activityProcessor.Invocations); + Assert.Equal(1, activityProcessor.Invocations.Count); Assert.Equal(parent.TraceId, contentFromPropagator.TraceId); Assert.Equal(parent.SpanId, contentFromPropagator.SpanId); @@ -172,9 +172,9 @@ public async Task HttpWebRequestInstrumentationInjectsHeadersAsync_CustomFormat( using var response = await request.GetResponseAsync(); - Assert.Equal(2, activityProcessor.Invocations.Count); // begin and end was called + Assert.Equal(3, activityProcessor.Invocations.Count); // SetTracerProvider/Begin/End called - var activity = (Activity)activityProcessor.Invocations[1].Arguments[0]; + var activity = (Activity)activityProcessor.Invocations[2].Arguments[0]; Assert.Equal(parent.TraceId, activity.Context.TraceId); Assert.Equal(parent.SpanId, activity.ParentSpanId); @@ -215,7 +215,7 @@ public async Task HttpWebRequestInstrumentationBacksOffIfAlreadyInstrumented() using var c = new HttpClient(); await c.SendAsync(request); - Assert.Equal(0, activityProcessor.Invocations.Count); + Assert.Equal(1, activityProcessor.Invocations.Count); } [Fact] @@ -231,7 +231,7 @@ public async Task RequestNotCollectedWhenInstrumentationFilterApplied() using var c = new HttpClient(); await c.GetAsync(this.url); - Assert.Equal(0, activityProcessor.Invocations.Count); + Assert.Equal(1, activityProcessor.Invocations.Count); } [Fact] diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs index af1629ac03b..cc60106a5d4 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs @@ -83,8 +83,8 @@ public void HttpOutCallsAreCollectedSuccessfully(HttpTestData.HttpOutTestCase tc tc.ResponseExpected = false; } - Assert.Equal(2, activityProcessor.Invocations.Count); // begin and end was called - var activity = (Activity)activityProcessor.Invocations[1].Arguments[0]; + Assert.Equal(3, activityProcessor.Invocations.Count); // SetTracerProvider/Begin/End called + var activity = (Activity)activityProcessor.Invocations[2].Arguments[0]; ValidateHttpWebRequestActivity(activity); Assert.Equal(tc.SpanName, activity.DisplayName); diff --git a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs index 8c08ffc1426..2327e2721b6 100644 --- a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs +++ b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs @@ -187,7 +187,7 @@ public void SqlClientCallsAreCollectedSuccessfully( afterExecuteEventData); } - Assert.Equal(4, processor.Invocations.Count); // OnStart/OnEnd/OnShutdown/Dispose called. + Assert.Equal(5, processor.Invocations.Count); // SetTracerProvider/OnStart/OnEnd/OnShutdown/Dispose called. VerifyActivityData( sqlCommand.CommandType, @@ -196,7 +196,7 @@ public void SqlClientCallsAreCollectedSuccessfully( captureTextCommandContent, false, sqlConnection.DataSource, - (Activity)processor.Invocations[1].Arguments[0]); + (Activity)processor.Invocations[2].Arguments[0]); } [Theory] @@ -249,7 +249,7 @@ public void SqlClientErrorsAreCollectedSuccessfully(string beforeCommand, string commandErrorEventData); } - Assert.Equal(4, processor.Invocations.Count); // OnStart/OnEnd/OnShutdown/Dispose called. + Assert.Equal(5, processor.Invocations.Count); // SetTracerProvider/OnStart/OnEnd/OnShutdown/Dispose called. VerifyActivityData( sqlCommand.CommandType, @@ -258,7 +258,7 @@ public void SqlClientErrorsAreCollectedSuccessfully(string beforeCommand, string false, true, sqlConnection.DataSource, - (Activity)processor.Invocations[1].Arguments[0]); + (Activity)processor.Invocations[2].Arguments[0]); } private static void VerifyActivityData( diff --git a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlEventSourceTests.netfx.cs b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlEventSourceTests.netfx.cs index af2f4e5bdd6..686f8728647 100644 --- a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlEventSourceTests.netfx.cs +++ b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlEventSourceTests.netfx.cs @@ -128,9 +128,9 @@ public void EventSourceFakeTests( fakeSqlEventSource.WriteEndExecuteEvent(objectId, compositeState, sqlExceptionNumber); shutdownSignal.Dispose(); - Assert.Equal(4, activityProcessor.Invocations.Count); // OnStart/OnEnd/OnShutdown/Dispose called. + Assert.Equal(5, activityProcessor.Invocations.Count); // SetTracerProvider/OnStart/OnEnd/OnShutdown/Dispose called. - var activity = (Activity)activityProcessor.Invocations[1].Arguments[0]; + var activity = (Activity)activityProcessor.Invocations[2].Arguments[0]; VerifyActivityData(commandType, commandText, captureText, isFailure, "127.0.0.1", activity, enableConnectionLevelAttributes); } @@ -150,7 +150,7 @@ public void EventSourceFakeUnknownEventWithNullPayloadTest() shutdownSignal.Dispose(); - Assert.Equal(2, activityProcessor.Invocations.Count); // OnShutdown/Dispose called. + Assert.Equal(3, activityProcessor.Invocations.Count); // SetTracerProvider/OnShutdown/Dispose called. } [Fact] @@ -169,7 +169,7 @@ public void EventSourceFakeInvalidPayloadTest() fakeSqlEventSource.WriteEndExecuteEvent("arg1", "arg2", "arg3", "arg4"); shutdownSignal.Dispose(); - Assert.Equal(2, activityProcessor.Invocations.Count); // OnShutdown/Dispose called. + Assert.Equal(3, activityProcessor.Invocations.Count); // SetTracerProvider/OnShutdown/Dispose called. } private static void VerifyActivityData( From bc3b0902c86bf353ca79a9841bb23a4fcdb544e7 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Fri, 6 Nov 2020 11:16:29 -0800 Subject: [PATCH 06/12] Added concept of BaseProvider. Updated public API. --- .../.publicApi/net452/PublicAPI.Unshipped.txt | 9 ++-- .../netstandard2.0/PublicAPI.Unshipped.txt | 9 ++-- src/OpenTelemetry.Api/BaseProvider.cs | 49 +++++++++++++++++++ .../Metrics/MeterProvider.cs | 17 +------ .../OpenTelemetry.Api.csproj | 4 ++ src/OpenTelemetry.Api/Trace/TracerProvider.cs | 18 +------ .../ConsoleExporter.cs | 9 +--- .../JaegerExporter.cs | 4 +- .../OtlpExporter.cs | 4 +- .../ZipkinExporter.cs | 4 +- .../.publicApi/net452/PublicAPI.Unshipped.txt | 10 ++-- .../.publicApi/net46/PublicAPI.Unshipped.txt | 10 ++-- .../.publicApi/net461/PublicAPI.Unshipped.txt | 10 ++-- .../netstandard2.0/PublicAPI.Unshipped.txt | 10 ++-- src/OpenTelemetry/BaseExportProcessor.cs | 5 +- src/OpenTelemetry/BaseExporter.cs | 25 ++++++---- src/OpenTelemetry/BaseProcessor.cs | 30 ++++++++---- src/OpenTelemetry/OpenTelemetry.csproj | 8 +++ src/OpenTelemetry/ProviderExtensions.cs | 42 ++++++++++++++++ .../Trace/TracerProviderExtensions.cs | 11 ----- src/OpenTelemetry/Trace/TracerProviderSdk.cs | 2 +- 21 files changed, 190 insertions(+), 100 deletions(-) create mode 100644 src/OpenTelemetry.Api/BaseProvider.cs create mode 100644 src/OpenTelemetry/ProviderExtensions.cs diff --git a/src/OpenTelemetry.Api/.publicApi/net452/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Api/.publicApi/net452/PublicAPI.Unshipped.txt index 3e01f92b9c9..89cf41e71eb 100644 --- a/src/OpenTelemetry.Api/.publicApi/net452/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Api/.publicApi/net452/PublicAPI.Unshipped.txt @@ -14,6 +14,10 @@ OpenTelemetry.Baggage.RemoveBaggage(string name) -> OpenTelemetry.Baggage OpenTelemetry.Baggage.SetBaggage(System.Collections.Generic.IEnumerable> baggageItems) -> OpenTelemetry.Baggage OpenTelemetry.Baggage.SetBaggage(params System.Collections.Generic.KeyValuePair[] baggageItems) -> OpenTelemetry.Baggage OpenTelemetry.Baggage.SetBaggage(string name, string value) -> OpenTelemetry.Baggage +OpenTelemetry.BaseProvider +OpenTelemetry.BaseProvider.BaseProvider() -> void +OpenTelemetry.BaseProvider.Dispose() -> void +OpenTelemetry.BaseProvider.~BaseProvider() -> void OpenTelemetry.Context.Propagation.B3Propagator OpenTelemetry.Context.Propagation.B3Propagator.B3Propagator() -> void OpenTelemetry.Context.Propagation.B3Propagator.B3Propagator(bool singleHeader) -> void @@ -70,7 +74,6 @@ OpenTelemetry.Metrics.Meter.Meter() -> void OpenTelemetry.Metrics.MeterFactoryBase OpenTelemetry.Metrics.MeterFactoryBase.MeterFactoryBase() -> void OpenTelemetry.Metrics.MeterProvider -OpenTelemetry.Metrics.MeterProvider.Dispose() -> void OpenTelemetry.Metrics.MeterProvider.MeterProvider() -> void OpenTelemetry.Metrics.NoopBoundCounterMetric OpenTelemetry.Metrics.NoopBoundCounterMetric.NoopBoundCounterMetric() -> void @@ -166,7 +169,6 @@ OpenTelemetry.Trace.Tracer.StartRootSpan(string name, OpenTelemetry.Trace.SpanKi OpenTelemetry.Trace.Tracer.StartSpan(string name, OpenTelemetry.Trace.SpanKind kind = OpenTelemetry.Trace.SpanKind.Internal, in OpenTelemetry.Trace.SpanContext parentContext = default(OpenTelemetry.Trace.SpanContext), OpenTelemetry.Trace.SpanAttributes initialAttributes = null, System.Collections.Generic.IEnumerable links = null, System.DateTimeOffset startTime = default(System.DateTimeOffset)) -> OpenTelemetry.Trace.TelemetrySpan OpenTelemetry.Trace.Tracer.StartSpan(string name, OpenTelemetry.Trace.SpanKind kind, in OpenTelemetry.Trace.TelemetrySpan parentSpan, OpenTelemetry.Trace.SpanAttributes initialAttributes = null, System.Collections.Generic.IEnumerable links = null, System.DateTimeOffset startTime = default(System.DateTimeOffset)) -> OpenTelemetry.Trace.TelemetrySpan OpenTelemetry.Trace.TracerProvider -OpenTelemetry.Trace.TracerProvider.Dispose() -> void OpenTelemetry.Trace.TracerProvider.GetTracer(string name, string version = null) -> OpenTelemetry.Trace.Tracer OpenTelemetry.Trace.TracerProvider.TracerProvider() -> void abstract OpenTelemetry.Context.RuntimeContextSlot.Get() -> T @@ -300,10 +302,9 @@ static readonly OpenTelemetry.Metrics.NoopMeasureMetric.Instance -> OpenTelem static readonly OpenTelemetry.Trace.Status.Error -> OpenTelemetry.Trace.Status static readonly OpenTelemetry.Trace.Status.Ok -> OpenTelemetry.Trace.Status static readonly OpenTelemetry.Trace.Status.Unset -> OpenTelemetry.Trace.Status +virtual OpenTelemetry.BaseProvider.Dispose(bool disposing) -> void virtual OpenTelemetry.Context.RuntimeContextSlot.Dispose(bool disposing) -> void virtual OpenTelemetry.Metrics.LabelSet.Labels.get -> System.Collections.Generic.IEnumerable> virtual OpenTelemetry.Metrics.LabelSet.Labels.set -> void virtual OpenTelemetry.Metrics.MeterFactoryBase.GetMeter(string name, string version = null) -> OpenTelemetry.Metrics.Meter -virtual OpenTelemetry.Metrics.MeterProvider.Dispose(bool disposing) -> void virtual OpenTelemetry.Metrics.MeterProvider.GetMeter(string name, string version = null) -> OpenTelemetry.Metrics.Meter -virtual OpenTelemetry.Trace.TracerProvider.Dispose(bool disposing) -> void diff --git a/src/OpenTelemetry.Api/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Api/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index 6247afb3bdb..ac7d5c0cc7c 100644 --- a/src/OpenTelemetry.Api/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Api/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -14,6 +14,10 @@ OpenTelemetry.Baggage.RemoveBaggage(string name) -> OpenTelemetry.Baggage OpenTelemetry.Baggage.SetBaggage(System.Collections.Generic.IEnumerable> baggageItems) -> OpenTelemetry.Baggage OpenTelemetry.Baggage.SetBaggage(params System.Collections.Generic.KeyValuePair[] baggageItems) -> OpenTelemetry.Baggage OpenTelemetry.Baggage.SetBaggage(string name, string value) -> OpenTelemetry.Baggage +OpenTelemetry.BaseProvider +OpenTelemetry.BaseProvider.BaseProvider() -> void +OpenTelemetry.BaseProvider.Dispose() -> void +OpenTelemetry.BaseProvider.~BaseProvider() -> void OpenTelemetry.Context.AsyncLocalRuntimeContextSlot OpenTelemetry.Context.AsyncLocalRuntimeContextSlot.AsyncLocalRuntimeContextSlot(string name) -> void OpenTelemetry.Context.Propagation.B3Propagator @@ -70,7 +74,6 @@ OpenTelemetry.Metrics.Meter.Meter() -> void OpenTelemetry.Metrics.MeterFactoryBase OpenTelemetry.Metrics.MeterFactoryBase.MeterFactoryBase() -> void OpenTelemetry.Metrics.MeterProvider -OpenTelemetry.Metrics.MeterProvider.Dispose() -> void OpenTelemetry.Metrics.MeterProvider.MeterProvider() -> void OpenTelemetry.Metrics.NoopBoundCounterMetric OpenTelemetry.Metrics.NoopBoundCounterMetric.NoopBoundCounterMetric() -> void @@ -166,7 +169,6 @@ OpenTelemetry.Trace.Tracer.StartRootSpan(string name, OpenTelemetry.Trace.SpanKi OpenTelemetry.Trace.Tracer.StartSpan(string name, OpenTelemetry.Trace.SpanKind kind = OpenTelemetry.Trace.SpanKind.Internal, in OpenTelemetry.Trace.SpanContext parentContext = default(OpenTelemetry.Trace.SpanContext), OpenTelemetry.Trace.SpanAttributes initialAttributes = null, System.Collections.Generic.IEnumerable links = null, System.DateTimeOffset startTime = default(System.DateTimeOffset)) -> OpenTelemetry.Trace.TelemetrySpan OpenTelemetry.Trace.Tracer.StartSpan(string name, OpenTelemetry.Trace.SpanKind kind, in OpenTelemetry.Trace.TelemetrySpan parentSpan, OpenTelemetry.Trace.SpanAttributes initialAttributes = null, System.Collections.Generic.IEnumerable links = null, System.DateTimeOffset startTime = default(System.DateTimeOffset)) -> OpenTelemetry.Trace.TelemetrySpan OpenTelemetry.Trace.TracerProvider -OpenTelemetry.Trace.TracerProvider.Dispose() -> void OpenTelemetry.Trace.TracerProvider.GetTracer(string name, string version = null) -> OpenTelemetry.Trace.Tracer OpenTelemetry.Trace.TracerProvider.TracerProvider() -> void abstract OpenTelemetry.Context.RuntimeContextSlot.Get() -> T @@ -300,10 +302,9 @@ static readonly OpenTelemetry.Metrics.NoopMeasureMetric.Instance -> OpenTelem static readonly OpenTelemetry.Trace.Status.Error -> OpenTelemetry.Trace.Status static readonly OpenTelemetry.Trace.Status.Ok -> OpenTelemetry.Trace.Status static readonly OpenTelemetry.Trace.Status.Unset -> OpenTelemetry.Trace.Status +virtual OpenTelemetry.BaseProvider.Dispose(bool disposing) -> void virtual OpenTelemetry.Context.RuntimeContextSlot.Dispose(bool disposing) -> void virtual OpenTelemetry.Metrics.LabelSet.Labels.get -> System.Collections.Generic.IEnumerable> virtual OpenTelemetry.Metrics.LabelSet.Labels.set -> void virtual OpenTelemetry.Metrics.MeterFactoryBase.GetMeter(string name, string version = null) -> OpenTelemetry.Metrics.Meter -virtual OpenTelemetry.Metrics.MeterProvider.Dispose(bool disposing) -> void virtual OpenTelemetry.Metrics.MeterProvider.GetMeter(string name, string version = null) -> OpenTelemetry.Metrics.Meter -virtual OpenTelemetry.Trace.TracerProvider.Dispose(bool disposing) -> void diff --git a/src/OpenTelemetry.Api/BaseProvider.cs b/src/OpenTelemetry.Api/BaseProvider.cs new file mode 100644 index 00000000000..4aabc8cd119 --- /dev/null +++ b/src/OpenTelemetry.Api/BaseProvider.cs @@ -0,0 +1,49 @@ +// +// 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; + +namespace OpenTelemetry +{ + /// + /// Contains logic shared by all OpenTelemetry providers. + /// + public abstract class BaseProvider : IDisposable + { + /// + /// Finalizes an instance of the class. + /// + ~BaseProvider() + { + this.Dispose(false); + } + + /// + public void Dispose() + { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Releases the unmanaged resources used by this class and optionally releases the managed resources. + /// + /// to release both managed and unmanaged resources; to release only unmanaged resources. + protected virtual void Dispose(bool disposing) + { + } + } +} diff --git a/src/OpenTelemetry.Api/Metrics/MeterProvider.cs b/src/OpenTelemetry.Api/Metrics/MeterProvider.cs index b9c2f1ae97b..6b574aef1a1 100644 --- a/src/OpenTelemetry.Api/Metrics/MeterProvider.cs +++ b/src/OpenTelemetry.Api/Metrics/MeterProvider.cs @@ -21,7 +21,7 @@ namespace OpenTelemetry.Metrics /// /// MeterProvider is the entry point of the OpenTelemetry Metrics API. It provides access to Meters. /// - public class MeterProvider : IDisposable + public class MeterProvider : BaseProvider { private static ProxyMeter proxyMeter = new ProxyMeter(); private static bool isInitialized; @@ -71,13 +71,6 @@ public static void SetDefault(MeterProvider meterProvider) isInitialized = true; } - /// - public void Dispose() - { - this.Dispose(true); - GC.SuppressFinalize(this); - } - /// /// Returns a Meter for a given name and version. /// @@ -96,13 +89,5 @@ internal static void Reset() isInitialized = false; defaultProvider = new MeterProvider(); } - - /// - /// Releases the unmanaged resources used by this class and optionally releases the managed resources. - /// - /// to release both managed and unmanaged resources; to release only unmanaged resources. - protected virtual void Dispose(bool disposing) - { - } } } diff --git a/src/OpenTelemetry.Api/OpenTelemetry.Api.csproj b/src/OpenTelemetry.Api/OpenTelemetry.Api.csproj index dfb0a8b517e..25cf462d281 100644 --- a/src/OpenTelemetry.Api/OpenTelemetry.Api.csproj +++ b/src/OpenTelemetry.Api/OpenTelemetry.Api.csproj @@ -4,6 +4,10 @@ OpenTelemetry .NET API OpenTelemetry + + + + diff --git a/src/OpenTelemetry.Api/Trace/TracerProvider.cs b/src/OpenTelemetry.Api/Trace/TracerProvider.cs index e66f65cf12a..58f0fba55df 100644 --- a/src/OpenTelemetry.Api/Trace/TracerProvider.cs +++ b/src/OpenTelemetry.Api/Trace/TracerProvider.cs @@ -14,7 +14,6 @@ // limitations under the License. // -using System; using System.Diagnostics; namespace OpenTelemetry.Trace @@ -22,7 +21,7 @@ namespace OpenTelemetry.Trace /// /// TracerProvider is the entry point of the OpenTelemetry API. It provides access to . /// - public class TracerProvider : IDisposable + public class TracerProvider : BaseProvider { /// /// Initializes a new instance of the class. @@ -51,20 +50,5 @@ public Tracer GetTracer(string name, string version = null) return new Tracer(new ActivitySource(name, version)); } - - /// - public void Dispose() - { - this.Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Releases the unmanaged resources used by this class and optionally releases the managed resources. - /// - /// to release both managed and unmanaged resources; to release only unmanaged resources. - protected virtual void Dispose(bool disposing) - { - } } } diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs b/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs index 50ace926bc8..1fa13774da8 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleExporter.cs @@ -21,7 +21,6 @@ using OpenTelemetry.Logs; #endif using OpenTelemetry.Resources; -using OpenTelemetry.Trace; namespace OpenTelemetry.Exporter { @@ -29,7 +28,6 @@ public class ConsoleExporter : BaseExporter where T : class { private readonly ConsoleExporterOptions options; - private TracerProvider tracerProvider; public ConsoleExporter(ConsoleExporterOptions options) { @@ -100,7 +98,7 @@ public override ExportResult Export(in Batch batch) } } - var resource = this.tracerProvider?.GetResource() ?? Resource.Empty; + var resource = this.ParentProvider.GetResource(); if (resource != Resource.Empty) { this.WriteLine("Resource associated with Activity:"); @@ -141,11 +139,6 @@ public override ExportResult Export(in Batch batch) return ExportResult.Success; } - protected override void OnTracerProviderSet(TracerProvider tracerProvider) - { - this.tracerProvider = tracerProvider; - } - private void WriteLine(string message) { if (this.options.Targets.HasFlag(ConsoleExporterOutputTargets.Console)) diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs index 27a04e964aa..3c46264df04 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs @@ -199,9 +199,9 @@ protected override void Dispose(bool disposing) } /// - protected override void OnTracerProviderSet(TracerProvider tracerProvider) + protected override void OnParentProviderSet() { - this.SetResource(tracerProvider.GetResource()); + this.SetResource(this.ParentProvider.GetResource()); } private void SendCurrentBatches(Batch workingBatch) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs index c83e9d1a0c2..834207bf9da 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs @@ -130,9 +130,9 @@ protected override bool OnShutdown(int timeoutMilliseconds) } /// - protected override void OnTracerProviderSet(TracerProvider tracerProvider) + protected override void OnParentProviderSet() { - this.SetResource(tracerProvider.GetResource()); + this.SetResource(this.ParentProvider.GetResource()); } } } diff --git a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs index 2ed245ea7a0..f3b2654ae27 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs @@ -151,9 +151,9 @@ internal void SetResource(Resource resource) } /// - protected override void OnTracerProviderSet(TracerProvider tracerProvider) + protected override void OnParentProviderSet() { - this.SetResource(tracerProvider.GetResource()); + this.SetResource(this.ParentProvider.GetResource()); } private static string ResolveHostAddress(string hostName, AddressFamily family) diff --git a/src/OpenTelemetry/.publicApi/net452/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net452/PublicAPI.Unshipped.txt index 8fa6eec76fe..466657116cb 100644 --- a/src/OpenTelemetry/.publicApi/net452/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/net452/PublicAPI.Unshipped.txt @@ -1,3 +1,4 @@ +OpenTelemetry.BaseExporter.ParentProvider.get -> OpenTelemetry.BaseProvider OpenTelemetry.BaseExportProcessor OpenTelemetry.BaseExportProcessor.BaseExportProcessor(OpenTelemetry.BaseExporter exporter) -> void OpenTelemetry.BaseExporter @@ -8,6 +9,7 @@ OpenTelemetry.BaseProcessor OpenTelemetry.BaseProcessor.BaseProcessor() -> void OpenTelemetry.BaseProcessor.Dispose() -> void OpenTelemetry.BaseProcessor.ForceFlush(int timeoutMilliseconds = -1) -> bool +OpenTelemetry.BaseProcessor.ParentProvider.get -> OpenTelemetry.BaseProvider OpenTelemetry.BaseProcessor.Shutdown(int timeoutMilliseconds = -1) -> bool OpenTelemetry.Batch OpenTelemetry.Batch.Batch() -> void @@ -106,6 +108,7 @@ OpenTelemetry.Metrics.MeterProviderBuilder.Build() -> OpenTelemetry.Metrics.Mete OpenTelemetry.Metrics.MeterProviderBuilder.SetExporter(OpenTelemetry.Metrics.Export.MetricExporter exporter) -> OpenTelemetry.Metrics.MeterProviderBuilder OpenTelemetry.Metrics.MeterProviderBuilder.SetProcessor(OpenTelemetry.Metrics.Export.MetricProcessor processor) -> OpenTelemetry.Metrics.MeterProviderBuilder OpenTelemetry.Metrics.MeterProviderBuilder.SetPushInterval(System.TimeSpan pushInterval) -> OpenTelemetry.Metrics.MeterProviderBuilder +OpenTelemetry.ProviderExtensions OpenTelemetry.ReentrantExportProcessor OpenTelemetry.ReentrantExportProcessor.ReentrantExportProcessor(OpenTelemetry.BaseExporter exporter) -> void OpenTelemetry.Resources.Resource @@ -118,7 +121,6 @@ OpenTelemetry.SimpleExportProcessor OpenTelemetry.SimpleExportProcessor.SimpleExportProcessor(OpenTelemetry.BaseExporter exporter) -> void OpenTelemetry.SuppressInstrumentationScope OpenTelemetry.SuppressInstrumentationScope.Dispose() -> void -OpenTelemetry.Trace.ActivityExtensions OpenTelemetry.Trace.AlwaysOffSampler OpenTelemetry.Trace.AlwaysOffSampler.AlwaysOffSampler() -> void OpenTelemetry.Trace.AlwaysOnSampler @@ -176,6 +178,7 @@ const OpenTelemetry.Resources.Resource.ServiceNameKey = "service.name" -> string const OpenTelemetry.Resources.Resource.ServiceNamespaceKey = "service.namespace" -> string const OpenTelemetry.Resources.Resource.ServiceVersionKey = "service.version" -> string override OpenTelemetry.BaseExportProcessor.Dispose(bool disposing) -> void +override OpenTelemetry.BaseExportProcessor.OnParentProviderSet() -> void override OpenTelemetry.BaseExportProcessor.OnShutdown(int timeoutMilliseconds) -> bool override OpenTelemetry.BatchExportProcessor.OnEnd(T data) -> void override OpenTelemetry.BatchExportProcessor.OnForceFlush(int timeoutMilliseconds) -> bool @@ -222,6 +225,7 @@ override OpenTelemetry.Trace.TraceIdRatioBasedSampler.ShouldSample(in OpenTeleme override abstract OpenTelemetry.BaseExportProcessor.OnEnd(T data) -> void override sealed OpenTelemetry.BaseExportProcessor.OnStart(T data) -> void readonly OpenTelemetry.BaseExportProcessor.exporter -> OpenTelemetry.BaseExporter +static OpenTelemetry.ProviderExtensions.GetResource(this OpenTelemetry.BaseProvider baseProvider) -> OpenTelemetry.Resources.Resource static OpenTelemetry.Resources.Resource.Empty.get -> OpenTelemetry.Resources.Resource static OpenTelemetry.Resources.Resources.CreateServiceResource(string serviceName, string serviceInstanceId = null, string serviceNamespace = null, string serviceVersion = null) -> OpenTelemetry.Resources.Resource static OpenTelemetry.Sdk.CreateMeterProviderBuilder() -> OpenTelemetry.Metrics.MeterProviderBuilder @@ -230,16 +234,16 @@ static OpenTelemetry.Sdk.SetDefaultTextMapPropagator(OpenTelemetry.Context.Propa static OpenTelemetry.Sdk.SuppressInstrumentation.get -> bool static OpenTelemetry.SuppressInstrumentationScope.Begin(bool value = true) -> System.IDisposable static OpenTelemetry.SuppressInstrumentationScope.Enter() -> int -static OpenTelemetry.Trace.ActivityExtensions.GetResource(this System.Diagnostics.Activity activity) -> OpenTelemetry.Resources.Resource -static OpenTelemetry.Trace.ActivityExtensions.SetResource(this System.Diagnostics.Activity activity, OpenTelemetry.Resources.Resource resource) -> void static OpenTelemetry.Trace.SamplingResult.operator !=(OpenTelemetry.Trace.SamplingResult decision1, OpenTelemetry.Trace.SamplingResult decision2) -> bool static OpenTelemetry.Trace.SamplingResult.operator ==(OpenTelemetry.Trace.SamplingResult decision1, OpenTelemetry.Trace.SamplingResult decision2) -> bool static OpenTelemetry.Trace.TracerProviderExtensions.AddProcessor(this OpenTelemetry.Trace.TracerProvider provider, OpenTelemetry.BaseProcessor processor) -> OpenTelemetry.Trace.TracerProvider virtual OpenTelemetry.BaseExporter.Dispose(bool disposing) -> void +virtual OpenTelemetry.BaseExporter.OnParentProviderSet() -> void virtual OpenTelemetry.BaseExporter.OnShutdown(int timeoutMilliseconds) -> bool virtual OpenTelemetry.BaseProcessor.Dispose(bool disposing) -> void virtual OpenTelemetry.BaseProcessor.OnEnd(T data) -> void virtual OpenTelemetry.BaseProcessor.OnForceFlush(int timeoutMilliseconds) -> bool +virtual OpenTelemetry.BaseProcessor.OnParentProviderSet() -> void virtual OpenTelemetry.BaseProcessor.OnShutdown(int timeoutMilliseconds) -> bool virtual OpenTelemetry.BaseProcessor.OnStart(T data) -> void virtual OpenTelemetry.Metrics.Aggregators.Aggregator.Checkpoint() -> void diff --git a/src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt index 8fa6eec76fe..466657116cb 100644 --- a/src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt @@ -1,3 +1,4 @@ +OpenTelemetry.BaseExporter.ParentProvider.get -> OpenTelemetry.BaseProvider OpenTelemetry.BaseExportProcessor OpenTelemetry.BaseExportProcessor.BaseExportProcessor(OpenTelemetry.BaseExporter exporter) -> void OpenTelemetry.BaseExporter @@ -8,6 +9,7 @@ OpenTelemetry.BaseProcessor OpenTelemetry.BaseProcessor.BaseProcessor() -> void OpenTelemetry.BaseProcessor.Dispose() -> void OpenTelemetry.BaseProcessor.ForceFlush(int timeoutMilliseconds = -1) -> bool +OpenTelemetry.BaseProcessor.ParentProvider.get -> OpenTelemetry.BaseProvider OpenTelemetry.BaseProcessor.Shutdown(int timeoutMilliseconds = -1) -> bool OpenTelemetry.Batch OpenTelemetry.Batch.Batch() -> void @@ -106,6 +108,7 @@ OpenTelemetry.Metrics.MeterProviderBuilder.Build() -> OpenTelemetry.Metrics.Mete OpenTelemetry.Metrics.MeterProviderBuilder.SetExporter(OpenTelemetry.Metrics.Export.MetricExporter exporter) -> OpenTelemetry.Metrics.MeterProviderBuilder OpenTelemetry.Metrics.MeterProviderBuilder.SetProcessor(OpenTelemetry.Metrics.Export.MetricProcessor processor) -> OpenTelemetry.Metrics.MeterProviderBuilder OpenTelemetry.Metrics.MeterProviderBuilder.SetPushInterval(System.TimeSpan pushInterval) -> OpenTelemetry.Metrics.MeterProviderBuilder +OpenTelemetry.ProviderExtensions OpenTelemetry.ReentrantExportProcessor OpenTelemetry.ReentrantExportProcessor.ReentrantExportProcessor(OpenTelemetry.BaseExporter exporter) -> void OpenTelemetry.Resources.Resource @@ -118,7 +121,6 @@ OpenTelemetry.SimpleExportProcessor OpenTelemetry.SimpleExportProcessor.SimpleExportProcessor(OpenTelemetry.BaseExporter exporter) -> void OpenTelemetry.SuppressInstrumentationScope OpenTelemetry.SuppressInstrumentationScope.Dispose() -> void -OpenTelemetry.Trace.ActivityExtensions OpenTelemetry.Trace.AlwaysOffSampler OpenTelemetry.Trace.AlwaysOffSampler.AlwaysOffSampler() -> void OpenTelemetry.Trace.AlwaysOnSampler @@ -176,6 +178,7 @@ const OpenTelemetry.Resources.Resource.ServiceNameKey = "service.name" -> string const OpenTelemetry.Resources.Resource.ServiceNamespaceKey = "service.namespace" -> string const OpenTelemetry.Resources.Resource.ServiceVersionKey = "service.version" -> string override OpenTelemetry.BaseExportProcessor.Dispose(bool disposing) -> void +override OpenTelemetry.BaseExportProcessor.OnParentProviderSet() -> void override OpenTelemetry.BaseExportProcessor.OnShutdown(int timeoutMilliseconds) -> bool override OpenTelemetry.BatchExportProcessor.OnEnd(T data) -> void override OpenTelemetry.BatchExportProcessor.OnForceFlush(int timeoutMilliseconds) -> bool @@ -222,6 +225,7 @@ override OpenTelemetry.Trace.TraceIdRatioBasedSampler.ShouldSample(in OpenTeleme override abstract OpenTelemetry.BaseExportProcessor.OnEnd(T data) -> void override sealed OpenTelemetry.BaseExportProcessor.OnStart(T data) -> void readonly OpenTelemetry.BaseExportProcessor.exporter -> OpenTelemetry.BaseExporter +static OpenTelemetry.ProviderExtensions.GetResource(this OpenTelemetry.BaseProvider baseProvider) -> OpenTelemetry.Resources.Resource static OpenTelemetry.Resources.Resource.Empty.get -> OpenTelemetry.Resources.Resource static OpenTelemetry.Resources.Resources.CreateServiceResource(string serviceName, string serviceInstanceId = null, string serviceNamespace = null, string serviceVersion = null) -> OpenTelemetry.Resources.Resource static OpenTelemetry.Sdk.CreateMeterProviderBuilder() -> OpenTelemetry.Metrics.MeterProviderBuilder @@ -230,16 +234,16 @@ static OpenTelemetry.Sdk.SetDefaultTextMapPropagator(OpenTelemetry.Context.Propa static OpenTelemetry.Sdk.SuppressInstrumentation.get -> bool static OpenTelemetry.SuppressInstrumentationScope.Begin(bool value = true) -> System.IDisposable static OpenTelemetry.SuppressInstrumentationScope.Enter() -> int -static OpenTelemetry.Trace.ActivityExtensions.GetResource(this System.Diagnostics.Activity activity) -> OpenTelemetry.Resources.Resource -static OpenTelemetry.Trace.ActivityExtensions.SetResource(this System.Diagnostics.Activity activity, OpenTelemetry.Resources.Resource resource) -> void static OpenTelemetry.Trace.SamplingResult.operator !=(OpenTelemetry.Trace.SamplingResult decision1, OpenTelemetry.Trace.SamplingResult decision2) -> bool static OpenTelemetry.Trace.SamplingResult.operator ==(OpenTelemetry.Trace.SamplingResult decision1, OpenTelemetry.Trace.SamplingResult decision2) -> bool static OpenTelemetry.Trace.TracerProviderExtensions.AddProcessor(this OpenTelemetry.Trace.TracerProvider provider, OpenTelemetry.BaseProcessor processor) -> OpenTelemetry.Trace.TracerProvider virtual OpenTelemetry.BaseExporter.Dispose(bool disposing) -> void +virtual OpenTelemetry.BaseExporter.OnParentProviderSet() -> void virtual OpenTelemetry.BaseExporter.OnShutdown(int timeoutMilliseconds) -> bool virtual OpenTelemetry.BaseProcessor.Dispose(bool disposing) -> void virtual OpenTelemetry.BaseProcessor.OnEnd(T data) -> void virtual OpenTelemetry.BaseProcessor.OnForceFlush(int timeoutMilliseconds) -> bool +virtual OpenTelemetry.BaseProcessor.OnParentProviderSet() -> void virtual OpenTelemetry.BaseProcessor.OnShutdown(int timeoutMilliseconds) -> bool virtual OpenTelemetry.BaseProcessor.OnStart(T data) -> void virtual OpenTelemetry.Metrics.Aggregators.Aggregator.Checkpoint() -> void diff --git a/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt index fcb0d703375..e79cf752955 100644 --- a/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt @@ -1,4 +1,5 @@ Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions +OpenTelemetry.BaseExporter.ParentProvider.get -> OpenTelemetry.BaseProvider OpenTelemetry.BaseExportProcessor OpenTelemetry.BaseExportProcessor.BaseExportProcessor(OpenTelemetry.BaseExporter exporter) -> void OpenTelemetry.BaseExporter @@ -9,6 +10,7 @@ OpenTelemetry.BaseProcessor OpenTelemetry.BaseProcessor.BaseProcessor() -> void OpenTelemetry.BaseProcessor.Dispose() -> void OpenTelemetry.BaseProcessor.ForceFlush(int timeoutMilliseconds = -1) -> bool +OpenTelemetry.BaseProcessor.ParentProvider.get -> OpenTelemetry.BaseProvider OpenTelemetry.BaseProcessor.Shutdown(int timeoutMilliseconds = -1) -> bool OpenTelemetry.Batch OpenTelemetry.Batch.Batch() -> void @@ -125,6 +127,7 @@ OpenTelemetry.Metrics.MeterProviderBuilder.Build() -> OpenTelemetry.Metrics.Mete OpenTelemetry.Metrics.MeterProviderBuilder.SetExporter(OpenTelemetry.Metrics.Export.MetricExporter exporter) -> OpenTelemetry.Metrics.MeterProviderBuilder OpenTelemetry.Metrics.MeterProviderBuilder.SetProcessor(OpenTelemetry.Metrics.Export.MetricProcessor processor) -> OpenTelemetry.Metrics.MeterProviderBuilder OpenTelemetry.Metrics.MeterProviderBuilder.SetPushInterval(System.TimeSpan pushInterval) -> OpenTelemetry.Metrics.MeterProviderBuilder +OpenTelemetry.ProviderExtensions OpenTelemetry.ReentrantExportProcessor OpenTelemetry.ReentrantExportProcessor.ReentrantExportProcessor(OpenTelemetry.BaseExporter exporter) -> void OpenTelemetry.Resources.Resource @@ -137,7 +140,6 @@ OpenTelemetry.SimpleExportProcessor OpenTelemetry.SimpleExportProcessor.SimpleExportProcessor(OpenTelemetry.BaseExporter exporter) -> void OpenTelemetry.SuppressInstrumentationScope OpenTelemetry.SuppressInstrumentationScope.Dispose() -> void -OpenTelemetry.Trace.ActivityExtensions OpenTelemetry.Trace.AlwaysOffSampler OpenTelemetry.Trace.AlwaysOffSampler.AlwaysOffSampler() -> void OpenTelemetry.Trace.AlwaysOnSampler @@ -195,6 +197,7 @@ const OpenTelemetry.Resources.Resource.ServiceNameKey = "service.name" -> string const OpenTelemetry.Resources.Resource.ServiceNamespaceKey = "service.namespace" -> string const OpenTelemetry.Resources.Resource.ServiceVersionKey = "service.version" -> string override OpenTelemetry.BaseExportProcessor.Dispose(bool disposing) -> void +override OpenTelemetry.BaseExportProcessor.OnParentProviderSet() -> void override OpenTelemetry.BaseExportProcessor.OnShutdown(int timeoutMilliseconds) -> bool override OpenTelemetry.BatchExportProcessor.OnEnd(T data) -> void override OpenTelemetry.BatchExportProcessor.OnForceFlush(int timeoutMilliseconds) -> bool @@ -242,6 +245,7 @@ override abstract OpenTelemetry.BaseExportProcessor.OnEnd(T data) -> void override sealed OpenTelemetry.BaseExportProcessor.OnStart(T data) -> void readonly OpenTelemetry.BaseExportProcessor.exporter -> OpenTelemetry.BaseExporter static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder builder, System.Action configure = null) -> Microsoft.Extensions.Logging.ILoggingBuilder +static OpenTelemetry.ProviderExtensions.GetResource(this OpenTelemetry.BaseProvider baseProvider) -> OpenTelemetry.Resources.Resource static OpenTelemetry.Resources.Resource.Empty.get -> OpenTelemetry.Resources.Resource static OpenTelemetry.Resources.Resources.CreateServiceResource(string serviceName, string serviceInstanceId = null, string serviceNamespace = null, string serviceVersion = null) -> OpenTelemetry.Resources.Resource static OpenTelemetry.Sdk.CreateMeterProviderBuilder() -> OpenTelemetry.Metrics.MeterProviderBuilder @@ -250,16 +254,16 @@ static OpenTelemetry.Sdk.SetDefaultTextMapPropagator(OpenTelemetry.Context.Propa static OpenTelemetry.Sdk.SuppressInstrumentation.get -> bool static OpenTelemetry.SuppressInstrumentationScope.Begin(bool value = true) -> System.IDisposable static OpenTelemetry.SuppressInstrumentationScope.Enter() -> int -static OpenTelemetry.Trace.ActivityExtensions.GetResource(this System.Diagnostics.Activity activity) -> OpenTelemetry.Resources.Resource -static OpenTelemetry.Trace.ActivityExtensions.SetResource(this System.Diagnostics.Activity activity, OpenTelemetry.Resources.Resource resource) -> void static OpenTelemetry.Trace.SamplingResult.operator !=(OpenTelemetry.Trace.SamplingResult decision1, OpenTelemetry.Trace.SamplingResult decision2) -> bool static OpenTelemetry.Trace.SamplingResult.operator ==(OpenTelemetry.Trace.SamplingResult decision1, OpenTelemetry.Trace.SamplingResult decision2) -> bool static OpenTelemetry.Trace.TracerProviderExtensions.AddProcessor(this OpenTelemetry.Trace.TracerProvider provider, OpenTelemetry.BaseProcessor processor) -> OpenTelemetry.Trace.TracerProvider virtual OpenTelemetry.BaseExporter.Dispose(bool disposing) -> void +virtual OpenTelemetry.BaseExporter.OnParentProviderSet() -> void virtual OpenTelemetry.BaseExporter.OnShutdown(int timeoutMilliseconds) -> bool virtual OpenTelemetry.BaseProcessor.Dispose(bool disposing) -> void virtual OpenTelemetry.BaseProcessor.OnEnd(T data) -> void virtual OpenTelemetry.BaseProcessor.OnForceFlush(int timeoutMilliseconds) -> bool +virtual OpenTelemetry.BaseProcessor.OnParentProviderSet() -> void virtual OpenTelemetry.BaseProcessor.OnShutdown(int timeoutMilliseconds) -> bool virtual OpenTelemetry.BaseProcessor.OnStart(T data) -> void virtual OpenTelemetry.Logs.OpenTelemetryLoggerProvider.Dispose(bool disposing) -> void diff --git a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index fcb0d703375..e79cf752955 100644 --- a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,4 +1,5 @@ Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions +OpenTelemetry.BaseExporter.ParentProvider.get -> OpenTelemetry.BaseProvider OpenTelemetry.BaseExportProcessor OpenTelemetry.BaseExportProcessor.BaseExportProcessor(OpenTelemetry.BaseExporter exporter) -> void OpenTelemetry.BaseExporter @@ -9,6 +10,7 @@ OpenTelemetry.BaseProcessor OpenTelemetry.BaseProcessor.BaseProcessor() -> void OpenTelemetry.BaseProcessor.Dispose() -> void OpenTelemetry.BaseProcessor.ForceFlush(int timeoutMilliseconds = -1) -> bool +OpenTelemetry.BaseProcessor.ParentProvider.get -> OpenTelemetry.BaseProvider OpenTelemetry.BaseProcessor.Shutdown(int timeoutMilliseconds = -1) -> bool OpenTelemetry.Batch OpenTelemetry.Batch.Batch() -> void @@ -125,6 +127,7 @@ OpenTelemetry.Metrics.MeterProviderBuilder.Build() -> OpenTelemetry.Metrics.Mete OpenTelemetry.Metrics.MeterProviderBuilder.SetExporter(OpenTelemetry.Metrics.Export.MetricExporter exporter) -> OpenTelemetry.Metrics.MeterProviderBuilder OpenTelemetry.Metrics.MeterProviderBuilder.SetProcessor(OpenTelemetry.Metrics.Export.MetricProcessor processor) -> OpenTelemetry.Metrics.MeterProviderBuilder OpenTelemetry.Metrics.MeterProviderBuilder.SetPushInterval(System.TimeSpan pushInterval) -> OpenTelemetry.Metrics.MeterProviderBuilder +OpenTelemetry.ProviderExtensions OpenTelemetry.ReentrantExportProcessor OpenTelemetry.ReentrantExportProcessor.ReentrantExportProcessor(OpenTelemetry.BaseExporter exporter) -> void OpenTelemetry.Resources.Resource @@ -137,7 +140,6 @@ OpenTelemetry.SimpleExportProcessor OpenTelemetry.SimpleExportProcessor.SimpleExportProcessor(OpenTelemetry.BaseExporter exporter) -> void OpenTelemetry.SuppressInstrumentationScope OpenTelemetry.SuppressInstrumentationScope.Dispose() -> void -OpenTelemetry.Trace.ActivityExtensions OpenTelemetry.Trace.AlwaysOffSampler OpenTelemetry.Trace.AlwaysOffSampler.AlwaysOffSampler() -> void OpenTelemetry.Trace.AlwaysOnSampler @@ -195,6 +197,7 @@ const OpenTelemetry.Resources.Resource.ServiceNameKey = "service.name" -> string const OpenTelemetry.Resources.Resource.ServiceNamespaceKey = "service.namespace" -> string const OpenTelemetry.Resources.Resource.ServiceVersionKey = "service.version" -> string override OpenTelemetry.BaseExportProcessor.Dispose(bool disposing) -> void +override OpenTelemetry.BaseExportProcessor.OnParentProviderSet() -> void override OpenTelemetry.BaseExportProcessor.OnShutdown(int timeoutMilliseconds) -> bool override OpenTelemetry.BatchExportProcessor.OnEnd(T data) -> void override OpenTelemetry.BatchExportProcessor.OnForceFlush(int timeoutMilliseconds) -> bool @@ -242,6 +245,7 @@ override abstract OpenTelemetry.BaseExportProcessor.OnEnd(T data) -> void override sealed OpenTelemetry.BaseExportProcessor.OnStart(T data) -> void readonly OpenTelemetry.BaseExportProcessor.exporter -> OpenTelemetry.BaseExporter static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder builder, System.Action configure = null) -> Microsoft.Extensions.Logging.ILoggingBuilder +static OpenTelemetry.ProviderExtensions.GetResource(this OpenTelemetry.BaseProvider baseProvider) -> OpenTelemetry.Resources.Resource static OpenTelemetry.Resources.Resource.Empty.get -> OpenTelemetry.Resources.Resource static OpenTelemetry.Resources.Resources.CreateServiceResource(string serviceName, string serviceInstanceId = null, string serviceNamespace = null, string serviceVersion = null) -> OpenTelemetry.Resources.Resource static OpenTelemetry.Sdk.CreateMeterProviderBuilder() -> OpenTelemetry.Metrics.MeterProviderBuilder @@ -250,16 +254,16 @@ static OpenTelemetry.Sdk.SetDefaultTextMapPropagator(OpenTelemetry.Context.Propa static OpenTelemetry.Sdk.SuppressInstrumentation.get -> bool static OpenTelemetry.SuppressInstrumentationScope.Begin(bool value = true) -> System.IDisposable static OpenTelemetry.SuppressInstrumentationScope.Enter() -> int -static OpenTelemetry.Trace.ActivityExtensions.GetResource(this System.Diagnostics.Activity activity) -> OpenTelemetry.Resources.Resource -static OpenTelemetry.Trace.ActivityExtensions.SetResource(this System.Diagnostics.Activity activity, OpenTelemetry.Resources.Resource resource) -> void static OpenTelemetry.Trace.SamplingResult.operator !=(OpenTelemetry.Trace.SamplingResult decision1, OpenTelemetry.Trace.SamplingResult decision2) -> bool static OpenTelemetry.Trace.SamplingResult.operator ==(OpenTelemetry.Trace.SamplingResult decision1, OpenTelemetry.Trace.SamplingResult decision2) -> bool static OpenTelemetry.Trace.TracerProviderExtensions.AddProcessor(this OpenTelemetry.Trace.TracerProvider provider, OpenTelemetry.BaseProcessor processor) -> OpenTelemetry.Trace.TracerProvider virtual OpenTelemetry.BaseExporter.Dispose(bool disposing) -> void +virtual OpenTelemetry.BaseExporter.OnParentProviderSet() -> void virtual OpenTelemetry.BaseExporter.OnShutdown(int timeoutMilliseconds) -> bool virtual OpenTelemetry.BaseProcessor.Dispose(bool disposing) -> void virtual OpenTelemetry.BaseProcessor.OnEnd(T data) -> void virtual OpenTelemetry.BaseProcessor.OnForceFlush(int timeoutMilliseconds) -> bool +virtual OpenTelemetry.BaseProcessor.OnParentProviderSet() -> void virtual OpenTelemetry.BaseProcessor.OnShutdown(int timeoutMilliseconds) -> bool virtual OpenTelemetry.BaseProcessor.OnStart(T data) -> void virtual OpenTelemetry.Logs.OpenTelemetryLoggerProvider.Dispose(bool disposing) -> void diff --git a/src/OpenTelemetry/BaseExportProcessor.cs b/src/OpenTelemetry/BaseExportProcessor.cs index 7a9ca0734b9..e77fbf442e9 100644 --- a/src/OpenTelemetry/BaseExportProcessor.cs +++ b/src/OpenTelemetry/BaseExportProcessor.cs @@ -16,7 +16,6 @@ using System; using OpenTelemetry.Internal; -using OpenTelemetry.Trace; namespace OpenTelemetry { @@ -48,9 +47,9 @@ public sealed override void OnStart(T data) public abstract override void OnEnd(T data); /// - internal override void SetTracerProvider(TracerProvider tracerProvider) + protected override void OnParentProviderSet() { - this.exporter.SetTracerProvider(tracerProvider); + this.exporter.ParentProvider = this.ParentProvider; } /// diff --git a/src/OpenTelemetry/BaseExporter.cs b/src/OpenTelemetry/BaseExporter.cs index 4201c982d8b..4e526a12329 100644 --- a/src/OpenTelemetry/BaseExporter.cs +++ b/src/OpenTelemetry/BaseExporter.cs @@ -17,7 +17,6 @@ using System; using System.Threading; using OpenTelemetry.Internal; -using OpenTelemetry.Trace; namespace OpenTelemetry { @@ -45,6 +44,20 @@ public abstract class BaseExporter : IDisposable where T : class { private int shutdownCount; + private BaseProvider parentProvider; + + /// + /// Gets the parent . + /// + public BaseProvider ParentProvider + { + get => this.parentProvider; + internal set + { + this.parentProvider = value; + this.OnParentProviderSet(); + } + } /// /// Exports a batch of telemetry objects. @@ -101,11 +114,6 @@ public void Dispose() GC.SuppressFinalize(this); } - internal void SetTracerProvider(TracerProvider tracerProvider) - { - this.OnTracerProviderSet(tracerProvider); - } - /// /// Called by Shutdown. This function should block the current /// thread until shutdown completed or timed out. @@ -140,10 +148,9 @@ protected virtual void Dispose(bool disposing) } /// - /// Called when the parent is set on the exporter. + /// Called when the parent is set. /// - /// . - protected virtual void OnTracerProviderSet(TracerProvider tracerProvider) + protected virtual void OnParentProviderSet() { } } diff --git a/src/OpenTelemetry/BaseProcessor.cs b/src/OpenTelemetry/BaseProcessor.cs index 9805d3c28e2..7b7b32c39d0 100644 --- a/src/OpenTelemetry/BaseProcessor.cs +++ b/src/OpenTelemetry/BaseProcessor.cs @@ -17,7 +17,6 @@ using System; using System.Threading; using OpenTelemetry.Internal; -using OpenTelemetry.Trace; namespace OpenTelemetry { @@ -28,6 +27,20 @@ namespace OpenTelemetry public abstract class BaseProcessor : IDisposable { private int shutdownCount; + private BaseProvider parentProvider; + + /// + /// Gets the parent . + /// + public BaseProvider ParentProvider + { + get => this.parentProvider; + internal set + { + this.parentProvider = value; + this.OnParentProviderSet(); + } + } /// /// Called synchronously when a telemetry object is started. @@ -142,14 +155,6 @@ public void Dispose() GC.SuppressFinalize(this); } - /// - /// Set the parent . - /// - /// . - internal virtual void SetTracerProvider(TracerProvider tracerProvider) - { - } - /// /// Called by ForceFlush. This function should block the current /// thread until flush completed, shutdown signaled or timed out. @@ -203,5 +208,12 @@ protected virtual bool OnShutdown(int timeoutMilliseconds) protected virtual void Dispose(bool disposing) { } + + /// + /// Called when the parent is set. + /// + protected virtual void OnParentProviderSet() + { + } } } diff --git a/src/OpenTelemetry/OpenTelemetry.csproj b/src/OpenTelemetry/OpenTelemetry.csproj index 36ceb4b2b5a..f27693c5eed 100644 --- a/src/OpenTelemetry/OpenTelemetry.csproj +++ b/src/OpenTelemetry/OpenTelemetry.csproj @@ -7,6 +7,14 @@ --> $(NoWarn),1591 + + + + + + + + diff --git a/src/OpenTelemetry/ProviderExtensions.cs b/src/OpenTelemetry/ProviderExtensions.cs new file mode 100644 index 00000000000..c5b231c321a --- /dev/null +++ b/src/OpenTelemetry/ProviderExtensions.cs @@ -0,0 +1,42 @@ +// +// 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 OpenTelemetry.Resources; +using OpenTelemetry.Trace; + +namespace OpenTelemetry +{ + /// + /// Contains provider extension methods. + /// + public static class ProviderExtensions + { + /// + /// Gets the associated with the . + /// + /// . + /// if found otherwise . + public static Resource GetResource(this BaseProvider baseProvider) + { + if (baseProvider is TracerProviderSdk tracerProviderSdk) + { + return tracerProviderSdk.Resource; + } + + return Resource.Empty; + } + } +} diff --git a/src/OpenTelemetry/Trace/TracerProviderExtensions.cs b/src/OpenTelemetry/Trace/TracerProviderExtensions.cs index ef99aaf4f3b..f503cb59f97 100644 --- a/src/OpenTelemetry/Trace/TracerProviderExtensions.cs +++ b/src/OpenTelemetry/Trace/TracerProviderExtensions.cs @@ -16,7 +16,6 @@ using System; using System.Diagnostics; -using OpenTelemetry.Resources; namespace OpenTelemetry.Trace { @@ -43,15 +42,5 @@ public static TracerProvider AddProcessor(this TracerProvider provider, BaseProc return trait.AddProcessor(processor); } - - public static Resource GetResource(this TracerProvider tracerProvider) - { - if (tracerProvider is TracerProviderSdk tracerProviderSdk) - { - return tracerProviderSdk.Resource; - } - - return Resource.Empty; - } } } diff --git a/src/OpenTelemetry/Trace/TracerProviderSdk.cs b/src/OpenTelemetry/Trace/TracerProviderSdk.cs index b25d73ce51e..e5432b7d456 100644 --- a/src/OpenTelemetry/Trace/TracerProviderSdk.cs +++ b/src/OpenTelemetry/Trace/TracerProviderSdk.cs @@ -46,7 +46,7 @@ internal TracerProviderSdk( foreach (var processor in processors) { - processor.SetTracerProvider(this); + processor.ParentProvider = this; this.AddProcessor(processor); } From 3d2b8acc9d31cdb46aefd5fd7e2ad9758e908c71 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Fri, 6 Nov 2020 11:21:42 -0800 Subject: [PATCH 07/12] Project fixup. --- build/Common.prod.props | 4 ++-- src/OpenTelemetry.Api/OpenTelemetry.Api.csproj | 4 ---- src/OpenTelemetry/OpenTelemetry.csproj | 8 -------- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/build/Common.prod.props b/build/Common.prod.props index cff03f9845c..4bedfd73028 100644 --- a/build/Common.prod.props +++ b/build/Common.prod.props @@ -61,8 +61,8 @@ - - + + diff --git a/src/OpenTelemetry.Api/OpenTelemetry.Api.csproj b/src/OpenTelemetry.Api/OpenTelemetry.Api.csproj index 25cf462d281..dfb0a8b517e 100644 --- a/src/OpenTelemetry.Api/OpenTelemetry.Api.csproj +++ b/src/OpenTelemetry.Api/OpenTelemetry.Api.csproj @@ -4,10 +4,6 @@ OpenTelemetry .NET API OpenTelemetry - - - - diff --git a/src/OpenTelemetry/OpenTelemetry.csproj b/src/OpenTelemetry/OpenTelemetry.csproj index f27693c5eed..36ceb4b2b5a 100644 --- a/src/OpenTelemetry/OpenTelemetry.csproj +++ b/src/OpenTelemetry/OpenTelemetry.csproj @@ -7,14 +7,6 @@ --> $(NoWarn),1591 - - - - - - - - From b9426d36030c59922be09b86bc98a88e0fd933b2 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Sat, 7 Nov 2020 16:37:34 -0800 Subject: [PATCH 08/12] Removed OnParentProviderSet. --- build/Common.prod.props | 6 +++-- .../JaegerExporter.cs | 12 ++++------ .../OtlpExporter.cs | 12 ++++------ .../ZipkinExporter.cs | 12 ++++------ .../.publicApi/net452/PublicAPI.Unshipped.txt | 3 --- .../.publicApi/net46/PublicAPI.Unshipped.txt | 3 --- .../.publicApi/net461/PublicAPI.Unshipped.txt | 3 --- .../netstandard2.0/PublicAPI.Unshipped.txt | 3 --- src/OpenTelemetry/BaseExportProcessor.cs | 7 +++--- src/OpenTelemetry/BaseExporter.cs | 18 +-------------- src/OpenTelemetry/BaseProcessor.cs | 23 +++++-------------- .../Internal/OpenTelemetrySdkEventSource.cs | 2 +- src/OpenTelemetry/Trace/TracerProviderSdk.cs | 2 +- .../HttpInListenerTests.cs | 4 ++-- ...stsCollectionsIsAccordingToTheSpecTests.cs | 2 +- .../GrpcTests.client.cs | 6 ++--- .../HttpClientTests.Basic.netcore31.cs | 12 +++++----- .../HttpClientTests.netcore31.cs | 2 +- .../HttpWebRequestTests.Basic.netfx.cs | 4 ++-- .../HttpWebRequestTests.netfx.cs | 2 +- .../SqlClientTests.cs | 6 ++--- ...kExchangeRedisCallsInstrumentationTests.cs | 2 +- 22 files changed, 52 insertions(+), 94 deletions(-) diff --git a/build/Common.prod.props b/build/Common.prod.props index 4bedfd73028..d089a05ee77 100644 --- a/build/Common.prod.props +++ b/build/Common.prod.props @@ -61,8 +61,10 @@ - - + + + + diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs index 3c46264df04..52611fd6734 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs @@ -20,7 +20,6 @@ using System.Runtime.CompilerServices; using OpenTelemetry.Exporter.Jaeger.Implementation; using OpenTelemetry.Resources; -using OpenTelemetry.Trace; using Thrift.Protocol; using Thrift.Transport; using Process = OpenTelemetry.Exporter.Jaeger.Implementation.Process; @@ -65,6 +64,11 @@ public override ExportResult Export(in Batch activityBatch) { try { + if (this.processCache == null) + { + this.SetResource(this.ParentProvider.GetResource()); + } + foreach (var activity in activityBatch) { this.AppendSpan(activity.ToJaegerSpan()); @@ -198,12 +202,6 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); } - /// - protected override void OnParentProviderSet() - { - this.SetResource(this.ParentProvider.GetResource()); - } - private void SendCurrentBatches(Batch workingBatch) { try diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs index 834207bf9da..68641b26da1 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs @@ -22,7 +22,6 @@ using Grpc.Core; using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; using OpenTelemetry.Resources; -using OpenTelemetry.Trace; using OtlpCollector = Opentelemetry.Proto.Collector.Trace.V1; using OtlpCommon = Opentelemetry.Proto.Common.V1; using OtlpResource = Opentelemetry.Proto.Resource.V1; @@ -65,6 +64,11 @@ internal OtlpExporter(OtlpExporterOptions options, OtlpCollector.TraceService.IT /// public override ExportResult Export(in Batch activityBatch) { + if (this.ProcessResource == null) + { + this.SetResource(this.ParentProvider.GetResource()); + } + OtlpCollector.ExportTraceServiceRequest request = new OtlpCollector.ExportTraceServiceRequest(); request.AddBatch(this.ProcessResource, activityBatch); @@ -128,11 +132,5 @@ protected override bool OnShutdown(int timeoutMilliseconds) return Task.WaitAny(new Task[] { this.channel.ShutdownAsync(), Task.Delay(timeoutMilliseconds) }) == 0; } - - /// - protected override void OnParentProviderSet() - { - this.SetResource(this.ParentProvider.GetResource()); - } } } diff --git a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs index f3b2654ae27..4c878af9b90 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs @@ -31,7 +31,6 @@ using System.Threading.Tasks; using OpenTelemetry.Exporter.Zipkin.Implementation; using OpenTelemetry.Resources; -using OpenTelemetry.Trace; namespace OpenTelemetry.Exporter.Zipkin { @@ -65,6 +64,11 @@ internal ZipkinExporter(ZipkinExporterOptions options, HttpClient client = null) /// public override ExportResult Export(in Batch batch) { + if (this.LocalEndpoint == null) + { + this.SetResource(this.ParentProvider.GetResource()); + } + // Prevent Zipkin's HTTP operations from being instrumented. using var scope = SuppressInstrumentationScope.Begin(); @@ -150,12 +154,6 @@ internal void SetResource(Resource resource) tags); } - /// - protected override void OnParentProviderSet() - { - this.SetResource(this.ParentProvider.GetResource()); - } - private static string ResolveHostAddress(string hostName, AddressFamily family) { string result = null; diff --git a/src/OpenTelemetry/.publicApi/net452/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net452/PublicAPI.Unshipped.txt index 466657116cb..9161a0e61ec 100644 --- a/src/OpenTelemetry/.publicApi/net452/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/net452/PublicAPI.Unshipped.txt @@ -178,7 +178,6 @@ const OpenTelemetry.Resources.Resource.ServiceNameKey = "service.name" -> string const OpenTelemetry.Resources.Resource.ServiceNamespaceKey = "service.namespace" -> string const OpenTelemetry.Resources.Resource.ServiceVersionKey = "service.version" -> string override OpenTelemetry.BaseExportProcessor.Dispose(bool disposing) -> void -override OpenTelemetry.BaseExportProcessor.OnParentProviderSet() -> void override OpenTelemetry.BaseExportProcessor.OnShutdown(int timeoutMilliseconds) -> bool override OpenTelemetry.BatchExportProcessor.OnEnd(T data) -> void override OpenTelemetry.BatchExportProcessor.OnForceFlush(int timeoutMilliseconds) -> bool @@ -238,12 +237,10 @@ static OpenTelemetry.Trace.SamplingResult.operator !=(OpenTelemetry.Trace.Sampli static OpenTelemetry.Trace.SamplingResult.operator ==(OpenTelemetry.Trace.SamplingResult decision1, OpenTelemetry.Trace.SamplingResult decision2) -> bool static OpenTelemetry.Trace.TracerProviderExtensions.AddProcessor(this OpenTelemetry.Trace.TracerProvider provider, OpenTelemetry.BaseProcessor processor) -> OpenTelemetry.Trace.TracerProvider virtual OpenTelemetry.BaseExporter.Dispose(bool disposing) -> void -virtual OpenTelemetry.BaseExporter.OnParentProviderSet() -> void virtual OpenTelemetry.BaseExporter.OnShutdown(int timeoutMilliseconds) -> bool virtual OpenTelemetry.BaseProcessor.Dispose(bool disposing) -> void virtual OpenTelemetry.BaseProcessor.OnEnd(T data) -> void virtual OpenTelemetry.BaseProcessor.OnForceFlush(int timeoutMilliseconds) -> bool -virtual OpenTelemetry.BaseProcessor.OnParentProviderSet() -> void virtual OpenTelemetry.BaseProcessor.OnShutdown(int timeoutMilliseconds) -> bool virtual OpenTelemetry.BaseProcessor.OnStart(T data) -> void virtual OpenTelemetry.Metrics.Aggregators.Aggregator.Checkpoint() -> void diff --git a/src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt index 466657116cb..9161a0e61ec 100644 --- a/src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt @@ -178,7 +178,6 @@ const OpenTelemetry.Resources.Resource.ServiceNameKey = "service.name" -> string const OpenTelemetry.Resources.Resource.ServiceNamespaceKey = "service.namespace" -> string const OpenTelemetry.Resources.Resource.ServiceVersionKey = "service.version" -> string override OpenTelemetry.BaseExportProcessor.Dispose(bool disposing) -> void -override OpenTelemetry.BaseExportProcessor.OnParentProviderSet() -> void override OpenTelemetry.BaseExportProcessor.OnShutdown(int timeoutMilliseconds) -> bool override OpenTelemetry.BatchExportProcessor.OnEnd(T data) -> void override OpenTelemetry.BatchExportProcessor.OnForceFlush(int timeoutMilliseconds) -> bool @@ -238,12 +237,10 @@ static OpenTelemetry.Trace.SamplingResult.operator !=(OpenTelemetry.Trace.Sampli static OpenTelemetry.Trace.SamplingResult.operator ==(OpenTelemetry.Trace.SamplingResult decision1, OpenTelemetry.Trace.SamplingResult decision2) -> bool static OpenTelemetry.Trace.TracerProviderExtensions.AddProcessor(this OpenTelemetry.Trace.TracerProvider provider, OpenTelemetry.BaseProcessor processor) -> OpenTelemetry.Trace.TracerProvider virtual OpenTelemetry.BaseExporter.Dispose(bool disposing) -> void -virtual OpenTelemetry.BaseExporter.OnParentProviderSet() -> void virtual OpenTelemetry.BaseExporter.OnShutdown(int timeoutMilliseconds) -> bool virtual OpenTelemetry.BaseProcessor.Dispose(bool disposing) -> void virtual OpenTelemetry.BaseProcessor.OnEnd(T data) -> void virtual OpenTelemetry.BaseProcessor.OnForceFlush(int timeoutMilliseconds) -> bool -virtual OpenTelemetry.BaseProcessor.OnParentProviderSet() -> void virtual OpenTelemetry.BaseProcessor.OnShutdown(int timeoutMilliseconds) -> bool virtual OpenTelemetry.BaseProcessor.OnStart(T data) -> void virtual OpenTelemetry.Metrics.Aggregators.Aggregator.Checkpoint() -> void diff --git a/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt index e79cf752955..028dee03d98 100644 --- a/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt @@ -197,7 +197,6 @@ const OpenTelemetry.Resources.Resource.ServiceNameKey = "service.name" -> string const OpenTelemetry.Resources.Resource.ServiceNamespaceKey = "service.namespace" -> string const OpenTelemetry.Resources.Resource.ServiceVersionKey = "service.version" -> string override OpenTelemetry.BaseExportProcessor.Dispose(bool disposing) -> void -override OpenTelemetry.BaseExportProcessor.OnParentProviderSet() -> void override OpenTelemetry.BaseExportProcessor.OnShutdown(int timeoutMilliseconds) -> bool override OpenTelemetry.BatchExportProcessor.OnEnd(T data) -> void override OpenTelemetry.BatchExportProcessor.OnForceFlush(int timeoutMilliseconds) -> bool @@ -258,12 +257,10 @@ static OpenTelemetry.Trace.SamplingResult.operator !=(OpenTelemetry.Trace.Sampli static OpenTelemetry.Trace.SamplingResult.operator ==(OpenTelemetry.Trace.SamplingResult decision1, OpenTelemetry.Trace.SamplingResult decision2) -> bool static OpenTelemetry.Trace.TracerProviderExtensions.AddProcessor(this OpenTelemetry.Trace.TracerProvider provider, OpenTelemetry.BaseProcessor processor) -> OpenTelemetry.Trace.TracerProvider virtual OpenTelemetry.BaseExporter.Dispose(bool disposing) -> void -virtual OpenTelemetry.BaseExporter.OnParentProviderSet() -> void virtual OpenTelemetry.BaseExporter.OnShutdown(int timeoutMilliseconds) -> bool virtual OpenTelemetry.BaseProcessor.Dispose(bool disposing) -> void virtual OpenTelemetry.BaseProcessor.OnEnd(T data) -> void virtual OpenTelemetry.BaseProcessor.OnForceFlush(int timeoutMilliseconds) -> bool -virtual OpenTelemetry.BaseProcessor.OnParentProviderSet() -> void virtual OpenTelemetry.BaseProcessor.OnShutdown(int timeoutMilliseconds) -> bool virtual OpenTelemetry.BaseProcessor.OnStart(T data) -> void virtual OpenTelemetry.Logs.OpenTelemetryLoggerProvider.Dispose(bool disposing) -> void diff --git a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index e79cf752955..028dee03d98 100644 --- a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -197,7 +197,6 @@ const OpenTelemetry.Resources.Resource.ServiceNameKey = "service.name" -> string const OpenTelemetry.Resources.Resource.ServiceNamespaceKey = "service.namespace" -> string const OpenTelemetry.Resources.Resource.ServiceVersionKey = "service.version" -> string override OpenTelemetry.BaseExportProcessor.Dispose(bool disposing) -> void -override OpenTelemetry.BaseExportProcessor.OnParentProviderSet() -> void override OpenTelemetry.BaseExportProcessor.OnShutdown(int timeoutMilliseconds) -> bool override OpenTelemetry.BatchExportProcessor.OnEnd(T data) -> void override OpenTelemetry.BatchExportProcessor.OnForceFlush(int timeoutMilliseconds) -> bool @@ -258,12 +257,10 @@ static OpenTelemetry.Trace.SamplingResult.operator !=(OpenTelemetry.Trace.Sampli static OpenTelemetry.Trace.SamplingResult.operator ==(OpenTelemetry.Trace.SamplingResult decision1, OpenTelemetry.Trace.SamplingResult decision2) -> bool static OpenTelemetry.Trace.TracerProviderExtensions.AddProcessor(this OpenTelemetry.Trace.TracerProvider provider, OpenTelemetry.BaseProcessor processor) -> OpenTelemetry.Trace.TracerProvider virtual OpenTelemetry.BaseExporter.Dispose(bool disposing) -> void -virtual OpenTelemetry.BaseExporter.OnParentProviderSet() -> void virtual OpenTelemetry.BaseExporter.OnShutdown(int timeoutMilliseconds) -> bool virtual OpenTelemetry.BaseProcessor.Dispose(bool disposing) -> void virtual OpenTelemetry.BaseProcessor.OnEnd(T data) -> void virtual OpenTelemetry.BaseProcessor.OnForceFlush(int timeoutMilliseconds) -> bool -virtual OpenTelemetry.BaseProcessor.OnParentProviderSet() -> void virtual OpenTelemetry.BaseProcessor.OnShutdown(int timeoutMilliseconds) -> bool virtual OpenTelemetry.BaseProcessor.OnStart(T data) -> void virtual OpenTelemetry.Logs.OpenTelemetryLoggerProvider.Dispose(bool disposing) -> void diff --git a/src/OpenTelemetry/BaseExportProcessor.cs b/src/OpenTelemetry/BaseExportProcessor.cs index e77fbf442e9..b7a1335cef5 100644 --- a/src/OpenTelemetry/BaseExportProcessor.cs +++ b/src/OpenTelemetry/BaseExportProcessor.cs @@ -46,10 +46,11 @@ public sealed override void OnStart(T data) /// public abstract override void OnEnd(T data); - /// - protected override void OnParentProviderSet() + internal override void SetParentProvider(BaseProvider parentProvider) { - this.exporter.ParentProvider = this.ParentProvider; + base.SetParentProvider(parentProvider); + + this.exporter.ParentProvider = parentProvider; } /// diff --git a/src/OpenTelemetry/BaseExporter.cs b/src/OpenTelemetry/BaseExporter.cs index 4e526a12329..9a281063225 100644 --- a/src/OpenTelemetry/BaseExporter.cs +++ b/src/OpenTelemetry/BaseExporter.cs @@ -44,20 +44,11 @@ public abstract class BaseExporter : IDisposable where T : class { private int shutdownCount; - private BaseProvider parentProvider; /// /// Gets the parent . /// - public BaseProvider ParentProvider - { - get => this.parentProvider; - internal set - { - this.parentProvider = value; - this.OnParentProviderSet(); - } - } + public BaseProvider ParentProvider { get; internal set; } /// /// Exports a batch of telemetry objects. @@ -146,12 +137,5 @@ protected virtual bool OnShutdown(int timeoutMilliseconds) protected virtual void Dispose(bool disposing) { } - - /// - /// Called when the parent is set. - /// - protected virtual void OnParentProviderSet() - { - } } } diff --git a/src/OpenTelemetry/BaseProcessor.cs b/src/OpenTelemetry/BaseProcessor.cs index 7b7b32c39d0..e8cf98ae0e3 100644 --- a/src/OpenTelemetry/BaseProcessor.cs +++ b/src/OpenTelemetry/BaseProcessor.cs @@ -27,20 +27,11 @@ namespace OpenTelemetry public abstract class BaseProcessor : IDisposable { private int shutdownCount; - private BaseProvider parentProvider; /// /// Gets the parent . /// - public BaseProvider ParentProvider - { - get => this.parentProvider; - internal set - { - this.parentProvider = value; - this.OnParentProviderSet(); - } - } + public BaseProvider ParentProvider { get; private set; } /// /// Called synchronously when a telemetry object is started. @@ -155,6 +146,11 @@ public void Dispose() GC.SuppressFinalize(this); } + internal virtual void SetParentProvider(BaseProvider parentProvider) + { + this.ParentProvider = parentProvider; + } + /// /// Called by ForceFlush. This function should block the current /// thread until flush completed, shutdown signaled or timed out. @@ -208,12 +204,5 @@ protected virtual bool OnShutdown(int timeoutMilliseconds) protected virtual void Dispose(bool disposing) { } - - /// - /// Called when the parent is set. - /// - protected virtual void OnParentProviderSet() - { - } } } diff --git a/src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs b/src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs index c1bd65b635d..3cb12e262d9 100644 --- a/src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs +++ b/src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs @@ -295,7 +295,7 @@ protected override void OnEventSourceCreated(EventSource eventSource) protected override void OnEventWritten(EventWrittenEventArgs e) { string message; - if ((e.Payload?.Count ?? 0) > 0) + if (e.Message != null && (e.Payload?.Count ?? 0) > 0) { message = string.Format(e.Message, e.Payload.ToArray()); } diff --git a/src/OpenTelemetry/Trace/TracerProviderSdk.cs b/src/OpenTelemetry/Trace/TracerProviderSdk.cs index e5432b7d456..4b940bfac48 100644 --- a/src/OpenTelemetry/Trace/TracerProviderSdk.cs +++ b/src/OpenTelemetry/Trace/TracerProviderSdk.cs @@ -46,7 +46,7 @@ internal TracerProviderSdk( foreach (var processor in processors) { - processor.ParentProvider = this; + processor.SetParentProvider(this); this.AddProcessor(processor); } diff --git a/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs b/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs index 5cfc65b2dfc..1ffb8e4b36b 100644 --- a/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs @@ -193,7 +193,7 @@ public void AspNetRequestsAreCollectedSuccessfully( if (HttpContext.Current.Request.Path == filter || filter == "{ThrowException}") { - // only SetTracerProvider/Shutdown/Dispose are called because request was filtered. + // only SetParentProvider/Shutdown/Dispose are called because request was filtered. Assert.Equal(3, activityProcessor.Invocations.Count); return; } @@ -202,7 +202,7 @@ public void AspNetRequestsAreCollectedSuccessfully( var currentActivity = Activity.Current; Activity span; - Assert.Equal(5, activityProcessor.Invocations.Count); // SetTracerProvider/OnStart/OnEnd/OnShutdown/Dispose called. + Assert.Equal(5, activityProcessor.Invocations.Count); // SetParentProvider/OnStart/OnEnd/OnShutdown/Dispose called. span = (Activity)activityProcessor.Invocations[2].Arguments[0]; Assert.Equal( diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs index 26625a0d582..368ca5171e3 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs @@ -98,7 +98,7 @@ public async Task SuccessfulTemplateControllerCallGeneratesASpan( } } - Assert.Equal(3, processor.Invocations.Count); // SetTracerProvider/Begin/End called + Assert.Equal(3, processor.Invocations.Count); // SetParentProvider/Begin/End called var activity = (Activity)processor.Invocations[2].Arguments[0]; Assert.Equal(ActivityKind.Server, activity.Kind); diff --git a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs index 5eccfd6fbcc..c2529f38d35 100644 --- a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs +++ b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs @@ -66,7 +66,7 @@ public void GrpcClientCallsAreCollectedSuccessfully(string baseAddress, bool sho var rs = client.SayHello(new HelloRequest()); } - Assert.Equal(5, processor.Invocations.Count); // SetTracerProvider/OnStart/OnEnd/OnShutdown/Dispose called. + Assert.Equal(5, processor.Invocations.Count); // SetParentProvider/OnStart/OnEnd/OnShutdown/Dispose called. var activity = (Activity)processor.Invocations[2].Arguments[0]; ValidateGrpcActivity(activity); @@ -128,7 +128,7 @@ public void GrpcAndHttpClientInstrumentationIsInvoked(bool shouldEnrich) var rs = client.SayHello(new HelloRequest()); } - Assert.Equal(7, processor.Invocations.Count); // SetTracerProvider + OnStart/OnEnd (gRPC) + OnStart/OnEnd (HTTP) + OnShutdown/Dispose called. + Assert.Equal(7, processor.Invocations.Count); // SetParentProvider + OnStart/OnEnd (gRPC) + OnStart/OnEnd (HTTP) + OnShutdown/Dispose called. var httpSpan = (Activity)processor.Invocations[3].Arguments[0]; var grpcSpan = (Activity)processor.Invocations[4].Arguments[0]; @@ -177,7 +177,7 @@ public void GrpcAndHttpClientInstrumentationWithSuppressInstrumentation(bool sho }); } - Assert.Equal(11, processor.Invocations.Count); // SetTracerProvider + OnStart/OnEnd (gRPC) * 4 + OnShutdown/Dispose called. + Assert.Equal(11, processor.Invocations.Count); // SetParentProvider + OnStart/OnEnd (gRPC) * 4 + OnShutdown/Dispose called. var grpcSpan1 = (Activity)processor.Invocations[2].Arguments[0]; var grpcSpan2 = (Activity)processor.Invocations[4].Arguments[0]; var grpcSpan3 = (Activity)processor.Invocations[6].Arguments[0]; diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.netcore31.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.netcore31.cs index 4bc6772124f..3b216bb91d3 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.netcore31.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.netcore31.cs @@ -106,7 +106,7 @@ public async Task HttpClientInstrumentationInjectsHeadersAsync(bool shouldEnrich await c.SendAsync(request); } - Assert.Equal(5, processor.Invocations.Count); // SetTracerProvider/OnStart/OnEnd/OnShutdown/Dispose called. + Assert.Equal(5, processor.Invocations.Count); // SetParentProvider/OnStart/OnEnd/OnShutdown/Dispose called. var activity = (Activity)processor.Invocations[2].Arguments[0]; Assert.Equal(ActivityKind.Client, activity.Kind); @@ -168,7 +168,7 @@ public async Task HttpClientInstrumentationInjectsHeadersAsync_CustomFormat(bool await c.SendAsync(request); } - Assert.Equal(5, processor.Invocations.Count); // SetTracerProvider/OnStart/OnEnd/OnShutdown/Dispose called. + Assert.Equal(5, processor.Invocations.Count); // SetParentProvider/OnStart/OnEnd/OnShutdown/Dispose called. var activity = (Activity)processor.Invocations[2].Arguments[0]; Assert.Equal(ActivityKind.Client, activity.Kind); @@ -232,7 +232,7 @@ public async Task HttpClientInstrumentationBacksOffIfAlreadyInstrumented() await c.SendAsync(request); } - Assert.Equal(3, processor.Invocations.Count); // SetTracerProvider/OnShutdown/Dispose called. + Assert.Equal(3, processor.Invocations.Count); // SetParentProvider/OnShutdown/Dispose called. } [Fact] @@ -249,7 +249,7 @@ public async void RequestNotCollectedWhenInstrumentationFilterApplied() await c.GetAsync(this.url); } - Assert.Equal(3, processor.Invocations.Count); // SetTracerProvider/OnShutdown/Dispose called. + Assert.Equal(3, processor.Invocations.Count); // SetParentProvider/OnShutdown/Dispose called. } [Fact] @@ -270,7 +270,7 @@ public async void RequestNotCollectedWhenInstrumentationFilterThrowsException() } } - Assert.Equal(3, processor.Invocations.Count); // SetTracerProvider/OnShutdown/Dispose called. + Assert.Equal(3, processor.Invocations.Count); // SetParentProvider/OnShutdown/Dispose called. } [Fact] @@ -323,7 +323,7 @@ public async Task HttpClientInstrumentationContextPropagation() await c.SendAsync(request); } - Assert.Equal(4, processor.Invocations.Count); // OnStart/OnEnd/OnShutdown/Dispose called. + Assert.Equal(5, processor.Invocations.Count); // SetParentProvider/OnStart/OnEnd/OnShutdown/Dispose called. var activity = (Activity)processor.Invocations[1].Arguments[0]; Assert.Equal(ActivityKind.Client, activity.Kind); diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs index 70e4a470b85..3309497fa3c 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.netcore31.cs @@ -90,7 +90,7 @@ public async Task HttpOutCallsAreCollectedSuccessfullyAsync(HttpTestData.HttpOut } } - Assert.Equal(5, processor.Invocations.Count); // SetTracerProvider/OnStart/OnEnd/OnShutdown/Dispose called. + Assert.Equal(5, processor.Invocations.Count); // SetParentProvider/OnStart/OnEnd/OnShutdown/Dispose called. var activity = (Activity)processor.Invocations[2].Arguments[0]; Assert.Equal(ActivityKind.Client, activity.Kind); diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.netfx.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.netfx.cs index 343184b2f63..a6c851f9c02 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.netfx.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.netfx.cs @@ -78,7 +78,7 @@ public async Task HttpWebRequestInstrumentationInjectsHeadersAsync() using var response = await request.GetResponseAsync(); - Assert.Equal(3, activityProcessor.Invocations.Count); // SetTracerProvider/Begin/End called + Assert.Equal(3, activityProcessor.Invocations.Count); // SetParentProvider/Begin/End called var activity = (Activity)activityProcessor.Invocations[2].Arguments[0]; Assert.Equal(parent.TraceId, activity.Context.TraceId); @@ -172,7 +172,7 @@ public async Task HttpWebRequestInstrumentationInjectsHeadersAsync_CustomFormat( using var response = await request.GetResponseAsync(); - Assert.Equal(3, activityProcessor.Invocations.Count); // SetTracerProvider/Begin/End called + Assert.Equal(3, activityProcessor.Invocations.Count); // SetParentProvider/Begin/End called var activity = (Activity)activityProcessor.Invocations[2].Arguments[0]; diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs index cc60106a5d4..744be8ca199 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.netfx.cs @@ -83,7 +83,7 @@ public void HttpOutCallsAreCollectedSuccessfully(HttpTestData.HttpOutTestCase tc tc.ResponseExpected = false; } - Assert.Equal(3, activityProcessor.Invocations.Count); // SetTracerProvider/Begin/End called + Assert.Equal(3, activityProcessor.Invocations.Count); // SetParentProvider/Begin/End called var activity = (Activity)activityProcessor.Invocations[2].Arguments[0]; ValidateHttpWebRequestActivity(activity); Assert.Equal(tc.SpanName, activity.DisplayName); diff --git a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs index 2327e2721b6..a5591da751d 100644 --- a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs +++ b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs @@ -117,7 +117,7 @@ public void SuccessfulCommandTest( { } - Assert.Equal(2, activityProcessor.Invocations.Count); + Assert.Equal(3, activityProcessor.Invocations.Count); var activity = (Activity)activityProcessor.Invocations[1].Arguments[0]; @@ -187,7 +187,7 @@ public void SqlClientCallsAreCollectedSuccessfully( afterExecuteEventData); } - Assert.Equal(5, processor.Invocations.Count); // SetTracerProvider/OnStart/OnEnd/OnShutdown/Dispose called. + Assert.Equal(5, processor.Invocations.Count); // SetParentProvider/OnStart/OnEnd/OnShutdown/Dispose called. VerifyActivityData( sqlCommand.CommandType, @@ -249,7 +249,7 @@ public void SqlClientErrorsAreCollectedSuccessfully(string beforeCommand, string commandErrorEventData); } - Assert.Equal(5, processor.Invocations.Count); // SetTracerProvider/OnStart/OnEnd/OnShutdown/Dispose called. + Assert.Equal(5, processor.Invocations.Count); // SetParentProvider/OnStart/OnEnd/OnShutdown/Dispose called. VerifyActivityData( sqlCommand.CommandType, diff --git a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs index 00baf867f75..ebdfbe9c9df 100644 --- a/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs +++ b/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests/StackExchangeRedisCallsInstrumentationTests.cs @@ -73,7 +73,7 @@ public void SuccessfulCommandTest(string value) // Disposing SDK should flush the Redis profiling session immediately. - Assert.Equal(6, activityProcessor.Invocations.Count); + Assert.Equal(7, activityProcessor.Invocations.Count); VerifyActivityData((Activity)activityProcessor.Invocations[1].Arguments[0], true, connection.GetEndPoints()[0]); VerifyActivityData((Activity)activityProcessor.Invocations[3].Arguments[0], false, connection.GetEndPoints()[0]); From 4b96ed9fb41d18513b781ace17a896287c0f8601 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Sat, 7 Nov 2020 16:46:14 -0800 Subject: [PATCH 09/12] Updated changelog. --- src/OpenTelemetry/CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/OpenTelemetry/CHANGELOG.md b/src/OpenTelemetry/CHANGELOG.md index b29c0a995b3..94a57e3c9c1 100644 --- a/src/OpenTelemetry/CHANGELOG.md +++ b/src/OpenTelemetry/CHANGELOG.md @@ -2,6 +2,15 @@ ## Unreleased +* Removed `GetResource` and `SetResource` `Activity` extension methods. Added + `GetResource` extension method on `BaseProvider` + ([#1463](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1463)) +* Added `ParentProvider` property on `BaseProcessor` and `BaseExporter` classes. + ([#1463](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1463)) +* `Resource` is no longer added to observed `Activity` objects as a + `CustomProperty`. + ([#1463](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1463)) + ## 0.8.0-beta.1 Released 2020-Nov-5 From d6a6c75d734d1ed064511ef9ee3c646ff3d708ae Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Sat, 7 Nov 2020 17:17:27 -0800 Subject: [PATCH 10/12] Test fixup. --- .github/workflows/dotnet-core-linux.yml | 12 ++++++------ .../GrpcTests.client.cs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/dotnet-core-linux.yml b/.github/workflows/dotnet-core-linux.yml index 8750d27d56f..3c75ebb072e 100644 --- a/.github/workflows/dotnet-core-linux.yml +++ b/.github/workflows/dotnet-core-linux.yml @@ -20,17 +20,17 @@ jobs: - name: Setup .NET Core 2.1 uses: actions/setup-dotnet@v1 with: - dotnet-version: 2.1.807 + dotnet-version: 2.1.811 - name: Setup .NET Core 3.1 uses: actions/setup-dotnet@v1 with: - dotnet-version: 3.1.301 + dotnet-version: 3.1.403 - # For linux, we have to apply a workaround to enable both dotnet versions at same time - - name: .net SxS - run: | - rsync -a ${DOTNET_ROOT/3.1.301/2.1.807}/* $DOTNET_ROOT/ + # For linux, we have to apply a workaround to enable both dotnet versions at same time + - name: .net SxS + run: | + rsync -a ${DOTNET_ROOT/3.1.403/2.1.811}/* $DOTNET_ROOT/ - name: Install dependencies run: dotnet restore diff --git a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs index c2529f38d35..4658f0c8a55 100644 --- a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs +++ b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs @@ -238,7 +238,7 @@ public void GrpcPropagatesContextWithSuppressInstrumentation() var rs = client.SayHello(new HelloRequest()); } - Assert.Equal(8, processor.Invocations.Count); // OnStart/OnEnd * 3 (parent + gRPC client and server) + OnShutdown/Dispose called. + Assert.Equal(9, processor.Invocations.Count); // SetParentProcessor/OnStart/OnEnd * 3 (parent + gRPC client and server) + OnShutdown/Dispose called. var serverActivity = (Activity)processor.Invocations[3].Arguments[0]; var clientActivity = (Activity)processor.Invocations[4].Arguments[0]; From d576536d256bc5e1eaa363b013d0a96b6ec5526f Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Sat, 7 Nov 2020 17:38:55 -0800 Subject: [PATCH 11/12] Test fixup. --- src/OpenTelemetry/Trace/TracerProviderExtensions.cs | 2 ++ .../GrpcTests.client.cs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry/Trace/TracerProviderExtensions.cs b/src/OpenTelemetry/Trace/TracerProviderExtensions.cs index f503cb59f97..44950f90a27 100644 --- a/src/OpenTelemetry/Trace/TracerProviderExtensions.cs +++ b/src/OpenTelemetry/Trace/TracerProviderExtensions.cs @@ -40,6 +40,8 @@ public static TracerProvider AddProcessor(this TracerProvider provider, BaseProc throw new ArgumentException($"{nameof(provider)} is not an instance of TracerProviderSdk"); } + processor.SetParentProvider(trait); + return trait.AddProcessor(processor); } } diff --git a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs index 4658f0c8a55..8becd4d9567 100644 --- a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs +++ b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs @@ -239,8 +239,8 @@ public void GrpcPropagatesContextWithSuppressInstrumentation() } Assert.Equal(9, processor.Invocations.Count); // SetParentProcessor/OnStart/OnEnd * 3 (parent + gRPC client and server) + OnShutdown/Dispose called. - var serverActivity = (Activity)processor.Invocations[3].Arguments[0]; - var clientActivity = (Activity)processor.Invocations[4].Arguments[0]; + var serverActivity = (Activity)processor.Invocations[4].Arguments[0]; + var clientActivity = (Activity)processor.Invocations[5].Arguments[0]; Assert.Equal($"greet.Greeter/SayHello", clientActivity.DisplayName); Assert.Equal($"/greet.Greeter/SayHello", serverActivity.DisplayName); From 17b2de477cb8798ca65e3ecbf2e27b714bbcd03e Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Sat, 7 Nov 2020 18:00:07 -0800 Subject: [PATCH 12/12] Cleanup. --- src/OpenTelemetry/Trace/TracerProviderExtensions.cs | 2 -- src/OpenTelemetry/Trace/TracerProviderSdk.cs | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/OpenTelemetry/Trace/TracerProviderExtensions.cs b/src/OpenTelemetry/Trace/TracerProviderExtensions.cs index 44950f90a27..f503cb59f97 100644 --- a/src/OpenTelemetry/Trace/TracerProviderExtensions.cs +++ b/src/OpenTelemetry/Trace/TracerProviderExtensions.cs @@ -40,8 +40,6 @@ public static TracerProvider AddProcessor(this TracerProvider provider, BaseProc throw new ArgumentException($"{nameof(provider)} is not an instance of TracerProviderSdk"); } - processor.SetParentProvider(trait); - return trait.AddProcessor(processor); } } diff --git a/src/OpenTelemetry/Trace/TracerProviderSdk.cs b/src/OpenTelemetry/Trace/TracerProviderSdk.cs index 4b940bfac48..044058a4276 100644 --- a/src/OpenTelemetry/Trace/TracerProviderSdk.cs +++ b/src/OpenTelemetry/Trace/TracerProviderSdk.cs @@ -46,8 +46,6 @@ internal TracerProviderSdk( foreach (var processor in processors) { - processor.SetParentProvider(this); - this.AddProcessor(processor); } @@ -174,6 +172,8 @@ internal TracerProviderSdk AddProcessor(BaseProcessor processor) throw new ArgumentNullException(nameof(processor)); } + processor.SetParentProvider(this); + if (this.processor == null) { this.processor = processor;