Class TraceHeaderContext (4.4.0)

public sealed class TraceHeaderContext : ITraceContext

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
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
Nullable<Boolean>

SpanId

public ulong? SpanId { get; }

The span id or null if none is available.

Property Value
TypeDescription
Nullable<UInt64>
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, Nullable<UInt64>, Nullable<Boolean>)

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

Creates a TraceHeaderContext from a trace and span id.

Parameters
NameDescription
traceIdString
spanIdNullable<UInt64>
shouldTraceNullable<Boolean>
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<Nullable<Boolean>>)

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

traceFallbackPredicateFunc<Nullable<Boolean>>

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