Edit: Fixing per the additional information in comment.
You sound like you want to correlate the dependent requests with the server request. This is usually handled by the combination of two pieces:
- Set
disableCorrelationHeaders = false
in the JavaScript snippet config
- Ensure your API Service has the
OperationCorrelationTelemetryInitializer
added in the ApplicationInsights.config under the <TelemetryInitializers>
section
The JavaScript setting will set the x-ms-request-id
and the x-ms-request-root-id
header to be picked up by the telemetry initializer.
The initializer relies on the HttpContext.Request being available.
Using separate instrumentation keys (iKeys) will not matter when it comes to setting the operation id. Where it will matter is when you go to look for this correlated telemetry in the UI. If everything flows to the same iKey it will be able to be retrieved.
The next thing to be mindful of is if your server side telemetry is being sampled. By default the AdaptiveSampling processor is enabled and set to only send 5 telemetry items per second.
Steps to troubleshoot
- When the request is sent from the browser use Fiddler or the F12 tools to ensure the
x-ms-request-*
headers are being set.
- Debug your WebAPI application and validate that
System.Web.HttpContext.Current.Request.Headers["x-ms-request-id"]
or System.Web.HttpContext.Current.Request.Headers["x-ms-request-root-id"]
is present
- Ensure
<Add Type="Microsoft.ApplicationInsights.Web.OperationCorrelationTelemetryInitializer, Microsoft.AI.Web"/>
is added in the <TelemetryInitializers>
section of your ApplicationInsights.config
- Increase the
<MaxTelemetryItemsPerSecond>
to a large number like 5000
- Make sure you're using v2.2.0 or higher of the .NET SDK