public object BeforeSendRequest(ref Message request, IClientChannel channel) { // get the request URI var requestUri = GetRequestUri(request); webRequestTracer = action.TraceWebRequest(requestUri); webRequestTracer.Start(); // add Dynatrace custom header for tracing object httpRequestMessageObject; if (request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out httpRequestMessageObject)) { var httpRequestMessage = httpRequestMessageObject as HttpRequestMessageProperty; if (string.IsNullOrWhiteSpace(httpRequestMessage.Headers[OpenKitConstants.WEBREQUEST_TAG_HEADER])) { httpRequestMessage.Headers[OpenKitConstants.WEBREQUEST_TAG_HEADER] = webRequestTracer.Tag; } } else { // request properties does not contain request message properties - just for safety reasons var httpRequestMessage = new HttpRequestMessageProperty(); httpRequestMessage.Headers.Add(OpenKitConstants.WEBREQUEST_TAG_HEADER, webRequestTracer.Tag); request.Properties.Add(HttpRequestMessageProperty.Name, httpRequestMessage); } return(null); }
public void AfterReceiveReply(ref Message reply, object correlationState) { if (webRequestTracer != null) { object httpResponseMessageObject; // assume HTTP OK by default int responseCode = (int)HttpStatusCode.OK; if (reply.Properties.TryGetValue(HttpResponseMessageProperty.Name, out httpResponseMessageObject)) { var httpResponseMessage = httpResponseMessageObject as HttpResponseMessageProperty; responseCode = (int)httpResponseMessage.StatusCode; } webRequestTracer.Stop(responseCode); webRequestTracer = null; } }