From f748caa0a3cf14f58d86120f6fb0d5ba634a1157 Mon Sep 17 00:00:00 2001 From: Austin Tan Date: Mon, 1 Feb 2021 14:36:51 -0800 Subject: [PATCH 01/16] Jaeger and API changes and ProviderMethod --- .../JaegerExporter.cs | 15 ++++----------- .../.publicApi/net452/PublicAPI.Unshipped.txt | 1 + .../.publicApi/net46/PublicAPI.Unshipped.txt | 1 + .../.publicApi/net461/PublicAPI.Unshipped.txt | 1 + .../netstandard2.0/PublicAPI.Unshipped.txt | 1 + src/OpenTelemetry/ProviderExtensions.cs | 10 ++++++++++ 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs index 3ac56273dab..2d0f3d9b8d5 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using System.Runtime.CompilerServices; using OpenTelemetry.Exporter.Jaeger.Implementation; using OpenTelemetry.Resources; @@ -28,8 +29,6 @@ namespace OpenTelemetry.Exporter.Jaeger { public class JaegerExporter : BaseExporter { - private const string DefaultServiceName = "OpenTelemetry Exporter"; - private readonly int maxPayloadSizeInBytes; private readonly TProtocolFactory protocolFactory; private readonly TTransport clientTransport; @@ -58,7 +57,8 @@ internal JaegerExporter(JaegerExporterOptions options, TTransport clientTranspor this.memoryTransport = new InMemoryTransport(16000); this.memoryProtocol = this.protocolFactory.GetProtocol(this.memoryTransport); - this.Process = new Process(DefaultServiceName, options.ProcessTags); + string serviceName = (string) this.ParentProvider.GetDefaultResource().Attributes.FirstOrDefault().Value; + this.Process = new Process(serviceName, options.ProcessTags); } internal Process Process { get; set; } @@ -128,16 +128,9 @@ internal void SetResourceAndInitializeBatch(Resource resource) process.Tags[key] = label.ToJaegerTag(); } - if (serviceName != null) - { - process.ServiceName = serviceNamespace != null - ? serviceNamespace + "." + serviceName - : serviceName; - } - if (string.IsNullOrEmpty(process.ServiceName)) { - process.ServiceName = DefaultServiceName; + process.ServiceName = (string) this.ParentProvider.GetDefaultResource().Attributes.FirstOrDefault().Value; } this.Process.Message = this.BuildThriftMessage(this.Process).ToArray(); diff --git a/src/OpenTelemetry/.publicApi/net452/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net452/PublicAPI.Unshipped.txt index bd352476ea3..6e396d697c7 100644 --- a/src/OpenTelemetry/.publicApi/net452/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/net452/PublicAPI.Unshipped.txt @@ -119,6 +119,7 @@ override OpenTelemetry.Trace.TraceIdRatioBasedSampler.ShouldSample(in OpenTeleme abstract OpenTelemetry.BaseExportProcessor.OnExport(T data) -> void override sealed OpenTelemetry.BaseExportProcessor.OnStart(T data) -> void readonly OpenTelemetry.BaseExportProcessor.exporter -> OpenTelemetry.BaseExporter +static OpenTelemetry.ProviderExtensions.GetDefaultResource(this OpenTelemetry.BaseProvider baseProvider) -> OpenTelemetry.Resources.Resource static OpenTelemetry.ProviderExtensions.GetResource(this OpenTelemetry.BaseProvider baseProvider) -> OpenTelemetry.Resources.Resource static OpenTelemetry.Resources.ResourceBuilderExtensions.AddEnvironmentVariableDetector(this OpenTelemetry.Resources.ResourceBuilder resourceBuilder) -> OpenTelemetry.Resources.ResourceBuilder static OpenTelemetry.Resources.Resource.Empty.get -> OpenTelemetry.Resources.Resource diff --git a/src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt index a2634179477..927eff8b5c7 100644 --- a/src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/net46/PublicAPI.Unshipped.txt @@ -119,6 +119,7 @@ override OpenTelemetry.Trace.TraceIdRatioBasedSampler.ShouldSample(in OpenTeleme abstract OpenTelemetry.BaseExportProcessor.OnExport(T data) -> void override sealed OpenTelemetry.BaseExportProcessor.OnStart(T data) -> void readonly OpenTelemetry.BaseExportProcessor.exporter -> OpenTelemetry.BaseExporter +static OpenTelemetry.ProviderExtensions.GetDefaultResource(this OpenTelemetry.BaseProvider baseProvider) -> OpenTelemetry.Resources.Resource static OpenTelemetry.ProviderExtensions.GetResource(this OpenTelemetry.BaseProvider baseProvider) -> OpenTelemetry.Resources.Resource static OpenTelemetry.Resources.ResourceBuilderExtensions.AddEnvironmentVariableDetector(this OpenTelemetry.Resources.ResourceBuilder resourceBuilder) -> OpenTelemetry.Resources.ResourceBuilder static OpenTelemetry.Resources.Resource.Empty.get -> OpenTelemetry.Resources.Resource diff --git a/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt index dc1710590b2..20a97782078 100644 --- a/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/net461/PublicAPI.Unshipped.txt @@ -143,6 +143,7 @@ abstract OpenTelemetry.BaseExportProcessor.OnExport(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.GetDefaultResource(this OpenTelemetry.BaseProvider baseProvider) -> OpenTelemetry.Resources.Resource static OpenTelemetry.ProviderExtensions.GetResource(this OpenTelemetry.BaseProvider baseProvider) -> OpenTelemetry.Resources.Resource static OpenTelemetry.Resources.ResourceBuilderExtensions.AddEnvironmentVariableDetector(this OpenTelemetry.Resources.ResourceBuilder resourceBuilder) -> OpenTelemetry.Resources.ResourceBuilder static OpenTelemetry.Resources.Resource.Empty.get -> OpenTelemetry.Resources.Resource diff --git a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index dc1710590b2..20a97782078 100644 --- a/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -143,6 +143,7 @@ abstract OpenTelemetry.BaseExportProcessor.OnExport(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.GetDefaultResource(this OpenTelemetry.BaseProvider baseProvider) -> OpenTelemetry.Resources.Resource static OpenTelemetry.ProviderExtensions.GetResource(this OpenTelemetry.BaseProvider baseProvider) -> OpenTelemetry.Resources.Resource static OpenTelemetry.Resources.ResourceBuilderExtensions.AddEnvironmentVariableDetector(this OpenTelemetry.Resources.ResourceBuilder resourceBuilder) -> OpenTelemetry.Resources.ResourceBuilder static OpenTelemetry.Resources.Resource.Empty.get -> OpenTelemetry.Resources.Resource diff --git a/src/OpenTelemetry/ProviderExtensions.cs b/src/OpenTelemetry/ProviderExtensions.cs index c5b231c321a..4f792c151af 100644 --- a/src/OpenTelemetry/ProviderExtensions.cs +++ b/src/OpenTelemetry/ProviderExtensions.cs @@ -38,5 +38,15 @@ public static Resource GetResource(this BaseProvider baseProvider) return Resource.Empty; } + + /// + /// Gets the associated with the . + /// + /// . + /// if found otherwise . + public static Resource GetDefaultResource(this BaseProvider baseProvider) + { + return ResourceBuilder.CreateDefault().Build(); + } } } From c606aad5949ff09ac3f8a4579e177dc6cce521f5 Mon Sep 17 00:00:00 2001 From: Austin Tan Date: Mon, 1 Feb 2021 14:42:42 -0800 Subject: [PATCH 02/16] Changelog --- src/OpenTelemetry/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/OpenTelemetry/CHANGELOG.md b/src/OpenTelemetry/CHANGELOG.md index 5930d1418f6..87f0f0da471 100644 --- a/src/OpenTelemetry/CHANGELOG.md +++ b/src/OpenTelemetry/CHANGELOG.md @@ -4,6 +4,9 @@ * Default `Resource` will now contain service.name instead of Telemetry SDK. [#1744](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1744) +* Exporters fall back to the default `Resource`'s `service.name` value instead + of their own presets. Providers extended to access the default `Resource`. + [#1768](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1768) ## 1.0.0-rc2 From 1908b14a56040c3cb5e080d361bb0497814e0573 Mon Sep 17 00:00:00 2001 From: Austin Tan Date: Mon, 1 Feb 2021 14:47:13 -0800 Subject: [PATCH 03/16] Fix whitespace --- src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs index 2d0f3d9b8d5..fe4fa127fc0 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs @@ -57,7 +57,7 @@ internal JaegerExporter(JaegerExporterOptions options, TTransport clientTranspor this.memoryTransport = new InMemoryTransport(16000); this.memoryProtocol = this.protocolFactory.GetProtocol(this.memoryTransport); - string serviceName = (string) this.ParentProvider.GetDefaultResource().Attributes.FirstOrDefault().Value; + string serviceName = (string)this.ParentProvider.GetDefaultResource().Attributes.FirstOrDefault().Value; this.Process = new Process(serviceName, options.ProcessTags); } @@ -130,7 +130,7 @@ internal void SetResourceAndInitializeBatch(Resource resource) if (string.IsNullOrEmpty(process.ServiceName)) { - process.ServiceName = (string) this.ParentProvider.GetDefaultResource().Attributes.FirstOrDefault().Value; + process.ServiceName = (string)this.ParentProvider.GetDefaultResource().Attributes.FirstOrDefault().Value; } this.Process.Message = this.BuildThriftMessage(this.Process).ToArray(); From 2dc5b831213b704d278b8243921c6314c5b527a9 Mon Sep 17 00:00:00 2001 From: Austin Tan Date: Mon, 1 Feb 2021 15:00:57 -0800 Subject: [PATCH 04/16] Not just checking first element of default resource but querying for servicename --- src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs index fe4fa127fc0..00acf54b065 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs @@ -57,7 +57,8 @@ internal JaegerExporter(JaegerExporterOptions options, TTransport clientTranspor this.memoryTransport = new InMemoryTransport(16000); this.memoryProtocol = this.protocolFactory.GetProtocol(this.memoryTransport); - string serviceName = (string)this.ParentProvider.GetDefaultResource().Attributes.FirstOrDefault().Value; + string serviceName = (string)this.ParentProvider.GetDefaultResource().Attributes.Where( + pair => pair.Key == ResourceSemanticConventions.AttributeServiceName).FirstOrDefault().Value; this.Process = new Process(serviceName, options.ProcessTags); } @@ -130,7 +131,8 @@ internal void SetResourceAndInitializeBatch(Resource resource) if (string.IsNullOrEmpty(process.ServiceName)) { - process.ServiceName = (string)this.ParentProvider.GetDefaultResource().Attributes.FirstOrDefault().Value; + process.ServiceName = (string)this.ParentProvider.GetDefaultResource().Attributes.Where( + pair => pair.Key == ResourceSemanticConventions.AttributeServiceName).FirstOrDefault().Value; } this.Process.Message = this.BuildThriftMessage(this.Process).ToArray(); From a130385e619f1afb8a5294dab10a5c8d4722282a Mon Sep 17 00:00:00 2001 From: Austin Tan Date: Mon, 1 Feb 2021 15:09:26 -0800 Subject: [PATCH 05/16] Including the servicename fallback in Zipkin options --- src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs index 884e4ebaa2c..a46583c8889 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs @@ -16,6 +16,8 @@ using System; using System.Diagnostics; +using System.Linq; +using OpenTelemetry.Resources; namespace OpenTelemetry.Exporter.Zipkin { @@ -34,7 +36,9 @@ public sealed class ZipkinExporterOptions /// Gets or sets the name of the service reporting telemetry. If the `Resource` associated with the telemetry /// has "service.name" defined, then it'll be preferred over this option. /// - public string ServiceName { get; set; } = DefaultServiceName; + public string ServiceName { get; set; } = + (string)ResourceBuilder.CreateDefault().Build().Attributes + .Where(pair => pair.Key == ResourceSemanticConventions.AttributeServiceName).FirstOrDefault().Value; /// /// Gets or sets Zipkin endpoint address. See https://zipkin.io/zipkin-api/#/default/post_spans. From 9f659f8e18752b4dde640a9247da4e8a8058dec5 Mon Sep 17 00:00:00 2001 From: Austin Tan Date: Mon, 1 Feb 2021 15:30:53 -0800 Subject: [PATCH 06/16] Resolving tests --- src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs | 2 -- .../JaegerExporterTests.cs | 2 -- .../ZipkinExporterTests.cs | 7 ++++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs index a46583c8889..8aa444a3498 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs @@ -26,8 +26,6 @@ namespace OpenTelemetry.Exporter.Zipkin /// public sealed class ZipkinExporterOptions { - internal const string DefaultServiceName = "OpenTelemetry Exporter"; - #if !NET452 internal const int DefaultMaxPayloadSizeInBytes = 4096; #endif diff --git a/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterTests.cs b/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterTests.cs index 9fbb44f3510..24bef4f7696 100644 --- a/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterTests.cs @@ -28,8 +28,6 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests { public class JaegerExporterTests { - private const string DefaultServiceName = "OpenTelemetry Exporter"; - [Fact] public void JaegerExporter_BadArgs() { diff --git a/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs b/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs index 24e5bb99f6e..33d015a3842 100644 --- a/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs @@ -171,8 +171,9 @@ public void IntegrationTest( UseShortTraceIds = useShortTraceIds, }); - var serviceName = ZipkinExporterOptions.DefaultServiceName; - var resoureTags = string.Empty; + var serviceName = (string)exporter.ParentProvider.GetDefaultResource().Attributes + .Where(pair => pair.Key == ResourceSemanticConventions.AttributeServiceName).FirstOrDefault().Value; + var resourceTags = string.Empty; var activity = CreateTestActivity(isRootSpan: isRootSpan, status: status); if (useTestResource) { @@ -237,7 +238,7 @@ public void IntegrationTest( } Assert.Equal( - $@"[{{""traceId"":""{traceId}"",""name"":""Name"",{parentId}""id"":""{ZipkinActivityConversionExtensions.EncodeSpanId(context.SpanId)}"",""kind"":""CLIENT"",""timestamp"":{timestamp},""duration"":60000000,""localEndpoint"":{{""serviceName"":""{serviceName}""{ipInformation}}},""remoteEndpoint"":{{""serviceName"":""http://localhost:44312/""}},""annotations"":[{{""timestamp"":{eventTimestamp},""value"":""Event1""}},{{""timestamp"":{eventTimestamp},""value"":""Event2""}}],""tags"":{{{resoureTags}""stringKey"":""value"",""longKey"":""1"",""longKey2"":""1"",""doubleKey"":""1"",""doubleKey2"":""1"",""longArrayKey"":""1,2"",""boolKey"":""true"",""boolArrayKey"":""true,false"",""http.host"":""http://localhost:44312/"",{statusTag}""otel.library.name"":""CreateTestActivity"",""peer.service"":""http://localhost:44312/""{errorTag}}}}}]", + $@"[{{""traceId"":""{traceId}"",""name"":""Name"",{parentId}""id"":""{ZipkinActivityConversionExtensions.EncodeSpanId(context.SpanId)}"",""kind"":""CLIENT"",""timestamp"":{timestamp},""duration"":60000000,""localEndpoint"":{{""serviceName"":""{serviceName}""{ipInformation}}},""remoteEndpoint"":{{""serviceName"":""http://localhost:44312/""}},""annotations"":[{{""timestamp"":{eventTimestamp},""value"":""Event1""}},{{""timestamp"":{eventTimestamp},""value"":""Event2""}}],""tags"":{{{resourceTags}""stringKey"":""value"",""longKey"":""1"",""longKey2"":""1"",""doubleKey"":""1"",""doubleKey2"":""1"",""longArrayKey"":""1,2"",""boolKey"":""true"",""boolArrayKey"":""true,false"",""http.host"":""http://localhost:44312/"",{statusTag}""otel.library.name"":""CreateTestActivity"",""peer.service"":""http://localhost:44312/""{errorTag}}}}}]", Responses[requestId]); } From 9e1411558b62916611850d873247c454d7ad9ad8 Mon Sep 17 00:00:00 2001 From: Austin Tan Date: Mon, 1 Feb 2021 15:48:33 -0800 Subject: [PATCH 07/16] we previously removed the adapting of new servicenames from resources in jaeger, this undoes that --- src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs index 00acf54b065..604a1610570 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs @@ -129,6 +129,13 @@ internal void SetResourceAndInitializeBatch(Resource resource) process.Tags[key] = label.ToJaegerTag(); } + if (serviceName != null) + { + process.ServiceName = serviceNamespace != null + ? serviceNamespace + "." + serviceName + : serviceName; + } + if (string.IsNullOrEmpty(process.ServiceName)) { process.ServiceName = (string)this.ParentProvider.GetDefaultResource().Attributes.Where( From 65ea610d3cfac4ac047adbfdb2a11e3a7f26cf3a Mon Sep 17 00:00:00 2001 From: Austin Tan Date: Mon, 1 Feb 2021 16:28:40 -0800 Subject: [PATCH 08/16] Removing servicename from Jaeger ctor --- src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs index 604a1610570..d940592469e 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs @@ -56,9 +56,6 @@ internal JaegerExporter(JaegerExporterOptions options, TTransport clientTranspor this.thriftClient = new JaegerThriftClient(this.protocolFactory.GetProtocol(this.clientTransport)); this.memoryTransport = new InMemoryTransport(16000); this.memoryProtocol = this.protocolFactory.GetProtocol(this.memoryTransport); - - string serviceName = (string)this.ParentProvider.GetDefaultResource().Attributes.Where( - pair => pair.Key == ResourceSemanticConventions.AttributeServiceName).FirstOrDefault().Value; this.Process = new Process(serviceName, options.ProcessTags); } From d3228c582f80ed271c633caa9b88fd44c776955b Mon Sep 17 00:00:00 2001 From: Austin Tan Date: Mon, 1 Feb 2021 16:40:00 -0800 Subject: [PATCH 09/16] re-adding servicename to Ctor for Jaeger --- src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs index d940592469e..ef11bd90265 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs @@ -56,6 +56,9 @@ internal JaegerExporter(JaegerExporterOptions options, TTransport clientTranspor this.thriftClient = new JaegerThriftClient(this.protocolFactory.GetProtocol(this.clientTransport)); this.memoryTransport = new InMemoryTransport(16000); this.memoryProtocol = this.protocolFactory.GetProtocol(this.memoryTransport); + + string serviceName = (string)this.ParentProvider.GetDefaultResource().Attributes.Where( + pair => pair.Key == ResourceSemanticConventions.AttributeServiceName).FirstOrDefault().Value; this.Process = new Process(serviceName, options.ProcessTags); } From 1dd9529316412ee53808cd888ed82c0ae96a986b Mon Sep 17 00:00:00 2001 From: Austin Tan Date: Mon, 1 Feb 2021 20:17:39 -0800 Subject: [PATCH 10/16] CodeBlanch 's implementation for preserving servicename --- src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs index 4d25d376995..5954ac613b5 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs @@ -131,15 +131,14 @@ internal void SetResourceAndInitializeBatch(Resource resource) if (serviceName != null) { - process.ServiceName = serviceNamespace != null + serviceName = string.IsNullOrEmpty(serviceNamespace) ? serviceNamespace + "." + serviceName : serviceName; } - if (string.IsNullOrEmpty(process.ServiceName)) + if (!string.IsNullOrEmpty(serviceName)) { - process.ServiceName = (string)this.ParentProvider.GetDefaultResource().Attributes.Where( - pair => pair.Key == ResourceSemanticConventions.AttributeServiceName).FirstOrDefault().Value; + process.ServiceName = serviceName; } this.Process.Message = this.BuildThriftMessage(this.Process).ToArray(); From 4bc9b0dc69a3630a176a103ca55d1efa6ee4ea48 Mon Sep 17 00:00:00 2001 From: Austin Tan Date: Mon, 1 Feb 2021 20:35:07 -0800 Subject: [PATCH 11/16] Scrubbed ServiceName from ZipkinExporterOptions --- examples/MicroserviceExample/WebApi/Startup.cs | 1 - examples/MicroserviceExample/WorkerService/Program.cs | 1 - src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs | 4 +++- .../ZipkinExporterOptions.cs | 8 -------- .../ZipkinExporterTests.cs | 1 - 5 files changed, 3 insertions(+), 12 deletions(-) diff --git a/examples/MicroserviceExample/WebApi/Startup.cs b/examples/MicroserviceExample/WebApi/Startup.cs index e1b9ef775d6..a7664f00ccf 100644 --- a/examples/MicroserviceExample/WebApi/Startup.cs +++ b/examples/MicroserviceExample/WebApi/Startup.cs @@ -46,7 +46,6 @@ public void ConfigureServices(IServiceCollection services) .AddZipkinExporter(b => { var zipkinHostName = Environment.GetEnvironmentVariable("ZIPKIN_HOSTNAME") ?? "localhost"; - b.ServiceName = nameof(WebApi); b.Endpoint = new Uri($"http://{zipkinHostName}:9411/api/v2/spans"); })); } diff --git a/examples/MicroserviceExample/WorkerService/Program.cs b/examples/MicroserviceExample/WorkerService/Program.cs index a891b6f8b49..d037e727cfb 100644 --- a/examples/MicroserviceExample/WorkerService/Program.cs +++ b/examples/MicroserviceExample/WorkerService/Program.cs @@ -44,7 +44,6 @@ public static IHostBuilder CreateHostBuilder(string[] args) => .AddZipkinExporter(b => { var zipkinHostName = Environment.GetEnvironmentVariable("ZIPKIN_HOSTNAME") ?? "localhost"; - b.ServiceName = nameof(WorkerService); b.Endpoint = new Uri($"http://{zipkinHostName}:9411/api/v2/spans"); }); }); diff --git a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs index 55a67d3a03c..51ab87a1f29 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs @@ -31,6 +31,7 @@ using System.Threading.Tasks; using OpenTelemetry.Exporter.Zipkin.Implementation; using OpenTelemetry.Resources; +using System.Linq; namespace OpenTelemetry.Exporter { @@ -119,7 +120,8 @@ internal void SetLocalEndpointFromResource(Resource resource) if (string.IsNullOrEmpty(serviceName)) { - serviceName = this.options.ServiceName; + serviceName = (string)this.ParentProvider.GetDefaultResource().Attributes.Where( + pair => pair.Key == ResourceSemanticConventions.AttributeServiceName).FirstOrDefault().Value; } this.LocalEndpoint = new ZipkinEndpoint( diff --git a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs index e58e0bc4898..57985dec1d9 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporterOptions.cs @@ -30,14 +30,6 @@ public sealed class ZipkinExporterOptions internal const int DefaultMaxPayloadSizeInBytes = 4096; #endif - /// - /// Gets or sets the name of the service reporting telemetry. If the `Resource` associated with the telemetry - /// has "service.name" defined, then it'll be preferred over this option. - /// - public string ServiceName { get; set; } = - (string)ResourceBuilder.CreateDefault().Build().Attributes - .Where(pair => pair.Key == ResourceSemanticConventions.AttributeServiceName).FirstOrDefault().Value; - /// /// Gets or sets Zipkin endpoint address. See https://zipkin.io/zipkin-api/#/default/post_spans. /// Typically https://zipkin-server-name:9411/api/v2/spans. diff --git a/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs b/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs index 33d015a3842..47829b712b1 100644 --- a/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Zipkin.Tests/ZipkinExporterTests.cs @@ -105,7 +105,6 @@ public void SuppresssesInstrumentation() var exporterOptions = new ZipkinExporterOptions { - ServiceName = "test-zipkin", Endpoint = new Uri($"http://{this.testServerHost}:{this.testServerPort}/api/v2/spans?requestId={requestId}"), }; var zipkinExporter = new ZipkinExporter(exporterOptions); From d4e4dcd93853499409abe1992411bbef78175a78 Mon Sep 17 00:00:00 2001 From: Austin Tan Date: Mon, 1 Feb 2021 20:43:20 -0800 Subject: [PATCH 12/16] Messed up ternary operator order again --- src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs index 5954ac613b5..3ccd556e592 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs +++ b/src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs @@ -132,8 +132,8 @@ internal void SetResourceAndInitializeBatch(Resource resource) if (serviceName != null) { serviceName = string.IsNullOrEmpty(serviceNamespace) - ? serviceNamespace + "." + serviceName - : serviceName; + ? serviceName + : serviceNamespace + "." + serviceName; } if (!string.IsNullOrEmpty(serviceName)) From e6639bda07f7944abdb7d8d30ac565333b5ca068 Mon Sep 17 00:00:00 2001 From: Austin Tan Date: Mon, 1 Feb 2021 20:47:50 -0800 Subject: [PATCH 13/16] reordering using for SA compliance --- src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs index 51ab87a1f29..0205157694a 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs @@ -18,6 +18,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using System.Net; using System.Net.Http; using System.Net.Http.Headers; @@ -31,7 +32,6 @@ using System.Threading.Tasks; using OpenTelemetry.Exporter.Zipkin.Implementation; using OpenTelemetry.Resources; -using System.Linq; namespace OpenTelemetry.Exporter { From 5cbabac73c7529fd91fb24e52f34da6ddf1d3dca Mon Sep 17 00:00:00 2001 From: Austin Tan Date: Mon, 1 Feb 2021 20:56:33 -0800 Subject: [PATCH 14/16] more instances of zipkinoptions.servicename --- examples/AspNetCore/Startup.cs | 1 - examples/Console/TestRedis.cs | 1 - examples/Console/TestZipkinExporter.cs | 1 - examples/GrpcService/Startup.cs | 1 - 4 files changed, 4 deletions(-) diff --git a/examples/AspNetCore/Startup.cs b/examples/AspNetCore/Startup.cs index 9711826df8e..7a0e7876643 100644 --- a/examples/AspNetCore/Startup.cs +++ b/examples/AspNetCore/Startup.cs @@ -75,7 +75,6 @@ public void ConfigureServices(IServiceCollection services) .AddHttpClientInstrumentation() .AddZipkinExporter(zipkinOptions => { - zipkinOptions.ServiceName = this.Configuration.GetValue("Zipkin:ServiceName"); zipkinOptions.Endpoint = new Uri(this.Configuration.GetValue("Zipkin:Endpoint")); })); break; diff --git a/examples/Console/TestRedis.cs b/examples/Console/TestRedis.cs index 068f95bf1c4..745b077043c 100644 --- a/examples/Console/TestRedis.cs +++ b/examples/Console/TestRedis.cs @@ -45,7 +45,6 @@ internal static object Run(string zipkinUri) using var openTelemetry = Sdk.CreateTracerProviderBuilder() .AddZipkinExporter(o => { - o.ServiceName = "redis-test"; o.Endpoint = new Uri(zipkinUri); }) .AddRedisInstrumentation(connection, options => diff --git a/examples/Console/TestZipkinExporter.cs b/examples/Console/TestZipkinExporter.cs index d5e8f1617c0..25c63c07104 100644 --- a/examples/Console/TestZipkinExporter.cs +++ b/examples/Console/TestZipkinExporter.cs @@ -40,7 +40,6 @@ internal static object Run(string zipkinUri) .AddSource("Samples.SampleClient", "Samples.SampleServer") .AddZipkinExporter(o => { - o.ServiceName = "test-zipkin"; o.Endpoint = new Uri(zipkinUri); }) .Build(); diff --git a/examples/GrpcService/Startup.cs b/examples/GrpcService/Startup.cs index 40eb2e1bde1..427c665841e 100644 --- a/examples/GrpcService/Startup.cs +++ b/examples/GrpcService/Startup.cs @@ -59,7 +59,6 @@ public void ConfigureServices(IServiceCollection services) .AddAspNetCoreInstrumentation() .AddZipkinExporter(zipkinOptions => { - zipkinOptions.ServiceName = this.Configuration.GetValue("Zipkin:ServiceName"); zipkinOptions.Endpoint = new Uri(this.Configuration.GetValue("Zipkin:Endpoint")); })); break; From 20f21c1a66a4dde5ce6d9255b7bd80c5ed6588f7 Mon Sep 17 00:00:00 2001 From: Austin Tan Date: Mon, 1 Feb 2021 21:05:26 -0800 Subject: [PATCH 15/16] removed servicename from API --- .../.publicApi/net452/PublicAPI.Unshipped.txt | 2 -- .../.publicApi/net461/PublicAPI.Unshipped.txt | 2 -- .../.publicApi/netstandard2.0/PublicAPI.Unshipped.txt | 2 -- 3 files changed, 6 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Zipkin/.publicApi/net452/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Zipkin/.publicApi/net452/PublicAPI.Unshipped.txt index cc5e9e72e75..4ca16ec8bad 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/.publicApi/net452/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Zipkin/.publicApi/net452/PublicAPI.Unshipped.txt @@ -7,8 +7,6 @@ OpenTelemetry.Exporter.ZipkinExporterOptions.Endpoint.get -> System.Uri OpenTelemetry.Exporter.ZipkinExporterOptions.Endpoint.set -> void OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.set -> void -OpenTelemetry.Exporter.ZipkinExporterOptions.ServiceName.get -> string -OpenTelemetry.Exporter.ZipkinExporterOptions.ServiceName.set -> void OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.get -> bool OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.set -> void OpenTelemetry.Exporter.ZipkinExporterOptions.ZipkinExporterOptions() -> void diff --git a/src/OpenTelemetry.Exporter.Zipkin/.publicApi/net461/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Zipkin/.publicApi/net461/PublicAPI.Unshipped.txt index c2de59b6d4b..30a9861d7bb 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/.publicApi/net461/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Zipkin/.publicApi/net461/PublicAPI.Unshipped.txt @@ -9,8 +9,6 @@ OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.get -> OpenTele OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.set -> void OpenTelemetry.Exporter.ZipkinExporterOptions.MaxPayloadSizeInBytes.get -> int? OpenTelemetry.Exporter.ZipkinExporterOptions.MaxPayloadSizeInBytes.set -> void -OpenTelemetry.Exporter.ZipkinExporterOptions.ServiceName.get -> string -OpenTelemetry.Exporter.ZipkinExporterOptions.ServiceName.set -> void OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.get -> bool OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.set -> void OpenTelemetry.Exporter.ZipkinExporterOptions.ZipkinExporterOptions() -> void diff --git a/src/OpenTelemetry.Exporter.Zipkin/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Exporter.Zipkin/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index c2de59b6d4b..30a9861d7bb 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Exporter.Zipkin/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -9,8 +9,6 @@ OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.get -> OpenTele OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.set -> void OpenTelemetry.Exporter.ZipkinExporterOptions.MaxPayloadSizeInBytes.get -> int? OpenTelemetry.Exporter.ZipkinExporterOptions.MaxPayloadSizeInBytes.set -> void -OpenTelemetry.Exporter.ZipkinExporterOptions.ServiceName.get -> string -OpenTelemetry.Exporter.ZipkinExporterOptions.ServiceName.set -> void OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.get -> bool OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.set -> void OpenTelemetry.Exporter.ZipkinExporterOptions.ZipkinExporterOptions() -> void From 089d216e90aa1e031808994def2f1f765357f045 Mon Sep 17 00:00:00 2001 From: Austin Tan Date: Tue, 2 Feb 2021 10:40:30 -0800 Subject: [PATCH 16/16] Changelog in right places --- src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md | 3 +++ src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md | 4 ++++ src/OpenTelemetry/CHANGELOG.md | 3 +-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md b/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md index 322a954ee16..c0f775e4fe1 100644 --- a/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md @@ -5,6 +5,9 @@ * Moved `JaegerExporter` and `JaegerExporterOptions` classes to `OpenTelemetry.Exporter` namespace. ([#1770](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1770)) +* Default `service.name` complies with OTel spec. Grabs default from + `ParentProvider` using GetDefaultResource() APIfrom SDK if not found. + [#1768](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1768) ## 1.0.0-rc2 diff --git a/src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md b/src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md index e56edf4bb28..3aee8950918 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md @@ -5,6 +5,10 @@ * Moved `ZipkinExporter` and `ZipkinExporterOptions` classes to `OpenTelemetry.Exporter` namespace. ([#1770](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1770)) +* Removes ability to configure ServiceName for Zipkin. ServiceName must come + via Resource. If service name is not found in Resource, Zipkin uses + GetDefaultResource API from the SDK. + [#1768](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1768) ## 1.0.0-rc2 diff --git a/src/OpenTelemetry/CHANGELOG.md b/src/OpenTelemetry/CHANGELOG.md index 87f0f0da471..c35462bb27a 100644 --- a/src/OpenTelemetry/CHANGELOG.md +++ b/src/OpenTelemetry/CHANGELOG.md @@ -4,8 +4,7 @@ * Default `Resource` will now contain service.name instead of Telemetry SDK. [#1744](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1744) -* Exporters fall back to the default `Resource`'s `service.name` value instead - of their own presets. Providers extended to access the default `Resource`. +* Added GetDefaultResource() method to `Provider`. [#1768](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1768) ## 1.0.0-rc2