Пример #1
0
        public static async Task OutgoingWebRequestAsync()
        {
            var request = new MyCustomHttpRequest("https://www.example.com:8080/api/auth/user?group=42&location=Linz", "GET");

            request.Headers["Accept"]            = "application/json; q=1.0, application/xml; q=0.8";
            request.Headers["Accept-Charset"]    = "utf-8";
            request.Headers["Cache-Control"]     = "no-cache,no-store,must-revalidate";
            request.Headers["X-MyRequestHeader"] = "MyRequestValue";

            IOutgoingWebRequestTracer tracer = SampleApplication.OneAgentSdk.TraceOutgoingWebRequest(request.Url, request.Method);

            foreach (KeyValuePair <string, string> header in request.Headers)
            {
                tracer.AddRequestHeader(header.Key, header.Value);
            }

            // start tracer and send request
            await tracer.TraceAsync(async() =>
            {
                // add the Dynatrace tag or W3C Trace Context (based on your configuration) to request headers to allow
                // the agent in the web server to link the request together for end-to-end tracing
                tracer.InjectTracingHeaders((key, value, carrier) => carrier[key] = value, request.Headers); // Option 2: passing a stateless implementation, which gets 'request.Headers' passed as 'carrier'

                MyCustomHttpResponse response = await request.ExecuteAsync();

                tracer.SetStatusCode(response.StatusCode);

                foreach (KeyValuePair <string, string> header in response.Headers)
                {
                    tracer.AddResponseHeader(header.Key, header.Value);
                }
            });
        }
Пример #2
0
        public static async Task OutgoingWebRequestAsync()
        {
            var request = new MyCustomHttpRequest("https://www.example.com:8080/api/auth/user?group=42&location=Linz", "GET");

            request.Headers["Accept"]            = "application/json; q=1.0, application/xml; q=0.8";
            request.Headers["Accept-Charset"]    = "utf-8";
            request.Headers["Cache-Control"]     = "no-cache,no-store,must-revalidate";
            request.Headers["X-MyRequestHeader"] = "MyRequestValue";

            IOutgoingWebRequestTracer tracer = SampleApplication.OneAgentSdk.TraceOutgoingWebRequest(request.Url, request.Method);

            foreach (KeyValuePair <string, string> header in request.Headers)
            {
                tracer.AddRequestHeader(header.Key, header.Value);
            }

            // start tracer and send request
            await tracer.TraceAsync(async() =>
            {
                // set the Dynatrace tracing header to allow linking the request on the server
                request.Headers[OneAgentSdkConstants.DYNATRACE_HTTP_HEADERNAME] = tracer.GetDynatraceStringTag();

                MyCustomHttpResponse response = await request.ExecuteAsync();

                tracer.SetStatusCode(response.StatusCode);

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