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); } }); }
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); } }); }
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; })); }
public static void LinkedOutgoingIncomingWebRequest() { 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"; 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 tracer.Trace(() => { // 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) => request.Headers[key] = value); // Option 1: passing a stateful lambda, directly accessing 'request.Headers' MyCustomHttpResponse response = null; // represents server side processing Thread server = new Thread(() => { response = HandleIncomingWebRequest(request); }); server.Start(); server.Join(); // sync request, wait for result tracer.SetStatusCode(response.StatusCode); foreach (KeyValuePair <string, string> header in response.Headers) { tracer.AddResponseHeader(header.Key, header.Value); } }); }
public static void LinkedOutgoingIncomingWebRequest() { 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"; 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 tracer.Trace(() => { // set the Dynatrace tracing header to allow linking the request on the server request.Headers[OneAgentSdkConstants.DYNATRACE_HTTP_HEADERNAME] = tracer.GetDynatraceStringTag(); MyCustomHttpResponse response = null; // represents server side processing Thread server = new Thread(() => { response = HandleIncomingWebRequest(request); }); server.Start(); server.Join(); // sync request, wait for result tracer.SetStatusCode(response.StatusCode); foreach (KeyValuePair <string, string> header in response.Headers) { tracer.AddResponseHeader(header.Key, header.Value); } }); }