void IWcfTelemetryModule.OnEndRequest(IOperationContext operation, Message reply) { if (operation == null) { throw new ArgumentNullException("operation"); } if (telemetryClient == null) { return; } RequestTelemetry telemetry = operation.Request; telemetry.Stop(); // make some assumptions bool isFault = false; HttpStatusCode responseCode = HttpStatusCode.OK; if (reply != null) { isFault = reply.IsFault; } HttpResponseMessageProperty httpHeaders = operation.GetHttpResponseHeaders(); if (httpHeaders != null) { responseCode = httpHeaders.StatusCode; if ((int)responseCode >= 400) { isFault = true; } } else if (isFault) { responseCode = HttpStatusCode.InternalServerError; } // if the operation code has already marked the request as failed // don't overwrite the value if we think it was successful if (isFault || !telemetry.Success.HasValue) { telemetry.Success = !isFault; } telemetry.ResponseCode = responseCode.ToString("d"); telemetry.Properties.Add("Protocol", telemetry.Url.Scheme); // if the Microsoft.ApplicationInsights.Web package started // tracking this request before WCF handled it, we // don't want to track it because it would duplicate the event. // Let the HttpModule instead write it later on. if (operation.OwnsRequest) { telemetryClient.TrackRequest(telemetry); } }
void IWcfTelemetryModule.OnEndRequest(IOperationContext operation, Message reply) { if (operation == null) { throw new ArgumentNullException("operation"); } if (telemetryClient == null) { return; } RequestTelemetry telemetry = operation.Request; telemetry.Stop(); // make some assumptions bool isFault = false; HttpStatusCode responseCode = HttpStatusCode.OK; if (reply != null) { isFault = reply.IsFault; } HttpResponseMessageProperty httpHeaders = operation.GetHttpResponseHeaders(); if (httpHeaders != null) { responseCode = httpHeaders.StatusCode; if ((int)responseCode >= 400) { isFault = true; } } else if (isFault) { responseCode = HttpStatusCode.InternalServerError; } telemetry.Success = !isFault; telemetry.ResponseCode = responseCode.ToString("d"); telemetry.Properties.Add("Protocol", telemetry.Url.Scheme); telemetryClient.TrackRequest(telemetry); }