Skip to content

Commit

Permalink
Remove ServiceName from OtlpExporterOptions (#1557)
Browse files Browse the repository at this point in the history
* Remove ServiceName from OtlpExporterOptions

* Update PublicAPI

* Update changelog

* Add back default service name when resource does not have service.name

* Fix test

* Fix examples post merge
  • Loading branch information
alanwest authored Nov 17, 2020
1 parent 3c49d35 commit 0e30817
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 29 deletions.
4 changes: 3 additions & 1 deletion examples/AspNetCore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
using OpenTelemetry;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

namespace Examples.AspNetCore
Expand Down Expand Up @@ -79,11 +81,11 @@ public void ConfigureServices(IServiceCollection services)
break;
case "otlp":
services.AddOpenTelemetryTracing((builder) => builder
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(this.Configuration.GetValue<string>("Otlp:ServiceName")))
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddOtlpExporter(otlpOptions =>
{
otlpOptions.ServiceName = this.Configuration.GetValue<string>("Otlp:ServiceName");
otlpOptions.Endpoint = this.Configuration.GetValue<string>("Otlp:Endpoint");
}));
break;
Expand Down
2 changes: 2 additions & 0 deletions examples/Console/TestOtlpExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// </copyright>

using OpenTelemetry;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

namespace Examples.Console
Expand Down Expand Up @@ -56,6 +57,7 @@ private static object RunWithActivitySource(string endpoint)
// and use OTLP exporter.
using var openTelemetry = Sdk.CreateTracerProviderBuilder()
.AddSource("Samples.SampleClient", "Samples.SampleServer")
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("otlp-test"))
.AddOtlpExporter(opt => opt.Endpoint = endpoint)
.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.Endpoint.set ->
OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.Headers.get -> Grpc.Core.Metadata
OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.Headers.set -> void
OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.OtlpExporterOptions() -> void
OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.ServiceName.get -> string
OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.ServiceName.set -> void
OpenTelemetry.Trace.OtlpExporterHelperExtensions
static OpenTelemetry.Trace.OtlpExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions> configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.Endpoint.set ->
OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.Headers.get -> Grpc.Core.Metadata
OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.Headers.set -> void
OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.OtlpExporterOptions() -> void
OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.ServiceName.get -> string
OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.ServiceName.set -> void
OpenTelemetry.Trace.OtlpExporterHelperExtensions
static OpenTelemetry.Trace.OtlpExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions> configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.Endpoint.set ->
OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.Headers.get -> Grpc.Core.Metadata
OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.Headers.set -> void
OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.OtlpExporterOptions() -> void
OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.ServiceName.get -> string
OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions.ServiceName.set -> void
OpenTelemetry.Trace.OtlpExporterHelperExtensions
static OpenTelemetry.Trace.OtlpExporterHelperExtensions.AddOtlpExporter(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporterOptions> configure = null) -> OpenTelemetry.Trace.TracerProviderBuilder
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
([#1524](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1524))
* The `OtlpExporter` class has been made internal.
([#1528](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1528))
* Removed `ServiceName` from options available on the `AddOtlpExporter`
extension. It is not required by the
[specification](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/protocol/exporter.md#configuration-options).
([#1557](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1557))

## 0.8.0-beta.1

Expand Down
10 changes: 3 additions & 7 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol
/// </summary>
internal class OtlpExporter : BaseExporter<Activity>
{
private const string DefaultServiceName = "OpenTelemetry Exporter";

private readonly OtlpExporterOptions options;
private readonly Channel channel;
private readonly OtlpCollector.TraceService.ITraceServiceClient traceClient;
Expand Down Expand Up @@ -106,16 +108,10 @@ internal void SetResource(Resource resource)

if (!processResource.Attributes.Any(kvp => kvp.Key == ResourceSemanticConventions.AttributeServiceName))
{
string serviceName = this.options.ServiceName;
if (string.IsNullOrEmpty(serviceName))
{
serviceName = OtlpExporterOptions.DefaultServiceName;
}

processResource.Attributes.Add(new OtlpCommon.KeyValue
{
Key = ResourceSemanticConventions.AttributeServiceName,
Value = new OtlpCommon.AnyValue { StringValue = serviceName },
Value = new OtlpCommon.AnyValue { StringValue = DefaultServiceName },
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol
/// </summary>
public class OtlpExporterOptions
{
internal const string DefaultServiceName = "OpenTelemetry Exporter";

/// <summary>
/// Gets or sets the name of the service reporting telemetry. Default value: OpenTelemetry Exporter.
/// </summary>
public string ServiceName { get; set; } = DefaultServiceName;

/// <summary>
/// Gets or sets the target to which the exporter is going to send traces or metrics.
/// The valid syntax is described at https://github.com/grpc/grpc/blob/master/doc/naming.md.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public void OtlpExporter_BadArgs()
}

[Theory]
[InlineData(true, null)]
[InlineData(false, "test-service")]
public void ToOtlpResourceSpansTest(bool addResource, string optionsServiceName)
[InlineData(true)]
[InlineData(false)]
public void ToOtlpResourceSpansTest(bool addResource)
{
var evenTags = new[] { new KeyValuePair<string, object>("k0", "v0") };
var oddTags = new[] { new KeyValuePair<string, object>("k1", "v1") };
Expand All @@ -71,10 +71,7 @@ public void ToOtlpResourceSpansTest(bool addResource, string optionsServiceName)
};

using var exporter = new OtlpExporter(
new OtlpExporterOptions
{
ServiceName = optionsServiceName,
},
new OtlpExporterOptions(),
new NoopTraceServiceClient());

if (addResource)
Expand Down Expand Up @@ -129,7 +126,7 @@ void RunTest(Batch<Activity> batch)
}
else
{
Assert.Contains(oltpResource.Attributes, (kvp) => kvp.Key == Resources.ResourceSemanticConventions.AttributeServiceName && kvp.Value.StringValue == optionsServiceName);
Assert.Contains(oltpResource.Attributes, (kvp) => kvp.Key == Resources.ResourceSemanticConventions.AttributeServiceName && kvp.Value.StringValue == "OpenTelemetry Exporter");
}

foreach (var instrumentationLibrarySpans in request.ResourceSpans.First().InstrumentationLibrarySpans)
Expand Down

0 comments on commit 0e30817

Please sign in to comment.