public class UnchainedTraceHeaderPropagatingHandler : DelegatingHandler, IDisposable
Class for tracing outgoing HTTP requests and propagating the trace context.
Inheritance
Object > HttpMessageHandler > DelegatingHandler > UnchainedTraceHeaderPropagatingHandlerImplements
IDisposableDerived Types
Namespace
Google.Cloud.Diagnostics.CommonAssembly
Google.Cloud.Diagnostics.Common.dll
Remarks
Ensures the trace context is propagated for outgoing HTTP requests and traces the total time of the outgoing HTTP request. This is only done if tracing is initialized and tracing is enabled for the current request.
Explicitly leaves unset the InnerHandler property so that this Handler can be used with the System.Net.Http.IHttpClientFactory defined in Microsoft.Extensions.Http.
Constructors
UnchainedTraceHeaderPropagatingHandler(Func<IManagedTracer>)
public UnchainedTraceHeaderPropagatingHandler(Func<IManagedTracer> managedTracerFactory)
Constructs a new instance using the given delegate to obtain the "current" tracer on each request.
Parameter | |
---|---|
Name | Description |
managedTracerFactory | Func<IManagedTracer> A delegate used to obtain the "current" tracer for each request. The delegate should therefore be thread-safe. |
UnchainedTraceHeaderPropagatingHandler(Func<IManagedTracer>, Action<HttpRequestMessage, ITraceContext>)
public UnchainedTraceHeaderPropagatingHandler(Func<IManagedTracer> managedTracerFactory, Action<HttpRequestMessage, ITraceContext> traceContextPropagator)
Constructs a new instance using the given delegate to obtain the "current" tracer on each request.
Parameters | |
---|---|
Name | Description |
managedTracerFactory | Func<IManagedTracer> A delegate used to obtain the "current" tracer for each request. The delegate should therefore be thread-safe. |
traceContextPropagator | Action<HttpRequestMessage, ITraceContext> The trace context propagator used to set the trace context on the outgoing HTTP request. May be null, in which case the Google Trace Header will be set. |
Methods
SendAsync(HttpRequestMessage, CancellationToken)
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
Sends the given request. If tracing is initialized and enabled the outgoing request is traced and the trace context is propagated.
Parameters | |
---|---|
Name | Description |
request | HttpRequestMessage |
cancellationToken | CancellationToken |
Returns | |
---|---|
Type | Description |
Task<HttpResponseMessage> |