Google.Cloud.Diagnostics.Common - Class TraceHeaderContext (5.2.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

Google.Cloud.Diagnostics.Common

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
Type Description
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
Type Description
bool

SpanId

public ulong? SpanId { get; }

The span id or null if none is available.

Property Value
Type Description
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
Type Description
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
Name Description
traceId string
spanId ulong
shouldTrace bool
Returns
Type Description
TraceHeaderContext

FromHeader(string)

public static TraceHeaderContext FromHeader(string header)

Creates a TraceHeaderContext from a header.

Parameter
Name Description
header string

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

Returns
Type Description
TraceHeaderContext

FromHeader(string, Func<bool?>)

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

Creates a TraceHeaderContext from a header.

Parameters
Name Description
header string

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

traceFallbackPredicate Funcbool

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

Returns
Type Description
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
Type Description
string
Overrides