Dynatrace provides comprehensive web request monitoring for MAUI applications. You can automatically instrument HTTP requests via HttpClient or manually report requests from unsupported libraries.
You can optionally use the following method to enable the auto-instrumentation of web requests. The HttpMessageHandler used by HttpClient takes care of the manual web request instrumentation.
using Dynatrace.MAUI;var httpHandler = Agent.Instance.GetHttpMessageHandler();var httpClient = new HttpClient(httpHandler);
Moreover, you can also have your own HTTP handler:
using Dynatrace.MAUI;var defaultHttpHandler = new HttpClientHandler();var httpHandler = Agent.Instance.GetHttpMessageHandler(defaultHttpHandler);var httpClient = new HttpClient(httpHandler);
Use the following code snippet to instrument web requests:
using Dynatrace.MAUI;// Create an actionIRootAction webAction = Agent.Instance.EnterAction(actionName: "WebRequest Action");// Generate a new unique tag associated with the web request actionstring requestTag = webAction.GetRequestTag(url);string requestTagHeader = webAction.GetRequestTagHeader();// Place the Dynatrace HTTP header on your web requesthttpClient.DefaultRequestHeaders.Add(requestTagHeader, requestTag);// Generate a WebRequestTiming object based on the unique tagIWebRequestTiming timing = Agent.Instance.GetWebRequestTiming(requestTag, url);// Start web request timing before the HTTP request is senttiming.StartWebRequestTiming();try{var response = await httpClient.GetAsync(url);// Stop web request timing when the HTTP response is received and the response body is obtainedtiming.StopWebRequestTiming(url, (int)response.StatusCode, response.ReasonPhrase);}catch (HttpRequestException exception){// Stop web request timing when a connection exception occurstiming.StopWebRequestTiming(url, -1, exception.ToString());}finally{// Leave an actionwebAction.LeaveAction();}