0
votes

I have a need to add CorrelationId for end to end tracing of a request in a asp dotnet core application. I'm using Azure application insights for logging and telemetry. How do I add the correlation Id to request scope so that every Ilogger call in various layers and telemetry call record this info?

Below is the code snippet used to enable application insights:

 .UseApplicationInsights()
 .ConfigureLogging(loggingBuilder => loggingBuilder.AddApplicationInsights())
1
with default application insights settings, the request and all other telemetry within that scope would already be correlated with same operation_id. Are you not seeing this behavior?cijothomas
I'd like to show the correlation Id along with error text in the UI when an error occurred. That way it will be quick to resolve customer support issues. How is operation_id generated? Is it possible for me to set it?frosty

1 Answers

0
votes

Application Insights defines a data model for distributed telemetry correlation. To associate telemetry with the logical operation, every telemetry item has a context field called operation_Id. This identifier is shared by every telemetry item in the distributed trace. So, even with loss of telemetry from a single layer, you can still associate telemetry reported by other components.

A distributed logical operation typically consists of a set of smaller operations, which are requests processed by one of the components. These operations are defined by request telemetry. Every request telemetry has its own id that identifies it uniquely and globally. And all telemetry items (such as traces and exceptions) that are associated with this request should set the operation_parentId to the value of the request id.

Every outgoing operation, such as an HTTP call to another component, is represented by dependency telemetry. Dependency telemetry also defines its own id that is globally unique. Request telemetry, initiated by this dependency call, uses this id as its operation_parentId.

You can build a view of the distributed logical operation by using operation_Id, operation_parentId, and request.id with dependency.id. These fields also define the causality order of telemetry calls.

Documentation Reference - link

Hope the above information helps.