Class UnchainedTraceHeaderPropagatingHandler (4.3.1)

public class UnchainedTraceHeaderPropagatingHandler : DelegatingHandler, IDisposable

Class for tracing outgoing HTTP requests and propagating the trace context.

Inheritance

Object > HttpMessageHandler > DelegatingHandler > UnchainedTraceHeaderPropagatingHandler

Implements

IDisposable

Namespace

Google.Cloud.Diagnostics.Common

Assembly

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
NameDescription
managedTracerFactoryFunc<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
NameDescription
managedTracerFactoryFunc<IManagedTracer>

A delegate used to obtain the "current" tracer for each request. The delegate should therefore be thread-safe.

traceContextPropagatorAction<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
NameDescription
requestHttpRequestMessage
cancellationTokenCancellationToken
Returns
TypeDescription
Task<HttpResponseMessage>
Overrides