Class TraceHeaderContext
Context from the Cloud Trace Header.
Inheritance
Inherited Members
Namespace: Google.Cloud.Diagnostics.Common
Assembly: Google.Cloud.Diagnostics.Common.dll
Syntax
public sealed class TraceHeaderContext
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
The trace header.
Declaration
public const string TraceHeader = "X-Cloud-Trace-Context"
Field Value
| Type | Description |
|---|---|
| System.String |
Properties
ShouldTrace
True if the request should be traced, false if it should not be. Null if the trace header does not indicate whether or not it should be traced.
Declaration
public bool? ShouldTrace { get; }
Property Value
| Type | Description |
|---|---|
| System.Nullable<System.Boolean> |
SpanId
Gets the span id or null if none is available.
Declaration
public ulong? SpanId { get; }
Property Value
| Type | Description |
|---|---|
| System.Nullable<System.UInt64> |
TraceId
Gets the trace id or null if none is available.
Declaration
public string TraceId { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Methods
Create(String, Nullable<UInt64>, Nullable<Boolean>)
Creates a TraceHeaderContext from a trace and span id.
Declaration
public static TraceHeaderContext Create(string traceId, ulong? spanId, bool? shouldTrace)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | traceId | |
| System.Nullable<System.UInt64> | spanId | |
| System.Nullable<System.Boolean> | shouldTrace |
Returns
| Type | Description |
|---|---|
| TraceHeaderContext |
FromHeader(String)
Creates a TraceHeaderContext from a header.
Declaration
public static TraceHeaderContext FromHeader(string header)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | header | 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<Nullable<Boolean>>)
Creates a TraceHeaderContext from a header.
Declaration
public static TraceHeaderContext FromHeader(string header, Func<bool?> traceFallbackPredicate)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | header | The string value of the trace header. Can be null. See: https://cloud.google.com/trace/docs/faq |
| System.Func<System.Nullable<System.Boolean>> | traceFallbackPredicate | Optional function to override and trace requests. Can be null. |
Returns
| Type | Description |
|---|---|
| TraceHeaderContext |
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.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String |