Skip to content

Commit c141779

Browse files
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 <[email protected]>
1 parent 7d8c403 commit c141779

File tree

22 files changed

+41
-35
lines changed

22 files changed

+41
-35
lines changed

examples/AspNetCore/Startup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public void ConfigureServices(IServiceCollection services)
7575
.AddHttpClientInstrumentation()
7676
.AddZipkinExporter(zipkinOptions =>
7777
{
78-
zipkinOptions.ServiceName = this.Configuration.GetValue<string>("Zipkin:ServiceName");
7978
zipkinOptions.Endpoint = new Uri(this.Configuration.GetValue<string>("Zipkin:Endpoint"));
8079
}));
8180
break;

examples/Console/TestRedis.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ internal static object Run(string zipkinUri)
4545
using var openTelemetry = Sdk.CreateTracerProviderBuilder()
4646
.AddZipkinExporter(o =>
4747
{
48-
o.ServiceName = "redis-test";
4948
o.Endpoint = new Uri(zipkinUri);
5049
})
5150
.AddRedisInstrumentation(connection, options =>

examples/Console/TestZipkinExporter.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ internal static object Run(string zipkinUri)
4040
.AddSource("Samples.SampleClient", "Samples.SampleServer")
4141
.AddZipkinExporter(o =>
4242
{
43-
o.ServiceName = "test-zipkin";
4443
o.Endpoint = new Uri(zipkinUri);
4544
})
4645
.Build();

examples/GrpcService/Startup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public void ConfigureServices(IServiceCollection services)
5959
.AddAspNetCoreInstrumentation()
6060
.AddZipkinExporter(zipkinOptions =>
6161
{
62-
zipkinOptions.ServiceName = this.Configuration.GetValue<string>("Zipkin:ServiceName");
6362
zipkinOptions.Endpoint = new Uri(this.Configuration.GetValue<string>("Zipkin:Endpoint"));
6463
}));
6564
break;

examples/MicroserviceExample/WebApi/Startup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public void ConfigureServices(IServiceCollection services)
4646
.AddZipkinExporter(b =>
4747
{
4848
var zipkinHostName = Environment.GetEnvironmentVariable("ZIPKIN_HOSTNAME") ?? "localhost";
49-
b.ServiceName = nameof(WebApi);
5049
b.Endpoint = new Uri($"http://{zipkinHostName}:9411/api/v2/spans");
5150
}));
5251
}

examples/MicroserviceExample/WorkerService/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
4444
.AddZipkinExporter(b =>
4545
{
4646
var zipkinHostName = Environment.GetEnvironmentVariable("ZIPKIN_HOSTNAME") ?? "localhost";
47-
b.ServiceName = nameof(WorkerService);
4847
b.Endpoint = new Uri($"http://{zipkinHostName}:9411/api/v2/spans");
4948
});
5049
});

src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* Moved `JaegerExporter` and `JaegerExporterOptions` classes to
66
`OpenTelemetry.Exporter` namespace.
77
([#1770](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1770))
8+
* Default `service.name` complies with OTel spec. Grabs default from
9+
`ParentProvider` using GetDefaultResource() APIfrom SDK if not found.
10+
[#1768](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1768)
811

912
## 1.0.0-rc2
1013

src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System;
1818
using System.Collections.Generic;
1919
using System.Diagnostics;
20+
using System.Linq;
2021
using System.Runtime.CompilerServices;
2122
using OpenTelemetry.Exporter.Jaeger.Implementation;
2223
using OpenTelemetry.Resources;
@@ -28,8 +29,6 @@ namespace OpenTelemetry.Exporter
2829
{
2930
public class JaegerExporter : BaseExporter<Activity>
3031
{
31-
private const string DefaultServiceName = "OpenTelemetry Exporter";
32-
3332
private readonly int maxPayloadSizeInBytes;
3433
private readonly TProtocolFactory protocolFactory;
3534
private readonly TTransport clientTransport;
@@ -58,7 +57,9 @@ internal JaegerExporter(JaegerExporterOptions options, TTransport clientTranspor
5857
this.memoryTransport = new InMemoryTransport(16000);
5958
this.memoryProtocol = this.protocolFactory.GetProtocol(this.memoryTransport);
6059

61-
this.Process = new Process(DefaultServiceName, options.ProcessTags);
60+
string serviceName = (string)this.ParentProvider.GetDefaultResource().Attributes.Where(
61+
pair => pair.Key == ResourceSemanticConventions.AttributeServiceName).FirstOrDefault().Value;
62+
this.Process = new Process(serviceName, options.ProcessTags);
6263
}
6364

6465
internal Process Process { get; set; }
@@ -130,14 +131,14 @@ internal void SetResourceAndInitializeBatch(Resource resource)
130131

131132
if (serviceName != null)
132133
{
133-
process.ServiceName = serviceNamespace != null
134-
? serviceNamespace + "." + serviceName
135-
: serviceName;
134+
serviceName = string.IsNullOrEmpty(serviceNamespace)
135+
? serviceName
136+
: serviceNamespace + "." + serviceName;
136137
}
137138

138-
if (string.IsNullOrEmpty(process.ServiceName))
139+
if (!string.IsNullOrEmpty(serviceName))
139140
{
140-
process.ServiceName = DefaultServiceName;
141+
process.ServiceName = serviceName;
141142
}
142143

143144
this.Process.Message = this.BuildThriftMessage(this.Process).ToArray();

src/OpenTelemetry.Exporter.Zipkin/.publicApi/net452/PublicAPI.Unshipped.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ OpenTelemetry.Exporter.ZipkinExporterOptions.Endpoint.get -> System.Uri
77
OpenTelemetry.Exporter.ZipkinExporterOptions.Endpoint.set -> void
88
OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.get -> OpenTelemetry.ExportProcessorType
99
OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.set -> void
10-
OpenTelemetry.Exporter.ZipkinExporterOptions.ServiceName.get -> string
11-
OpenTelemetry.Exporter.ZipkinExporterOptions.ServiceName.set -> void
1210
OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.get -> bool
1311
OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.set -> void
1412
OpenTelemetry.Exporter.ZipkinExporterOptions.ZipkinExporterOptions() -> void

src/OpenTelemetry.Exporter.Zipkin/.publicApi/net461/PublicAPI.Unshipped.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.get -> OpenTele
99
OpenTelemetry.Exporter.ZipkinExporterOptions.ExportProcessorType.set -> void
1010
OpenTelemetry.Exporter.ZipkinExporterOptions.MaxPayloadSizeInBytes.get -> int?
1111
OpenTelemetry.Exporter.ZipkinExporterOptions.MaxPayloadSizeInBytes.set -> void
12-
OpenTelemetry.Exporter.ZipkinExporterOptions.ServiceName.get -> string
13-
OpenTelemetry.Exporter.ZipkinExporterOptions.ServiceName.set -> void
1412
OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.get -> bool
1513
OpenTelemetry.Exporter.ZipkinExporterOptions.UseShortTraceIds.set -> void
1614
OpenTelemetry.Exporter.ZipkinExporterOptions.ZipkinExporterOptions() -> void

0 commit comments

Comments
 (0)