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

Include ai.operation.parentId from Activity.ParentSpanId instead of Activity.Parent.SpanId #20434

Merged
merged 4 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -43,9 +43,9 @@ internal static TelemetryItem GetTelemetryItem(Activity activity, Resource resou
telemetryItem.Tags[ContextTagKeys.AiCloudRoleInstance.ToString()] = RoleInstance;
telemetryItem.Tags[ContextTagKeys.AiOperationId.ToString()] = activity.TraceId.ToHexString();

if (activity.Parent != null)
if (activity.ParentSpanId != default)
{
telemetryItem.Tags[ContextTagKeys.AiOperationParentId.ToString()] = activity.Parent.SpanId.ToHexString();
telemetryItem.Tags[ContextTagKeys.AiOperationParentId.ToString()] = activity.ParentSpanId.ToHexString();
}

telemetryItem.Tags[ContextTagKeys.AiInternalSdkVersion.ToString()] = SdkVersionUtils.SdkVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private static Activity CreateTestActivity(IEnumerable<KeyValuePair<string, obje
var eventTimestamp = DateTime.UtcNow;
var traceId = ActivityTraceId.CreateRandom();

var parentSpanId = ActivitySpanId.CreateRandom();
var parentSpanId = default(ActivitySpanId);
Copy link
Contributor

Choose a reason for hiding this comment

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

@mangeg - I am not sure why this change is included.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, that was not supposed to be there. Must have been left in from testing.
Will make a update to revert that change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!


Dictionary<string, object> attributes = null;
if (additionalAttributes != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,28 @@ public void GeneratePartAEnvelope_Activity_WithResource()
Assert.Throws<KeyNotFoundException>(() => telemetryItem.Tags[ContextTagKeys.AiOperationParentId.ToString()]);
}

[Fact]
public void GeneratePartAEnvelope_Activity_WithParentSpanId()
{
using ActivitySource activitySource = new ActivitySource(ActivitySourceName);
using var activity = activitySource.StartActivity(
ActivityName,
ActivityKind.Client,
parentContext: new ActivityContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded),
startTime: DateTime.UtcNow);
var resource = CreateTestResource();

var telemetryItem = TelemetryPartA.GetTelemetryItem(activity, resource, null);

Assert.Equal("RemoteDependency", telemetryItem.Name);
Assert.Equal(TelemetryPartA.FormatUtcTimestamp(activity.StartTimeUtc), telemetryItem.Time);
Assert.StartsWith("unknown_service", telemetryItem.Tags[ContextTagKeys.AiCloudRole.ToString()]);
Assert.Null(telemetryItem.Tags[ContextTagKeys.AiCloudRoleInstance.ToString()]);
Assert.NotNull(telemetryItem.Tags[ContextTagKeys.AiOperationId.ToString()]);
Assert.NotNull(telemetryItem.Tags[ContextTagKeys.AiInternalSdkVersion.ToString()]);
Assert.Equal(activity.ParentSpanId.ToHexString(), telemetryItem.Tags[ContextTagKeys.AiOperationParentId.ToString()]);
}

// TODO: GeneratePartAEnvelope_WithActivityParent

/// <summary>
Expand Down