How do I use a GUID for Activity.SetParentID?

Viewed 37

I am using an application insights TelemetryClient and starting an operation with an Activity. I need to use a GUID as the parent, but it doesn't seem to take it. This is a worker service using .net6 with version 2.21.0 of Application Insights.

I am using this code:

Activity a = new Activity("test");
a.SetParentId("21bf02de-2d63-49c7-a0db-fb0d40483623");

using (client.StartOperation<RequestTelemetry>(a))
{
    _logger.LogError($"testing");
}

When this logs in application insights I do not get that guid as the operaiton ID. Instead, I get an auto generated operationID. I am using the default ActivityIdFormat.Unknown, but I have also tried it with Hierarchical and W3c.

If I use the format below, it works as expected and I get that value as the operationID.

a.SetParentId("7232382cd87c6aa0293cbb793f6c9839");

I need to set it to a guid, because I need to use our existing correlationID that comes from a message queue.

Is there a better way to set the operationID to our correlationID?

Is the best practvie to include the correlationID in a different field?

This question is different than the one below.

How do I set the applicaiton insights operationID to my custom correlationID?

This question specifically asks about using the Actvity passed to the start operation. The quesitons below, which is unanswered, deals with setting the operationID of the TelemtryClient. Either may solve my problem, but this one is asking a different question with different classes and methods.

0 Answers
Related