diff --git a/.github/workflows/dotnet-core-linux.yml b/.github/workflows/dotnet-core-linux.yml index ca9d4a22270..ba128f31aeb 100644 --- a/.github/workflows/dotnet-core-linux.yml +++ b/.github/workflows/dotnet-core-linux.yml @@ -20,12 +20,12 @@ jobs: - name: Setup .NET Core 2.1 uses: actions/setup-dotnet@v1 with: - dotnet-version: 2.1.807 + dotnet-version: 2.1.x - name: Setup .NET Core 3.1 uses: actions/setup-dotnet@v1 with: - dotnet-version: 3.1.301 + dotnet-version: 3.1.x - name: Setup .NET 5 uses: actions/setup-dotnet@v1 diff --git a/build/Common.prod.props b/build/Common.prod.props index cff03f9845c..d089a05ee77 100644 --- a/build/Common.prod.props +++ b/build/Common.prod.props @@ -63,6 +63,8 @@ + + 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/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 413c44b29d6..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 { @@ -99,7 +98,7 @@ public override ExportResult Export(in Batch batch) } } - var resource = activity.GetResource(); + var resource = this.ParentProvider.GetResource(); if (resource != Resource.Empty) { this.WriteLine("Resource associated with Activity:"); diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs index 4f89a3e8e6b..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,13 +64,13 @@ public override ExportResult Export(in Batch activityBatch) { try { - foreach (var activity in activityBatch) + if (this.processCache == null) { - if (this.processCache == null) - { - this.ApplyLibraryResource(activity.GetResource()); - } + this.SetResource(this.ParentProvider.GetResource()); + } + foreach (var activity in activityBatch) + { this.AppendSpan(activity.ToJaegerSpan()); } @@ -87,18 +86,18 @@ public override ExportResult Export(in Batch activityBatch) } } - internal void ApplyLibraryResource(Resource libraryResource) + 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.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..68641b26da1 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs @@ -18,12 +18,10 @@ 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; 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; @@ -40,7 +38,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 +59,19 @@ internal OtlpExporter(OtlpExporterOptions options, OtlpCollector.TraceService.IT } } + internal OtlpResource.Resource ProcessResource { get; private set; } + /// 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, activityBatch); + request.AddBatch(this.ProcessResource, activityBatch); try { @@ -87,17 +91,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 +119,7 @@ internal OtlpResource.Resource EnsureProcessResource(Activity activity) }); } - return this.processResource = processResource; + this.ProcessResource = processResource; } /// diff --git a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs index 73ba3b283f3..4c878af9b90 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs @@ -27,12 +27,10 @@ #else using System.Text.Json; #endif -using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using OpenTelemetry.Exporter.Zipkin.Implementation; using OpenTelemetry.Resources; -using OpenTelemetry.Trace; namespace OpenTelemetry.Exporter.Zipkin { @@ -66,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(); @@ -92,14 +95,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 +110,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 +146,7 @@ internal ZipkinEndpoint EnsureLocalEndpoint(Activity activity) serviceName = this.options.ServiceName; } - return this.LocalEndpoint = new ZipkinEndpoint( + this.LocalEndpoint = new ZipkinEndpoint( serviceName, ipv4, ipv6, @@ -257,9 +254,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/src/OpenTelemetry/.publicApi/net452/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net452/PublicAPI.Unshipped.txt index 8fa6eec76fe..9161a0e61ec 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 @@ -222,6 +224,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,8 +233,6 @@ 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 diff --git a/src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt index 8fa6eec76fe..9161a0e61ec 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 @@ -222,6 +224,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,8 +233,6 @@ 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 diff --git a/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt index fcb0d703375..028dee03d98 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 @@ -242,6 +244,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,8 +253,6 @@ 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 diff --git a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index fcb0d703375..028dee03d98 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 @@ -242,6 +244,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,8 +253,6 @@ 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 diff --git a/src/OpenTelemetry/BaseExportProcessor.cs b/src/OpenTelemetry/BaseExportProcessor.cs index b9ed83bc4c3..b7a1335cef5 100644 --- a/src/OpenTelemetry/BaseExportProcessor.cs +++ b/src/OpenTelemetry/BaseExportProcessor.cs @@ -46,6 +46,13 @@ public sealed override void OnStart(T data) /// public abstract override void OnEnd(T data); + internal override void SetParentProvider(BaseProvider parentProvider) + { + base.SetParentProvider(parentProvider); + + this.exporter.ParentProvider = parentProvider; + } + /// protected override bool OnShutdown(int timeoutMilliseconds) { diff --git a/src/OpenTelemetry/BaseExporter.cs b/src/OpenTelemetry/BaseExporter.cs index 1b0d0c0c6d9..9a281063225 100644 --- a/src/OpenTelemetry/BaseExporter.cs +++ b/src/OpenTelemetry/BaseExporter.cs @@ -45,6 +45,11 @@ public abstract class BaseExporter : IDisposable { private int shutdownCount; + /// + /// Gets the parent . + /// + public BaseProvider ParentProvider { get; internal set; } + /// /// Exports a batch of telemetry objects. /// diff --git a/src/OpenTelemetry/BaseProcessor.cs b/src/OpenTelemetry/BaseProcessor.cs index 5e6b5a538fa..e8cf98ae0e3 100644 --- a/src/OpenTelemetry/BaseProcessor.cs +++ b/src/OpenTelemetry/BaseProcessor.cs @@ -28,6 +28,11 @@ public abstract class BaseProcessor : IDisposable { private int shutdownCount; + /// + /// Gets the parent . + /// + public BaseProvider ParentProvider { get; private set; } + /// /// Called synchronously when a telemetry object is started. /// @@ -141,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. 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 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/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/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 864570fa9d1..6e514d5f7e0 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 @@ internal 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/TracerProviderSdk.cs b/src/OpenTelemetry/Trace/TracerProviderSdk.cs index 87d3016c97e..044058a4276 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; @@ -42,7 +41,7 @@ internal TracerProviderSdk( Sampler sampler, List> processors) { - this.resource = resource; + this.Resource = resource; this.sampler = sampler; foreach (var processor in processors) @@ -52,7 +51,7 @@ internal TracerProviderSdk( if (diagnosticSourceInstrumentationFactories.Any()) { - this.adapter = new ActivitySourceAdapter(sampler, this.processor, resource); + this.adapter = new ActivitySourceAdapter(sampler, this.processor); foreach (var instrumentationFactory in diagnosticSourceInstrumentationFactories) { this.instrumentations.Add(instrumentationFactory.Factory(this.adapter)); @@ -81,7 +80,6 @@ internal TracerProviderSdk( if (SuppressInstrumentationScope.IncrementIfTriggered() == 0) { - activity.SetResource(this.resource); this.processor?.OnStart(activity); } }, @@ -165,6 +163,8 @@ internal TracerProviderSdk( this.listener = listener; } + internal Resource Resource { get; } + internal TracerProviderSdk AddProcessor(BaseProcessor processor) { if (processor == null) @@ -172,6 +172,8 @@ internal TracerProviderSdk AddProcessor(BaseProcessor processor) throw new ArgumentNullException(nameof(processor)); } + processor.SetParentProvider(this); + if (this.processor == null) { this.processor = processor; 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()); diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterTest.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterTest.cs index 52a9d934e4d..d70becc737b 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterTest.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterTest.cs @@ -70,23 +70,32 @@ 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"), + })); + } + else + { + exporter.SetResource(Resources.Resource.Empty); } + 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 +118,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..1ffb8e4b36b 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(); @@ -196,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 SetParentProvider/Shutdown/Dispose are called because request was filtered. + Assert.Equal(3, activityProcessor.Invocations.Count); return; } @@ -205,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); // SetParentProvider/OnStart/OnEnd/OnShutdown/Dispose called. + span = (Activity)activityProcessor.Invocations[2].Arguments[0]; Assert.Equal( carrierFormat == "TraceContext" || carrierFormat == "CustomContextMatchParent" @@ -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 35526ddadf9..9671b6cc357 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs @@ -84,11 +84,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)); @@ -101,7 +101,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) { @@ -113,7 +112,6 @@ void ConfigureTestServices(IServiceCollection services) options.Enrich = ActivityEnrichment; } }) - .SetResource(expectedResource) .AddProcessor(activityProcessor.Object) .Build(); } @@ -130,13 +128,13 @@ 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", expectedResource); + ValidateAspNetCoreActivity(activity, "/api/values"); } [Fact] @@ -167,11 +165,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 @@ -223,12 +221,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); @@ -273,12 +271,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); @@ -325,13 +323,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); @@ -356,11 +354,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.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs index a0ae5210417..cbfb66ea766 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs @@ -88,7 +88,7 @@ public async Task SuccessfulTemplateControllerCallGeneratesASpan( for (var i = 0; i < 10; i++) { - if (processor.Invocations.Count == 2) + if (processor.Invocations.Count == 3) { break; } @@ -100,8 +100,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); // SetParentProvider/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 dd6972a06cc..7c857cfdd8d 100644 --- a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs +++ b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs @@ -43,10 +43,10 @@ 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") + .SetIdFormat(ActivityIdFormat.W3C) .Start(); using (Sdk.CreateTracerProviderBuilder() @@ -58,7 +58,6 @@ public void GrpcClientCallsAreCollectedSuccessfully(string baseAddress, bool sho options.Enrich = ActivityEnrichment; } }) - .SetResource(expectedResource) .AddProcessor(processor.Object) .Build()) { @@ -67,10 +66,10 @@ 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); // SetParentProvider/OnStart/OnEnd/OnShutdown/Dispose called. + var activity = (Activity)processor.Invocations[2].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); @@ -94,7 +93,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)); @@ -107,7 +105,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") @@ -115,7 +112,6 @@ public void GrpcAndHttpClientInstrumentationIsInvoked(bool shouldEnrich) using (Sdk.CreateTracerProviderBuilder() .SetSampler(new AlwaysOnSampler()) - .SetResource(expectedResource) .AddGrpcClientInstrumentation(options => { if (shouldEnrich) @@ -141,11 +137,11 @@ 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); // 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]; - ValidateGrpcActivity(grpcSpan, expectedResource); + ValidateGrpcActivity(grpcSpan); Assert.Equal($"greet.Greeter/SayHello", grpcSpan.DisplayName); Assert.Equal($"HTTP POST", httpSpan.DisplayName); Assert.Equal(grpcSpan.SpanId, httpSpan.ParentSpanId); @@ -157,7 +153,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") @@ -165,7 +160,6 @@ public void GrpcAndHttpClientInstrumentationWithSuppressInstrumentation(bool sho using (Sdk.CreateTracerProviderBuilder() .SetSampler(new AlwaysOnSampler()) - .SetResource(expectedResource) .AddGrpcClientInstrumentation(o => { o.SuppressDownstreamInstrumentation = true; @@ -192,22 +186,22 @@ 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); // 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]; + var grpcSpan4 = (Activity)processor.Invocations[8].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); } @@ -253,9 +247,9 @@ 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. - var serverActivity = (Activity)processor.Invocations[3].Arguments[0]; - var clientActivity = (Activity)processor.Invocations[4].Arguments[0]; + Assert.Equal(9, processor.Invocations.Count); // SetParentProcessor/OnStart/OnEnd * 3 (parent + gRPC client and server) + OnShutdown/Dispose called. + 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); @@ -271,10 +265,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.Basic.netcore31.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.Basic.netcore31.cs index 0ad16f22899..3b216bb91d3 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); // SetParentProvider/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); // SetParentProvider/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); @@ -232,7 +232,7 @@ public async Task HttpClientInstrumentationBacksOffIfAlreadyInstrumented() await c.SendAsync(request); } - Assert.Equal(2, processor.Invocations.Count); // 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(2, processor.Invocations.Count); // OnShutdown/Dispose called. + Assert.Equal(3, processor.Invocations.Count); // SetParentProvider/OnShutdown/Dispose called. } [Fact] @@ -270,7 +270,7 @@ public async void RequestNotCollectedWhenInstrumentationFilterThrowsException() } } - Assert.Equal(2, processor.Invocations.Count); // OnShutdown/Dispose called. + Assert.Equal(3, processor.Invocations.Count); // SetParentProvider/OnShutdown/Dispose called. } [Fact] @@ -295,7 +295,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); } [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 2f75d8d6144..3309497fa3c 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 @@ -92,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); // SetParentProvider/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); @@ -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.Basic.netfx.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestTests.Basic.netfx.cs index f1bfcfbd172..a6c851f9c02 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); // SetParentProvider/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); // SetParentProvider/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 75dd01b7a3e..744be8ca199 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 => { @@ -86,9 +83,9 @@ 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]; - ValidateHttpWebRequestActivity(activity, expectedResource, tc.ResponseExpected); + 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); 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.Instrumentation.SqlClient.Tests/SqlClientTests.cs b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs index 8c08ffc1426..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(4, processor.Invocations.Count); // OnStart/OnEnd/OnShutdown/Dispose called. + Assert.Equal(5, processor.Invocations.Count); // SetParentProvider/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); // SetParentProvider/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( 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]); 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()); - } - } - } -}