Use Agent.Subscribe() to register diagnostic subscribers that automatically capture outgoing HTTP calls as spans within your transactions.
Required Imports
copy
using Atatus;
using Atatus.DiagnosticSource;
HttpDiagnosticsSubscriber
Use HttpDiagnosticsSubscriber to automatically capture all outgoing HTTP requests made via HttpClient as spans. Each HTTP call will appear as a span under the active transaction.
Syntax
Agent.Subscribe(new HttpDiagnosticsSubscriber());
Example
copy
using Atatus;
using Atatus.Api;
using Atatus.DiagnosticSource;
// Subscribe to HTTP diagnostic events at application startup
Agent.Subscribe(new HttpDiagnosticsSubscriber());
var httpClient = new HttpClient
{
BaseAddress = new Uri("http://localhost:8080/")
};
var transaction = Atatus.Agent.Tracer.StartTransaction("GET /api/users", ApiConstants.TypeRequest);
try
{
// This HTTP call is automatically captured as a span
var response = await httpClient.GetAsync("/api/users");
var content = await response.Content.ReadAsStringAsync();
}
catch (Exception ex)
{
transaction.CaptureException(ex);
}
finally
{
transaction.End();
}
+1-415-800-4104