Class UnchainedTraceHeaderPropagatingHandler

[Obsolete("Use Google.Cloud.Diagnostics.Common.HttpClientBuilderExtensions.AddOutgoingGoogleTraceHandler insted. For more information see https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests")]
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.

UnchainedTraceHeaderPropagatingHandler(Func<IManagedTracer>, Action<HttpRequestMessage, ITraceContext>, IDictionary<String, String>)

public UnchainedTraceHeaderPropagatingHandler(Func<IManagedTracer> managedTracerFactory, Action<HttpRequestMessage, ITraceContext> traceContextPropagator, IDictionary<string, string> customLabels)

Constructs a new instance using the given delegate to obtain the "current" tracer on each request and annotates the trace with the given custom labels, if any.

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.

customLabelsIDictionary<String, String>

Custom labels to annotate the trace with. May be null or empty, in which case the trace won't be annotated with any custom labels.

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