Table of Contents

Class TelemetrySpan

Namespace
OpenTelemetry.Trace
Assembly
OpenTelemetry.Api.dll

Span represents a single operation within a trace.

public class TelemetrySpan : IDisposable
Inheritance
TelemetrySpan
Implements
Inherited Members

Remarks

TelemetrySpan is a wrapper around OpenTelemetry.Trace.TelemetrySpan.Activity class.

Properties

Context

Gets the span context.

public SpanContext Context { get; }

Property Value

SpanContext

IsRecording

Gets a value indicating whether this span will be recorded.

public bool IsRecording { get; }

Property Value

bool

ParentSpanId

Gets the identity of the parent span id, if any.

public ActivitySpanId ParentSpanId { get; }

Property Value

ActivitySpanId

Methods

AddEvent(string)

Adds a single Event to the TelemetrySpan.

public TelemetrySpan AddEvent(string name)

Parameters

name string

Name of the event.

Returns

TelemetrySpan

The TelemetrySpan instance for chaining.

AddEvent(string, SpanAttributes)

Adds a single Event to the TelemetrySpan.

public TelemetrySpan AddEvent(string name, SpanAttributes attributes)

Parameters

name string

Name of the event.

attributes SpanAttributes

Attributes for the event.

Returns

TelemetrySpan

The TelemetrySpan instance for chaining.

AddEvent(string, DateTimeOffset)

Adds a single Event to the TelemetrySpan.

public TelemetrySpan AddEvent(string name, DateTimeOffset timestamp)

Parameters

name string

Name of the event.

timestamp DateTimeOffset

Timestamp of the event.

Returns

TelemetrySpan

The TelemetrySpan instance for chaining.

AddEvent(string, DateTimeOffset, SpanAttributes)

Adds a single Event to the TelemetrySpan.

public TelemetrySpan AddEvent(string name, DateTimeOffset timestamp, SpanAttributes attributes)

Parameters

name string

Name of the event.

timestamp DateTimeOffset

Timestamp of the event.

attributes SpanAttributes

Attributes for the event.

Returns

TelemetrySpan

The TelemetrySpan instance for chaining.

Dispose()

public void Dispose()

Dispose(bool)

Releases the unmanaged resources used by this class and optionally releases the managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

End()

End the span.

public void End()

End(DateTimeOffset)

End the span.

public void End(DateTimeOffset endTimestamp)

Parameters

endTimestamp DateTimeOffset

End timestamp.

RecordException(Exception)

Record Exception.

public TelemetrySpan RecordException(Exception ex)

Parameters

ex Exception

Exception to be recorded.

Returns

TelemetrySpan

The TelemetrySpan instance for chaining.

RecordException(string, string, string)

Record Exception.

public TelemetrySpan RecordException(string type, string message, string stacktrace)

Parameters

type string

Type of the exception to be recorded.

message string

Message of the exception to be recorded.

stacktrace string

Stacktrace of the exception to be recorded.

Returns

TelemetrySpan

The TelemetrySpan instance for chaining.

SetAttribute(string, bool)

Sets a new attribute on the span.

public TelemetrySpan SetAttribute(string key, bool value)

Parameters

key string

Attribute key.

value bool

Attribute value.

Returns

TelemetrySpan

The TelemetrySpan instance for chaining.

SetAttribute(string, bool[])

Sets a new attribute on the span.

public TelemetrySpan SetAttribute(string key, bool[] values)

Parameters

key string

Attribute key.

values bool[]

Attribute values.

Returns

TelemetrySpan

The TelemetrySpan instance for chaining.

SetAttribute(string, double)

Sets a new attribute on the span.

public TelemetrySpan SetAttribute(string key, double value)

Parameters

key string

Attribute key.

value double

Attribute value.

Returns

TelemetrySpan

The TelemetrySpan instance for chaining.

SetAttribute(string, double[])

Sets a new attribute on the span.

public TelemetrySpan SetAttribute(string key, double[] values)

Parameters

key string

Attribute key.

values double[]

Attribute values.

Returns

TelemetrySpan

The TelemetrySpan instance for chaining.

SetAttribute(string, int)

Sets a new attribute on the span.

public TelemetrySpan SetAttribute(string key, int value)

Parameters

key string

Attribute key.

value int

Attribute value.

Returns

TelemetrySpan

The TelemetrySpan instance for chaining.

SetAttribute(string, int[])

Sets a new attribute on the span.

public TelemetrySpan SetAttribute(string key, int[] values)

Parameters

key string

Attribute key.

values int[]

Attribute values.

Returns

TelemetrySpan

The TelemetrySpan instance for chaining.

SetAttribute(string, string)

Sets a new attribute on the span.

public TelemetrySpan SetAttribute(string key, string value)

Parameters

key string

Attribute key.

value string

Attribute value.

Returns

TelemetrySpan

The TelemetrySpan instance for chaining.

SetAttribute(string, string[])

Sets a new attribute on the span.

public TelemetrySpan SetAttribute(string key, string[] values)

Parameters

key string

Attribute key.

values string[]

Attribute values.

Returns

TelemetrySpan

The TelemetrySpan instance for chaining.

SetStatus(Status)

Sets the status of the span execution.

public void SetStatus(Status value)

Parameters

value Status

Status to be set.

UpdateName(string)

Updates the TelemetrySpan name.

If used, this will override the name provided via StartSpan method overload. Upon this update, any sampling behavior based on TelemetrySpan name will depend on the implementation.

public TelemetrySpan UpdateName(string name)

Parameters

name string

Name of the span.

Returns

TelemetrySpan

The TelemetrySpan instance for chaining.