Google.Cloud.Diagnostics.Common - Class TraceHeaderContext (5.1.0)

public sealed class TraceHeaderContext : ITraceContext

Reference documentation and code samples for the Google.Cloud.Diagnostics.Common class TraceHeaderContext.

Context from the Google Cloud Trace Header.

Inheritance

object > TraceHeaderContext

Implements

ITraceContext

Namespace

GoogleCloudGoogle.Cloud.DiagnosticsCommon

Assembly

Google.Cloud.Diagnostics.Common.dll

Remarks

A trace can be forced by passing information along in the trace header ("X-Cloud-Trace-Context"). The trace id, parent span id and whether or not to trace can be set. See: https://cloud.google.com/trace/docs/faq#how_do_i_force_a_request_to_be_traced

Fields

TraceHeader

public const string TraceHeader = "X-Cloud-Trace-Context"

The trace header.

Field Value
TypeDescription
string

Properties

ShouldTrace

public bool? ShouldTrace { get; }

Whether this request should be traced or not. May be null, which means that there's not enough information to know whether this request should be traced or not.

Property Value
TypeDescription
bool

SpanId

public ulong? SpanId { get; }

The span id or null if none is available.

Property Value
TypeDescription
ulong
Remarks

This corresponds to the span_id field of the TraceSpan message in the API. See https://cloud.google.com/trace/docs/reference/v2/rpc/google.devtools.cloudtrace.v1#tracespan for more information.

TraceId

public string TraceId { get; }

The trace id or null if none is available.

Property Value
TypeDescription
string
Remarks

This corresponds to the trace_id field of the Trace message in the API. See https://cloud.google.com/trace/docs/reference/v2/rpc/google.devtools.cloudtrace.v1#trace for more information.

Methods

Create(string, ulong?, bool?)

public static TraceHeaderContext Create(string traceId, ulong? spanId, bool? shouldTrace)

Creates a TraceHeaderContext from a trace and span id.

Parameters
NameDescription
traceIdstring
spanIdulong
shouldTracebool
Returns
TypeDescription
TraceHeaderContext

FromHeader(string)

public static TraceHeaderContext FromHeader(string header)

Creates a TraceHeaderContext from a header.

Parameter
NameDescription
headerstring

The string value of the trace header. Can be null. See: https://cloud.google.com/trace/docs/faq

Returns
TypeDescription
TraceHeaderContext

FromHeader(string, Func<bool?>)

public static TraceHeaderContext FromHeader(string header, Func<bool?> traceFallbackPredicate)

Creates a TraceHeaderContext from a header.

Parameters
NameDescription
headerstring

The string value of the trace header. Can be null. See: https://cloud.google.com/trace/docs/faq

traceFallbackPredicateFuncbool

Optional function to override and trace requests. Can be null.

Returns
TypeDescription
TraceHeaderContext

ToString()

public override string ToString()

Gets the TraceHeaderContext as a string. Formatted as "[trace-id]/[span-id];o=[should-trace]" where "should-trace" is 1 to trace and 0 otherwise.

Returns
TypeDescription
string
Overrides