Dr Schizo
Dr Schizo

Reputation: 4386

TelemetryClient request tracking end to end with trace

It is possible to trace a request along with any traces that I have added via the TelemetryClient. In a nutshell, I am using:

var id = "a very unique id";
using (telemetryClient.StartOperation<RequestTelemetry>("Name", id, id))
{
telemetryClient.Trace("I have done something", new Dictionary<string, string> { { "uniqueId", id } );
telemetryClient.Trace("I am doing something else", new Dictionary<string, string> { { "uniqueId", id } );
}

The problem here is that the operationId isn't set nor the operationParentId.

Perhaps I am using this incorrectly but I was hoping to do a join between traces and requests on operationParentId so I can get the full picture.

Upvotes: 0

Views: 562

Answers (1)

Ivan Glasenberg
Ivan Glasenberg

Reputation: 30025

I suggest you use the latest version of Microsoft.ApplicationInsights 2.10.0

With the latest nuget package installed, I test the code you provide, operationId / operationParentId are set properly.

Code:

        static void Main(string[] args)
        {    
            TelemetryClient client = new TelemetryClient() { InstrumentationKey = "xxxx" };

            string id = "b123456";
            using (client.StartOperation<RequestTelemetry>("op_name",id,id))
            {
                client.TrackTrace("I have done something", new Dictionary<string, string> { { "my_uniqueId", id } } );
                client.TrackTrace("I am doing something else", new Dictionary<string, string> { { "my_uniqueId", id } } );    
            }    

            Console.ReadLine();
        }

In portal:

Request telemetry:

enter image description here

Trace telemetry:

enter image description here

Upvotes: 1

Related Questions