microsoft / ApplicationInsights-SDK-Labs

Application Insights experimental projects repository
MIT License
61 stars 48 forks source link

How can i log data from the request in the request telemetry #76

Closed ranjitkrishnan closed 8 years ago

ranjitkrishnan commented 8 years ago

I have a need to log some of the details of the request in Application Insights which will help me better track the web service requests.

I thought of logging it as CustomData in the request. I found the way to do so is by setting Context properties in the telemetry client.

I did so with the code below.

telemetry.Context.Properties["CustomGuid"] = data; telemetry.TrackRequest(request);

But this logged a duplicate request with all the data i needed. But i dont want duplicate requests to be logged. I would like to get the custom data to be logged as part of the request telemetry originally logged.

Is there any way i can do this ?

tomasr commented 8 years ago

You can obtain the RequestTelemetry object corresponding to the current request from the OperationContext like this:

using Microsoft.ApplicationInsights.Wcf;
...
var request = OperationContext.Current.GetRequestTelemetry();
request.Properties["CustomGuid"] = data;

You don't need to call TrackRequest() in this case.

OliverRC commented 7 years ago

@tomasr thanks for your answer. Any idea how to do this in ASP.NET?