Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ServiceName from OtlpExporterOptions #1557

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Comment on lines +26 to +27
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add both OpenTelemetry and OpenTelemetry.Resources here because the AddService extension method is in the OpenTelemetry namespace. Was this intentional? Relates to #1541 in that I think we should aim to be consistent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this requires some changes. Lets merge this PR, and follow up to make it consistent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alanwest @cijothomas I put the extensions into OpenTelemetry namespace instead of OpenTelemetry.Resources so that people could use the TracerBuilderExtension.ConfigureResource extension without an additional namespace having to be imported. But that ended up being removed so we can probably move into OpenTelemetry.Resources without any issues, people will just need OpenTelemetry.Trace & OpenTelemetry.Resources in their startup usings (if they want to use ResourceBuilder). Or we put all the builders into OpenTelemetry namespace so people only need that single using in their startup? 🤷

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we discussed this in todays SiG meeting as well.. Lets address the overall namespace changes separate from this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, good to know the history here. We can continue the namespace conversation separate from this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh, it backfired on me! Just updated some code to RC1 and I had to add using OpenTelemetry because of this. I ended up with:

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

All being required to configure TracerProvider w/ Resources in startup code. That sucks. Sorry!

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