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

Change unknown_service to DefaultServiceName #5671

Merged
merged 7 commits into from
Jul 11, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,20 @@ public static void OnStart(object processor, object activityData)
{
if (attribute.Key == "service.name")
{
span.ServiceName = attribute.Value.ToString();
var resourceServiceName = attribute.Value.ToString();

// if OTEL_SERVICE_NAME isn't set, OpenTelemetry will set "service.name" to:
// "unknown_service" or "unknown_service:ProcessName"
if (string.IsNullOrEmpty(resourceServiceName)
|| string.Equals(resourceServiceName, "unknown_service", StringComparison.Ordinal)
|| resourceServiceName.StartsWith("unknown_service:", StringComparison.Ordinal))
{
resourceServiceName = Tracer.Instance.DefaultServiceName;

span.SetTag(attribute.Key, resourceServiceName);
}

span.ServiceName = resourceServiceName;
}
else if (attribute.Key == "service.version")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public async Task SubmitsTraces(string packageVersion, bool legacyOperationNames
using (var agent = EnvironmentHelper.GetMockAgent())
using (await RunSampleAndWaitForExit(agent, packageVersion: packageVersion))
{
const int expectedSpanCount = 36;
const int expectedSpanCount = 37;
var spans = agent.WaitForSpans(expectedSpanCount);

using var s = new AssertionScope();
Expand All @@ -118,8 +118,8 @@ public async Task SubmitsTraces(string packageVersion, bool legacyOperationNames
var otelSpans = spans.Where(s => s.Service == "MyServiceName");
var activitySourceSpans = spans.Where(s => s.Service == CustomServiceName);

otelSpans.Count().Should().Be(expectedSpanCount - 2); // there is another span w/ service == ServiceNameOverride
activitySourceSpans.Count().Should().Be(1);
otelSpans.Count().Should().Be(expectedSpanCount - 3); // there is another span w/ service == ServiceNameOverride
activitySourceSpans.Count().Should().Be(2);

ValidateIntegrationSpans(otelSpans, metadataSchemaVersion: "v0", expectedServiceName: "MyServiceName", isExternalSpan: false);
ValidateIntegrationSpans(activitySourceSpans, metadataSchemaVersion: "v0", expectedServiceName: CustomServiceName, isExternalSpan: false);
Expand Down Expand Up @@ -159,13 +159,13 @@ public async Task SubmitsTracesWithActivitySource(string packageVersion)
using (var agent = EnvironmentHelper.GetMockAgent())
using (await RunSampleAndWaitForExit(agent, packageVersion: packageVersion))
{
const int expectedSpanCount = 36;
const int expectedSpanCount = 37;
var spans = agent.WaitForSpans(expectedSpanCount);

using var s = new AssertionScope();
var otelSpans = spans.Where(s => s.Service == "MyServiceName");

otelSpans.Count().Should().Be(expectedSpanCount - 1); // there is another span w/ service == ServiceNameOverride
otelSpans.Count().Should().Be(expectedSpanCount - 2); // there is another span w/ service == ServiceNameOverride

ValidateIntegrationSpans(otelSpans, metadataSchemaVersion: "v0", expectedServiceName: "MyServiceName", isExternalSpan: false);

Expand Down
31 changes: 29 additions & 2 deletions tracer/test/snapshots/OpenTelemetrySdkTests.verified.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
[
{
TraceId: Id_1,
SpanId: Id_2,
Expand Down Expand Up @@ -951,6 +951,33 @@ at Samples.OpenTelemetrySdk.Program.RunSpanUpdateMethods(TelemetrySpan span),
TraceId: Id_40,
SpanId: Id_41,
Name: internal,
Resource: service.name should be the DefaultServiceName value,
Service: CustomServiceName,
Copy link
Member

Choose a reason for hiding this comment

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

I really like this approach of having the verbose "assertion" in the Resource to make it easier to check the spans 👍

Type: custom,
Tags: {
env: integration_tests,
language: dotnet,
otel.library.name: MissingServiceName,
otel.status_code: STATUS_CODE_UNSET,
otel.trace_id: Guid_7,
runtime-id: Guid_2,
service.name: CustomServiceName,
span.kind: internal,
telemetry.sdk.language: dotnet,
telemetry.sdk.name: opentelemetry,
telemetry.sdk.version: sdk-version
},
Metrics: {
process_id: 0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
}
},
{
TraceId: Id_42,
SpanId: Id_43,
Name: internal,
Resource: Transform,
Service: CustomServiceName,
Type: custom,
Expand All @@ -959,7 +986,7 @@ at Samples.OpenTelemetrySdk.Program.RunSpanUpdateMethods(TelemetrySpan span),
language: dotnet,
otel.library.name: AdditionalActivitySource,
otel.status_code: STATUS_CODE_UNSET,
otel.trace_id: Guid_7,
otel.trace_id: Guid_8,
runtime-id: Guid_2,
span.kind: internal
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
[
{
TraceId: Id_1,
SpanId: Id_2,
Expand Down Expand Up @@ -951,6 +951,33 @@ at Samples.OpenTelemetrySdk.Program.RunSpanUpdateMethods(TelemetrySpan span),
TraceId: Id_40,
SpanId: Id_41,
Name: internal,
Resource: service.name should be the DefaultServiceName value,
Service: CustomServiceName,
Type: custom,
Tags: {
env: integration_tests,
language: dotnet,
otel.library.name: MissingServiceName,
otel.status_code: STATUS_CODE_UNSET,
otel.trace_id: Guid_7,
runtime-id: Guid_2,
service.name: CustomServiceName,
span.kind: internal,
telemetry.sdk.language: dotnet,
telemetry.sdk.name: opentelemetry,
telemetry.sdk.version: sdk-version
},
Metrics: {
process_id: 0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
}
},
{
TraceId: Id_42,
SpanId: Id_43,
Name: internal,
Resource: Transform,
Service: MyServiceName,
Type: custom,
Expand All @@ -959,7 +986,7 @@ at Samples.OpenTelemetrySdk.Program.RunSpanUpdateMethods(TelemetrySpan span),
language: dotnet,
otel.library.name: AdditionalActivitySource,
otel.status_code: STATUS_CODE_UNSET,
otel.trace_id: Guid_7,
otel.trace_id: Guid_8,
runtime-id: Guid_2,
service.instance.id: Guid_3,
service.name: MyServiceName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
[
{
TraceId: Id_1,
SpanId: Id_2,
Expand Down Expand Up @@ -846,6 +846,30 @@ at Samples.OpenTelemetrySdk.Program.RunSpanUpdateMethods(TelemetrySpan span),
TraceId: Id_40,
SpanId: Id_41,
Name: internal,
Resource: service.name should be the DefaultServiceName value,
Service: CustomServiceName,
Type: custom,
Tags: {
env: integration_tests,
language: dotnet,
otel.library.name: MissingServiceName,
otel.status_code: STATUS_CODE_UNSET,
otel.trace_id: Guid_7,
runtime-id: Guid_2,
service.name: CustomServiceName,
span.kind: internal
},
Metrics: {
process_id: 0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
}
},
{
TraceId: Id_42,
SpanId: Id_43,
Name: internal,
Resource: Transform,
Service: MyServiceName,
Type: custom,
Expand All @@ -854,7 +878,7 @@ at Samples.OpenTelemetrySdk.Program.RunSpanUpdateMethods(TelemetrySpan span),
language: dotnet,
otel.library.name: AdditionalActivitySource,
otel.status_code: STATUS_CODE_UNSET,
otel.trace_id: Guid_7,
otel.trace_id: Guid_8,
runtime-id: Guid_2,
service.instance.id: Guid_3,
service.name: MyServiceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,30 @@ at Samples.OpenTelemetrySdk.Program.RunSpanUpdateMethods(TelemetrySpan span),
TraceId: Id_40,
SpanId: Id_41,
Name: internal,
Resource: service.name should be the DefaultServiceName value,
Service: CustomServiceName,
Type: custom,
Tags: {
env: integration_tests,
language: dotnet,
otel.library.name: MissingServiceName,
otel.status_code: STATUS_CODE_UNSET,
otel.trace_id: Guid_7,
runtime-id: Guid_2,
service.name: CustomServiceName,
span.kind: internal
},
Metrics: {
process_id: 0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
}
},
{
TraceId: Id_42,
SpanId: Id_43,
Name: internal,
Resource: Transform,
Service: MyServiceName,
Type: custom,
Expand All @@ -854,7 +878,7 @@ at Samples.OpenTelemetrySdk.Program.RunSpanUpdateMethods(TelemetrySpan span),
language: dotnet,
otel.library.name: AdditionalActivitySource,
otel.status_code: STATUS_CODE_UNSET,
otel.trace_id: Guid_7,
otel.trace_id: Guid_8,
runtime-id: Guid_2,
service.instance.id: Guid_3,
service.name: MyServiceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,33 @@ at Samples.OpenTelemetrySdk.Program.RunSpanUpdateMethods(TelemetrySpan span),
TraceId: Id_40,
SpanId: Id_41,
Name: internal,
Resource: service.name should be the DefaultServiceName value,
Service: CustomServiceName,
Type: custom,
Tags: {
env: integration_tests,
language: dotnet,
otel.library.name: MissingServiceName,
otel.status_code: STATUS_CODE_UNSET,
otel.trace_id: Guid_7,
runtime-id: Guid_2,
service.name: CustomServiceName,
span.kind: internal,
telemetry.sdk.language: dotnet,
telemetry.sdk.name: opentelemetry,
telemetry.sdk.version: sdk-version
},
Metrics: {
process_id: 0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
}
},
{
TraceId: Id_42,
SpanId: Id_43,
Name: internal,
Resource: Transform,
Service: MyServiceName,
Type: custom,
Expand All @@ -959,7 +986,7 @@ at Samples.OpenTelemetrySdk.Program.RunSpanUpdateMethods(TelemetrySpan span),
language: dotnet,
otel.library.name: AdditionalActivitySource,
otel.status_code: STATUS_CODE_UNSET,
otel.trace_id: Guid_7,
otel.trace_id: Guid_8,
runtime-id: Guid_2,
service.instance.id: Guid_3,
service.name: MyServiceName,
Expand Down
28 changes: 26 additions & 2 deletions tracer/test/snapshots/OpenTelemetrySdkTests_1_0.verified.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
[
{
TraceId: Id_1,
SpanId: Id_2,
Expand Down Expand Up @@ -846,6 +846,30 @@ at Samples.OpenTelemetrySdk.Program.RunSpanUpdateMethods(TelemetrySpan span),
TraceId: Id_40,
SpanId: Id_41,
Name: internal,
Resource: service.name should be the DefaultServiceName value,
Service: CustomServiceName,
Type: custom,
Tags: {
env: integration_tests,
language: dotnet,
otel.library.name: MissingServiceName,
otel.status_code: STATUS_CODE_UNSET,
otel.trace_id: Guid_7,
runtime-id: Guid_2,
service.name: CustomServiceName,
span.kind: internal
},
Metrics: {
process_id: 0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
}
},
{
TraceId: Id_42,
SpanId: Id_43,
Name: internal,
Resource: Transform,
Service: CustomServiceName,
Type: custom,
Expand All @@ -854,7 +878,7 @@ at Samples.OpenTelemetrySdk.Program.RunSpanUpdateMethods(TelemetrySpan span),
language: dotnet,
otel.library.name: AdditionalActivitySource,
otel.status_code: STATUS_CODE_UNSET,
otel.trace_id: Guid_7,
otel.trace_id: Guid_8,
runtime-id: Guid_2,
span.kind: internal
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
[
{
TraceId: Id_1,
SpanId: Id_2,
Expand Down Expand Up @@ -845,6 +845,30 @@ at Samples.OpenTelemetrySdk.Program.RunSpanUpdateMethods(TelemetrySpan span),
{
TraceId: Id_40,
SpanId: Id_41,
Name: MissingServiceName.internal,
Resource: service.name should be the DefaultServiceName value,
Service: CustomServiceName,
Type: custom,
Tags: {
env: integration_tests,
language: dotnet,
otel.library.name: MissingServiceName,
otel.status_code: STATUS_CODE_UNSET,
otel.trace_id: Guid_7,
runtime-id: Guid_2,
service.name: CustomServiceName,
span.kind: internal
},
Metrics: {
process_id: 0,
_dd.top_level: 1.0,
_dd.tracer_kr: 1.0,
_sampling_priority_v1: 1.0
}
},
{
TraceId: Id_42,
SpanId: Id_43,
Name: AdditionalActivitySource.internal,
Resource: Transform,
Service: CustomServiceName,
Expand All @@ -854,7 +878,7 @@ at Samples.OpenTelemetrySdk.Program.RunSpanUpdateMethods(TelemetrySpan span),
language: dotnet,
otel.library.name: AdditionalActivitySource,
otel.status_code: STATUS_CODE_UNSET,
otel.trace_id: Guid_7,
otel.trace_id: Guid_8,
runtime-id: Guid_2,
span.kind: internal
},
Expand Down
Loading
Loading