Rely on DefaultResource's Service.Name for Exporters (#1768)

* Jaeger and API changes and ProviderMethod

* Changelog

* Fix whitespace

* Not just checking first element of default resource but querying for servicename

* Including the servicename fallback in Zipkin options

* Resolving tests

* we previously removed the adapting of new servicenames from resources in jaeger, this undoes that

* Removing servicename from Jaeger ctor

* re-adding servicename to Ctor for Jaeger

* CodeBlanch 's implementation for preserving servicename

* Scrubbed ServiceName from ZipkinExporterOptions

* Messed up ternary operator order again

* reordering using for SA compliance

* more instances of zipkinoptions.servicename

* removed servicename from API

* Changelog in right places

Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
This commit is contained in:
Austin Tan 2021-02-02 11:04:54 -08:00 committed by GitHub
parent 7d8c403ec2
commit c14177996a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 41 additions and 35 deletions

View File

@ -75,7 +75,6 @@ namespace Examples.AspNetCore
.AddHttpClientInstrumentation() .AddHttpClientInstrumentation()
.AddZipkinExporter(zipkinOptions => .AddZipkinExporter(zipkinOptions =>
{ {
zipkinOptions.ServiceName = this.Configuration.GetValue<string>("Zipkin:ServiceName");
zipkinOptions.Endpoint = new Uri(this.Configuration.GetValue<string>("Zipkin:Endpoint")); zipkinOptions.Endpoint = new Uri(this.Configuration.GetValue<string>("Zipkin:Endpoint"));
})); }));
break; break;

View File

@ -45,7 +45,6 @@ namespace Examples.Console
using var openTelemetry = Sdk.CreateTracerProviderBuilder() using var openTelemetry = Sdk.CreateTracerProviderBuilder()
.AddZipkinExporter(o => .AddZipkinExporter(o =>
{ {
o.ServiceName = "redis-test";
o.Endpoint = new Uri(zipkinUri); o.Endpoint = new Uri(zipkinUri);
}) })
.AddRedisInstrumentation(connection, options => .AddRedisInstrumentation(connection, options =>

View File

@ -40,7 +40,6 @@ namespace Examples.Console
.AddSource("Samples.SampleClient", "Samples.SampleServer") .AddSource("Samples.SampleClient", "Samples.SampleServer")
.AddZipkinExporter(o => .AddZipkinExporter(o =>
{ {
o.ServiceName = "test-zipkin";
o.Endpoint = new Uri(zipkinUri); o.Endpoint = new Uri(zipkinUri);
}) })
.Build(); .Build();

View File

@ -59,7 +59,6 @@ namespace Examples.GrpcService
.AddAspNetCoreInstrumentation() .AddAspNetCoreInstrumentation()
.AddZipkinExporter(zipkinOptions => .AddZipkinExporter(zipkinOptions =>
{ {
zipkinOptions.ServiceName = this.Configuration.GetValue<string>("Zipkin:ServiceName");
zipkinOptions.Endpoint = new Uri(this.Configuration.GetValue<string>("Zipkin:Endpoint")); zipkinOptions.Endpoint = new Uri(this.Configuration.GetValue<string>("Zipkin:Endpoint"));
})); }));
break; break;

View File

@ -46,7 +46,6 @@ namespace WebApi
.AddZipkinExporter(b => .AddZipkinExporter(b =>
{ {
var zipkinHostName = Environment.GetEnvironmentVariable("ZIPKIN_HOSTNAME") ?? "localhost"; var zipkinHostName = Environment.GetEnvironmentVariable("ZIPKIN_HOSTNAME") ?? "localhost";
b.ServiceName = nameof(WebApi);
b.Endpoint = new Uri($"http://{zipkinHostName}:9411/api/v2/spans"); b.Endpoint = new Uri($"http://{zipkinHostName}:9411/api/v2/spans");
})); }));
} }

View File

@ -44,7 +44,6 @@ namespace WorkerService
.AddZipkinExporter(b => .AddZipkinExporter(b =>
{ {
var zipkinHostName = Environment.GetEnvironmentVariable("ZIPKIN_HOSTNAME") ?? "localhost"; var zipkinHostName = Environment.GetEnvironmentVariable("ZIPKIN_HOSTNAME") ?? "localhost";
b.ServiceName = nameof(WorkerService);
b.Endpoint = new Uri($"http://{zipkinHostName}:9411/api/v2/spans"); b.Endpoint = new Uri($"http://{zipkinHostName}:9411/api/v2/spans");
}); });
}); });

View File

@ -5,6 +5,9 @@
* Moved `JaegerExporter` and `JaegerExporterOptions` classes to * Moved `JaegerExporter` and `JaegerExporterOptions` classes to
`OpenTelemetry.Exporter` namespace. `OpenTelemetry.Exporter` namespace.
([#1770](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1770)) ([#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 ## 1.0.0-rc2

View File

@ -17,6 +17,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using OpenTelemetry.Exporter.Jaeger.Implementation; using OpenTelemetry.Exporter.Jaeger.Implementation;
using OpenTelemetry.Resources; using OpenTelemetry.Resources;
@ -28,8 +29,6 @@ namespace OpenTelemetry.Exporter
{ {
public class JaegerExporter : BaseExporter<Activity> public class JaegerExporter : BaseExporter<Activity>
{ {
private const string DefaultServiceName = "OpenTelemetry Exporter";
private readonly int maxPayloadSizeInBytes; private readonly int maxPayloadSizeInBytes;
private readonly TProtocolFactory protocolFactory; private readonly TProtocolFactory protocolFactory;
private readonly TTransport clientTransport; private readonly TTransport clientTransport;
@ -58,7 +57,9 @@ namespace OpenTelemetry.Exporter
this.memoryTransport = new InMemoryTransport(16000); this.memoryTransport = new InMemoryTransport(16000);
this.memoryProtocol = this.protocolFactory.GetProtocol(this.memoryTransport); this.memoryProtocol = this.protocolFactory.GetProtocol(this.memoryTransport);
this.Process = new Process(DefaultServiceName, options.ProcessTags); string serviceName = (string)this.ParentProvider.GetDefaultResource().Attributes.Where(
pair => pair.Key == ResourceSemanticConventions.AttributeServiceName).FirstOrDefault().Value;
this.Process = new Process(serviceName, options.ProcessTags);
} }
internal Process Process { get; set; } internal Process Process { get; set; }
@ -130,14 +131,14 @@ namespace OpenTelemetry.Exporter
if (serviceName != null) if (serviceName != null)
{ {
process.ServiceName = serviceNamespace != null serviceName = string.IsNullOrEmpty(serviceNamespace)
? serviceNamespace + "." + serviceName ? serviceName
: serviceName; : serviceNamespace + "." + serviceName;
} }
if (string.IsNullOrEmpty(process.ServiceName)) if (!string.IsNullOrEmpty(serviceName))
{ {
process.ServiceName = DefaultServiceName; process.ServiceName = serviceName;
} }
this.Process.Message = this.BuildThriftMessage(this.Process).ToArray(); this.Process.Message = this.BuildThriftMessage(this.Process).ToArray();

View File

@ -7,8 +7,6 @@ OpenTelemetry.Exporter.ZipkinExporterOptions.Endpoint.get -> System.Uri
OpenTelemetry.Exporter.ZipkinExporterOptions.Endpoint.set -> void OpenTelemetry.Exporter.ZipkinExporterOptions.Endpoint.set -> void
OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType
OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.set -> void 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.get -> bool
OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.set -> void OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.set -> void
OpenTelemetry.Exporter.ZipkinExporterOptions.ZipkinExporterOptions() -> void OpenTelemetry.Exporter.ZipkinExporterOptions.ZipkinExporterOptions() -> void

View File

@ -9,8 +9,6 @@ OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.get -> OpenTele
OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.set -> void OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.set -> void
OpenTelemetry.Exporter.ZipkinExporterOptions.MaxPayloadSizeInBytes.get -> int? OpenTelemetry.Exporter.ZipkinExporterOptions.MaxPayloadSizeInBytes.get -> int?
OpenTelemetry.Exporter.ZipkinExporterOptions.MaxPayloadSizeInBytes.set -> void 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.get -> bool
OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.set -> void OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.set -> void
OpenTelemetry.Exporter.ZipkinExporterOptions.ZipkinExporterOptions() -> void OpenTelemetry.Exporter.ZipkinExporterOptions.ZipkinExporterOptions() -> void

View File

@ -9,8 +9,6 @@ OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.get -> OpenTele
OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.set -> void OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.set -> void
OpenTelemetry.Exporter.ZipkinExporterOptions.MaxPayloadSizeInBytes.get -> int? OpenTelemetry.Exporter.ZipkinExporterOptions.MaxPayloadSizeInBytes.get -> int?
OpenTelemetry.Exporter.ZipkinExporterOptions.MaxPayloadSizeInBytes.set -> void 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.get -> bool
OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.set -> void OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.set -> void
OpenTelemetry.Exporter.ZipkinExporterOptions.ZipkinExporterOptions() -> void OpenTelemetry.Exporter.ZipkinExporterOptions.ZipkinExporterOptions() -> void

View File

@ -5,6 +5,10 @@
* Moved `ZipkinExporter` and `ZipkinExporterOptions` classes to * Moved `ZipkinExporter` and `ZipkinExporterOptions` classes to
`OpenTelemetry.Exporter` namespace. `OpenTelemetry.Exporter` namespace.
([#1770](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1770)) ([#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 ## 1.0.0-rc2

View File

@ -18,6 +18,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
@ -119,7 +120,8 @@ namespace OpenTelemetry.Exporter
if (string.IsNullOrEmpty(serviceName)) 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( this.LocalEndpoint = new ZipkinEndpoint(

View File

@ -16,6 +16,8 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using OpenTelemetry.Resources;
namespace OpenTelemetry.Exporter namespace OpenTelemetry.Exporter
{ {
@ -24,18 +26,10 @@ namespace OpenTelemetry.Exporter
/// </summary> /// </summary>
public sealed class ZipkinExporterOptions public sealed class ZipkinExporterOptions
{ {
internal const string DefaultServiceName = "OpenTelemetry Exporter";
#if !NET452 #if !NET452
internal const int DefaultMaxPayloadSizeInBytes = 4096; internal const int DefaultMaxPayloadSizeInBytes = 4096;
#endif #endif
/// <summary>
/// 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.
/// </summary>
public string ServiceName { get; set; } = DefaultServiceName;
/// <summary> /// <summary>
/// Gets or sets Zipkin endpoint address. See https://zipkin.io/zipkin-api/#/default/post_spans. /// Gets or sets Zipkin endpoint address. See https://zipkin.io/zipkin-api/#/default/post_spans.
/// Typically https://zipkin-server-name:9411/api/v2/spans. /// Typically https://zipkin-server-name:9411/api/v2/spans.

View File

@ -119,6 +119,7 @@ override OpenTelemetry.Trace.TraceIdRatioBasedSampler.ShouldSample(in OpenTeleme
abstract OpenTelemetry.BaseExportProcessor<T>.OnExport(T data) -> void abstract OpenTelemetry.BaseExportProcessor<T>.OnExport(T data) -> void
override sealed OpenTelemetry.BaseExportProcessor<T>.OnStart(T data) -> void override sealed OpenTelemetry.BaseExportProcessor<T>.OnStart(T data) -> void
readonly OpenTelemetry.BaseExportProcessor<T>.exporter -> OpenTelemetry.BaseExporter<T> readonly OpenTelemetry.BaseExportProcessor<T>.exporter -> OpenTelemetry.BaseExporter<T>
static OpenTelemetry.ProviderExtensions.GetDefaultResource(this OpenTelemetry.BaseProvider baseProvider) -> OpenTelemetry.Resources.Resource
static OpenTelemetry.ProviderExtensions.GetResource(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.ResourceBuilderExtensions.AddEnvironmentVariableDetector(this OpenTelemetry.Resources.ResourceBuilder resourceBuilder) -> OpenTelemetry.Resources.ResourceBuilder
static OpenTelemetry.Resources.Resource.Empty.get -> OpenTelemetry.Resources.Resource static OpenTelemetry.Resources.Resource.Empty.get -> OpenTelemetry.Resources.Resource

View File

@ -119,6 +119,7 @@ override OpenTelemetry.Trace.TraceIdRatioBasedSampler.ShouldSample(in OpenTeleme
abstract OpenTelemetry.BaseExportProcessor<T>.OnExport(T data) -> void abstract OpenTelemetry.BaseExportProcessor<T>.OnExport(T data) -> void
override sealed OpenTelemetry.BaseExportProcessor<T>.OnStart(T data) -> void override sealed OpenTelemetry.BaseExportProcessor<T>.OnStart(T data) -> void
readonly OpenTelemetry.BaseExportProcessor<T>.exporter -> OpenTelemetry.BaseExporter<T> readonly OpenTelemetry.BaseExportProcessor<T>.exporter -> OpenTelemetry.BaseExporter<T>
static OpenTelemetry.ProviderExtensions.GetDefaultResource(this OpenTelemetry.BaseProvider baseProvider) -> OpenTelemetry.Resources.Resource
static OpenTelemetry.ProviderExtensions.GetResource(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.ResourceBuilderExtensions.AddEnvironmentVariableDetector(this OpenTelemetry.Resources.ResourceBuilder resourceBuilder) -> OpenTelemetry.Resources.ResourceBuilder
static OpenTelemetry.Resources.Resource.Empty.get -> OpenTelemetry.Resources.Resource static OpenTelemetry.Resources.Resource.Empty.get -> OpenTelemetry.Resources.Resource

View File

@ -143,6 +143,7 @@ abstract OpenTelemetry.BaseExportProcessor<T>.OnExport(T data) -> void
override sealed OpenTelemetry.BaseExportProcessor<T>.OnStart(T data) -> void override sealed OpenTelemetry.BaseExportProcessor<T>.OnStart(T data) -> void
readonly OpenTelemetry.BaseExportProcessor<T>.exporter -> OpenTelemetry.BaseExporter<T> readonly OpenTelemetry.BaseExportProcessor<T>.exporter -> OpenTelemetry.BaseExporter<T>
static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder builder, System.Action<OpenTelemetry.Logs.OpenTelemetryLoggerOptions> configure = null) -> Microsoft.Extensions.Logging.ILoggingBuilder static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder builder, System.Action<OpenTelemetry.Logs.OpenTelemetryLoggerOptions> 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.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.ResourceBuilderExtensions.AddEnvironmentVariableDetector(this OpenTelemetry.Resources.ResourceBuilder resourceBuilder) -> OpenTelemetry.Resources.ResourceBuilder
static OpenTelemetry.Resources.Resource.Empty.get -> OpenTelemetry.Resources.Resource static OpenTelemetry.Resources.Resource.Empty.get -> OpenTelemetry.Resources.Resource

View File

@ -143,6 +143,7 @@ abstract OpenTelemetry.BaseExportProcessor<T>.OnExport(T data) -> void
override sealed OpenTelemetry.BaseExportProcessor<T>.OnStart(T data) -> void override sealed OpenTelemetry.BaseExportProcessor<T>.OnStart(T data) -> void
readonly OpenTelemetry.BaseExportProcessor<T>.exporter -> OpenTelemetry.BaseExporter<T> readonly OpenTelemetry.BaseExportProcessor<T>.exporter -> OpenTelemetry.BaseExporter<T>
static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder builder, System.Action<OpenTelemetry.Logs.OpenTelemetryLoggerOptions> configure = null) -> Microsoft.Extensions.Logging.ILoggingBuilder static Microsoft.Extensions.Logging.OpenTelemetryLoggingExtensions.AddOpenTelemetry(this Microsoft.Extensions.Logging.ILoggingBuilder builder, System.Action<OpenTelemetry.Logs.OpenTelemetryLoggerOptions> 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.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.ResourceBuilderExtensions.AddEnvironmentVariableDetector(this OpenTelemetry.Resources.ResourceBuilder resourceBuilder) -> OpenTelemetry.Resources.ResourceBuilder
static OpenTelemetry.Resources.Resource.Empty.get -> OpenTelemetry.Resources.Resource static OpenTelemetry.Resources.Resource.Empty.get -> OpenTelemetry.Resources.Resource

View File

@ -4,6 +4,8 @@
* Default `Resource` will now contain service.name instead of Telemetry SDK. * Default `Resource` will now contain service.name instead of Telemetry SDK.
[#1744](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1744) [#1744](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1744)
* Added GetDefaultResource() method to `Provider`.
[#1768](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1768)
## 1.0.0-rc2 ## 1.0.0-rc2

View File

@ -38,5 +38,15 @@ namespace OpenTelemetry
return Resource.Empty; return Resource.Empty;
} }
/// <summary>
/// Gets the <see cref="Resource"/> associated with the <see cref="BaseProvider"/>.
/// </summary>
/// <param name="baseProvider"><see cref="BaseProvider"/>.</param>
/// <returns><see cref="Resource"/>if found otherwise <see cref="Resource.Empty"/>.</returns>
public static Resource GetDefaultResource(this BaseProvider baseProvider)
{
return ResourceBuilder.CreateDefault().Build();
}
} }
} }

View File

@ -27,8 +27,6 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests
{ {
public class JaegerExporterTests public class JaegerExporterTests
{ {
private const string DefaultServiceName = "OpenTelemetry Exporter";
[Fact] [Fact]
public void JaegerExporter_BadArgs() public void JaegerExporter_BadArgs()
{ {

View File

@ -105,7 +105,6 @@ namespace OpenTelemetry.Exporter.Zipkin.Tests
var exporterOptions = new ZipkinExporterOptions var exporterOptions = new ZipkinExporterOptions
{ {
ServiceName = "test-zipkin",
Endpoint = new Uri($"http://{this.testServerHost}:{this.testServerPort}/api/v2/spans?requestId={requestId}"), Endpoint = new Uri($"http://{this.testServerHost}:{this.testServerPort}/api/v2/spans?requestId={requestId}"),
}; };
var zipkinExporter = new ZipkinExporter(exporterOptions); var zipkinExporter = new ZipkinExporter(exporterOptions);
@ -171,8 +170,9 @@ namespace OpenTelemetry.Exporter.Zipkin.Tests
UseShortTraceIds = useShortTraceIds, UseShortTraceIds = useShortTraceIds,
}); });
var serviceName = ZipkinExporterOptions.DefaultServiceName; var serviceName = (string)exporter.ParentProvider.GetDefaultResource().Attributes
var resoureTags = string.Empty; .Where(pair => pair.Key == ResourceSemanticConventions.AttributeServiceName).FirstOrDefault().Value;
var resourceTags = string.Empty;
var activity = CreateTestActivity(isRootSpan: isRootSpan, status: status); var activity = CreateTestActivity(isRootSpan: isRootSpan, status: status);
if (useTestResource) if (useTestResource)
{ {
@ -237,7 +237,7 @@ namespace OpenTelemetry.Exporter.Zipkin.Tests
} }
Assert.Equal( 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]); Responses[requestId]);
} }