コード例 #1
0
        private static MyCustomHttpResponse HandleIncomingWebRequest(MyCustomHttpRequest request, bool sendOutgoingRequest = false)
        {
            // create web application info object describing our web service
            IWebApplicationInfo webAppInfo = SampleApplication.OneAgentSdk
                                             .CreateWebApplicationInfo("WebShopProduction", "AuthenticationService", "/api/auth");

            IIncomingWebRequestTracer tracer = SampleApplication.OneAgentSdk
                                               .TraceIncomingWebRequest(webAppInfo, request.Url, request.Method);

            tracer.SetRemoteAddress(request.RemoteClientAddress);

            // adding all request headers ensures that tracing headers required
            // for end-to-end linking of requests are provided to the SDK
            foreach (KeyValuePair <string, string> header in request.Headers)
            {
                tracer.AddRequestHeader(header.Key, header.Value);
            }
            foreach (KeyValuePair <string, string> param in request.PostParameters)
            {
                tracer.AddParameter(param.Key, param.Value);
            }

            // start tracer
            return(tracer.Trace(() =>
            {
                // send a nested outgoing request for demonstration
                if (sendOutgoingRequest)
                {
                    MyCustomHttpRequest outgoingRequest = new MyCustomHttpRequest("https://www.example.com:8081/api/auditlog", "POST");
                    IOutgoingWebRequestTracer outgoingTracer = SampleApplication.OneAgentSdk.TraceOutgoingWebRequest(outgoingRequest.Url, outgoingRequest.Method);
                    outgoingTracer.Trace(() =>
                    {
                        outgoingTracer.InjectTracingHeaders((name, value) => outgoingRequest.Headers[name] = value);
                        MyCustomHttpResponse incomingResponse = outgoingRequest.Execute();
                        outgoingTracer.SetStatusCode(incomingResponse.StatusCode);
                    });
                }

                var response = new MyCustomHttpResponse();

                // handle request and build response ...

                foreach (KeyValuePair <string, string> header in response.Headers)
                {
                    tracer.AddResponseHeader(header.Key, header.Value);
                }
                tracer.SetStatusCode(response.StatusCode);

                return response;
            }));
        }
コード例 #2
0
        private static MyCustomHttpResponse HandleIncomingWebRequest(MyCustomHttpRequest request)
        {
            // create web application info object describing our web service
            IWebApplicationInfo webAppInfo = SampleApplication.OneAgentSdk
                                             .CreateWebApplicationInfo("WebShopProduction", "AuthenticationService", "/api/auth");

            IIncomingWebRequestTracer tracer = SampleApplication.OneAgentSdk
                                               .TraceIncomingWebRequest(webAppInfo, request.Url, request.Method);

            tracer.SetRemoteAddress(request.RemoteClientAddress);

            // adding all request headers ensures that tracing headers required
            // for end-to-end linking of requests are provided to the SDK
            foreach (KeyValuePair <string, string> header in request.Headers)
            {
                tracer.AddRequestHeader(header.Key, header.Value);
            }
            foreach (KeyValuePair <string, string> param in request.PostParameters)
            {
                tracer.AddParameter(param.Key, param.Value);
            }

            // start tracer
            return(tracer.Trace(() =>
            {
                var response = new MyCustomHttpResponse();

                // handle request and build response ...

                foreach (KeyValuePair <string, string> header in response.Headers)
                {
                    tracer.AddResponseHeader(header.Key, header.Value);
                }
                tracer.SetStatusCode(response.StatusCode);

                return response;
            }));
        }