<PackageReference Include="OpenTelemetry.Api" Version="1.15.2" />

OpenTelemetry.Trace.TelemetrySpan

public class TelemetrySpan : IDisposable
Span represents a single operation within a trace.
public SpanContext Context { get; }

Gets the span context.

public bool IsRecording { get; }

Gets a value indicating whether this span will be recorded.

public ActivitySpanId ParentSpanId { get; }

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

public TelemetrySpan AddEvent(string name)

Adds a single Event to the TelemetrySpan.

public TelemetrySpan AddEvent(string name, DateTimeOffset timestamp)

Adds a single Event to the TelemetrySpan.

public TelemetrySpan AddEvent(string name, SpanAttributes attributes)

Adds a single Event to the TelemetrySpan.

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

Adds a single Event to the TelemetrySpan.

public TelemetrySpan AddLink(SpanContext spanContext)

Adds a link to another span.

public TelemetrySpan AddLink(SpanContext spanContext, SpanAttributes attributes)

Adds a link to another span.

public void Dispose()

protected virtual void Dispose(bool disposing)

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

public void End()

End the span.

public void End(DateTimeOffset endTimestamp)

End the span.

Record Exception.

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

Record Exception.

public TelemetrySpan SetAttribute(string key, string value)

Sets a new attribute on the span.

public TelemetrySpan SetAttribute(string key, int value)

Sets a new attribute on the span.

public TelemetrySpan SetAttribute(string key, bool value)

Sets a new attribute on the span.

public TelemetrySpan SetAttribute(string key, double value)

Sets a new attribute on the span.

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

Sets a new attribute on the span.

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

Sets a new attribute on the span.

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

Sets a new attribute on the span.

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

Sets a new attribute on the span.

public void SetStatus(Status value)

Sets the status of the span execution.

public TelemetrySpan UpdateName(string name)

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.