Table of Contents

Struct SpanContext

Namespace
OpenTelemetry.Trace
Assembly
OpenTelemetry.Api.dll

A struct that represents a span context. A span context contains the portion of a span that must propagate to child TelemetrySpan and across process boundaries. It contains the identifiers System.Diagnostics.ActivityTraceIdand System.Diagnostics.ActivitySpanId associated with the TelemetrySpan along with a set of common TraceFlags and system-specific TraceState values>.

public readonly struct SpanContext : IEquatable<SpanContext>
Implements
Inherited Members

Remarks

SpanContext is a wrapper around ActivityContext.

Constructors

SpanContext(in ActivityContext)

Initializes a new instance of the SpanContext struct with the given identifiers and options.

public SpanContext(in ActivityContext activityContext)

Parameters

activityContext ActivityContext

The activity context.

SpanContext(in ActivityTraceId, in ActivitySpanId, ActivityTraceFlags, bool, IEnumerable<KeyValuePair<string, string>>)

Initializes a new instance of the SpanContext struct with the given identifiers and options.

public SpanContext(in ActivityTraceId traceId, in ActivitySpanId spanId, ActivityTraceFlags traceFlags, bool isRemote = false, IEnumerable<KeyValuePair<string, string>> traceState = null)

Parameters

traceId ActivityTraceId

The System.Diagnostics.ActivityTraceId to associate with the SpanContext.

spanId ActivitySpanId

The System.Diagnostics.ActivitySpanId to associate with the SpanContext.

traceFlags ActivityTraceFlags

The TraceFlags to associate with the SpanContext.

isRemote bool

The value indicating whether this SpanContext was propagated from the remote parent.

traceState IEnumerable<KeyValuePair<string, string>>

The traceState to associate with the SpanContext.

Properties

IsRemote

Gets a value indicating whether this SpanContext was propagated from a remote parent.

public bool IsRemote { get; }

Property Value

bool

IsValid

Gets a value indicating whether this SpanContext is valid.

public bool IsValid { get; }

Property Value

bool

SpanId

Gets the System.Diagnostics.ActivitySpanId associated with this SpanContext.

public ActivitySpanId SpanId { get; }

Property Value

ActivitySpanId

TraceFlags

Gets the System.Diagnostics.ActivityTraceFlags associated with this SpanContext.

public ActivityTraceFlags TraceFlags { get; }

Property Value

ActivityTraceFlags

TraceId

Gets the System.Diagnostics.ActivityTraceId associated with this SpanContext.

public ActivityTraceId TraceId { get; }

Property Value

ActivityTraceId

TraceState

Gets the TraceState associated with this SpanContext.

public IEnumerable<KeyValuePair<string, string>> TraceState { get; }

Property Value

IEnumerable<KeyValuePair<string, string>>

Methods

Equals(SpanContext)

public bool Equals(SpanContext other)

Parameters

other SpanContext

Returns

bool

Equals(object)

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

Operators

operator ==(SpanContext, SpanContext)

Compare two SpanContext for equality.

public static bool operator ==(SpanContext spanContext1, SpanContext spanContext2)

Parameters

spanContext1 SpanContext

First SpanContext to compare.

spanContext2 SpanContext

Second SpanContext to compare.

Returns

bool

implicit operator ActivityContext(SpanContext)

Converts a SpanContext into an ActivityContext.

public static implicit operator ActivityContext(SpanContext spanContext)

Parameters

spanContext SpanContext

SpanContext source.

Returns

ActivityContext

operator !=(SpanContext, SpanContext)

Compare two SpanContext for not equality.

public static bool operator !=(SpanContext spanContext1, SpanContext spanContext2)

Parameters

spanContext1 SpanContext

First SpanContext to compare.

spanContext2 SpanContext

Second SpanContext to compare.

Returns

bool