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

Correctly set activityKey when we change the Trace ID #5771

Merged
merged 1 commit into from
Jul 10, 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,11 +58,6 @@ public static void ActivityStarted<T>(string sourceName, T activity, OpenTelemet
var activityTraceId = w3cActivity.TraceId;
var activitySpanId = w3cActivity.SpanId;

if (activityTraceId != null! && activitySpanId != null!)
{
activityKey = activityTraceId + activitySpanId;
}

// If the user has specified a parent context, get the parent Datadog SpanContext
if (w3cActivity is { ParentSpanId: { } parentSpanId, ParentId: { } parentId })
{
Expand Down Expand Up @@ -110,6 +105,7 @@ public static void ActivityStarted<T>(string sourceName, T activity, OpenTelemet
{
// TraceId (always 32 chars long even when using 64-bit ids)
w3cActivity.TraceId = activeSpan.Context.RawTraceId;
activityTraceId = w3cActivity.TraceId;

// SpanId (always 16 chars long)
w3cActivity.ParentSpanId = activeSpan.Context.RawSpanId;
Expand Down Expand Up @@ -137,6 +133,11 @@ public static void ActivityStarted<T>(string sourceName, T activity, OpenTelemet
rawTraceId = activityTraceId;
rawSpanId = activitySpanId;
}

if (activityTraceId != null! && activitySpanId != null!)
{
activityKey = activityTraceId + activitySpanId;
}
}

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +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);

if (string.IsNullOrEmpty(packageVersion) || new Version(packageVersion) >= new Version("1.7.0"))
{
otelSpans.Count().Should().Be(expectedSpanCount - 3); // there is another span w/ service == ServiceNameOverride
activitySourceSpans.Count().Should().Be(2);
}
else
{
otelSpans.Count().Should().Be(expectedSpanCount - 2); // there is another span w/ service == ServiceNameOverride
activitySourceSpans.Count().Should().Be(1);
}
otelSpans.Count().Should().Be(expectedSpanCount - 2); // there is another span w/ service == ServiceNameOverride
activitySourceSpans.Count().Should().Be(1);

ValidateIntegrationSpans(otelSpans, metadataSchemaVersion: "v0", expectedServiceName: "MyServiceName", isExternalSpan: false);
ValidateIntegrationSpans(activitySourceSpans, metadataSchemaVersion: "v0", expectedServiceName: CustomServiceName, isExternalSpan: false);
Expand Down Expand Up @@ -173,14 +165,7 @@ public async Task SubmitsTracesWithActivitySource(string packageVersion)
using var s = new AssertionScope();
var otelSpans = spans.Where(s => s.Service == "MyServiceName");

if (string.IsNullOrEmpty(packageVersion) || new Version(packageVersion) >= new Version("1.7.0"))
{
otelSpans.Count().Should().Be(expectedSpanCount - 2); // there is another span w/ service == ServiceNameOverride
}
else
{
otelSpans.Count().Should().Be(expectedSpanCount - 1); // there is another span w/ service == ServiceNameOverride
}
otelSpans.Count().Should().Be(expectedSpanCount - 1); // there is another span w/ service == ServiceNameOverride

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

Expand Down
14 changes: 8 additions & 6 deletions tracer/test/snapshots/OpenTelemetrySdkTests.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@
SpanId: Id_29,
Name: internal,
Resource: StartRootSpan,
Service: CustomServiceName,
Service: MyServiceName,
Type: custom,
ParentId: Id_26,
Tags: {
Expand All @@ -698,12 +698,14 @@
otel.library.name: MyServiceName,
otel.status_code: STATUS_CODE_UNSET,
otel.trace_id: Guid_4,
runtime-id: Guid_2,
service.instance.id: Guid_3,
service.name: MyServiceName,
service.version: 1.0.x,
span.kind: internal,
version: 1.0.x
},
Metrics: {
_dd.top_level: 1.0
telemetry.sdk.language: dotnet,
telemetry.sdk.name: opentelemetry,
telemetry.sdk.version: sdk-version,
_dd.base_service: CustomServiceName
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@
SpanId: Id_29,
Name: internal,
Resource: StartRootSpan,
Service: CustomServiceName,
Service: MyServiceName,
Type: custom,
ParentId: Id_26,
Tags: {
Expand All @@ -698,12 +698,14 @@
otel.library.name: MyServiceName,
otel.status_code: STATUS_CODE_UNSET,
otel.trace_id: Guid_4,
runtime-id: Guid_2,
service.instance.id: Guid_3,
service.name: MyServiceName,
service.version: 1.0.x,
span.kind: internal,
version: 1.0.x
},
Metrics: {
_dd.top_level: 1.0
telemetry.sdk.language: dotnet,
telemetry.sdk.name: opentelemetry,
telemetry.sdk.version: sdk-version,
_dd.base_service: CustomServiceName
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@
SpanId: Id_29,
Name: MyServiceName.internal,
Resource: StartRootSpan,
Service: CustomServiceName,
Service: MyServiceName,
Type: custom,
ParentId: Id_26,
Tags: {
Expand All @@ -698,12 +698,14 @@
otel.library.name: MyServiceName,
otel.status_code: STATUS_CODE_UNSET,
otel.trace_id: Guid_4,
runtime-id: Guid_2,
service.instance.id: Guid_3,
service.name: MyServiceName,
service.version: 1.0.x,
span.kind: internal,
version: 1.0.x
},
Metrics: {
_dd.top_level: 1.0
telemetry.sdk.language: dotnet,
telemetry.sdk.name: opentelemetry,
telemetry.sdk.version: sdk-version,
_dd.base_service: CustomServiceName
}
},
{
Expand Down
Loading