Skip to content

TraceSpan

Namespace AgentPrism · Assembly AgentPrism.Abstractions.dll

A single persisted OpenTelemetry span.

public sealed record TraceSpan : IEquatable<TraceSpan>

objectTraceSpan

IEquatable<TraceSpan>

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

TraceSpan.Id and TraceSpan.ParentId are derived from the W3C identifiers, not randomly generated. When a span completes, its parent may not have completed yet, and the parent’s database identifier is unknown. Deriving it (trace_id + span_id → SHA-256 → first 16 bytes) makes matching work without a map and without ordering; writing the same span twice also produces the same identifier.

The W3C identifiers are stored separately in the TraceSpan.SpanId field: this is needed so the user can find the same span in their own APM system (Jaeger, Application Insights).

public TraceSpan()

The span attributes. GenAI semantic convention keys (gen_ai.request.model, gen_ai.usage.input_tokens) go here.

public IReadOnlyDictionary<string, string> Attributes { get; init; }

IReadOnlyDictionary<string, string>

The span’s duration. null if the span has not ended.

[JsonIgnore]
public TimeSpan? Duration { get; }

TimeSpan?

The end time (UTC).

public DateTimeOffset? EndedAt { get; init; }

DateTimeOffset?

The database identifier. Derived from the W3C identifiers.

public required Guid Id { get; init; }

Guid

The span kind.

public TraceSpanKind Kind { get; init; }

TraceSpanKind

The span name. Example: chat gpt-5.4-mini, invoke_agent support.

public required string Name { get; init; }

string

The parent span’s database identifier. null for the root span.

public Guid? ParentId { get; init; }

Guid?

The W3C span identifier (16-character hex).

public required string SpanId { get; init; }

string

The start time (UTC).

public required DateTimeOffset StartedAt { get; init; }

DateTimeOffset

The result status.

public TraceSpanStatus Status { get; init; }

TraceSpanStatus

public override bool Equals(object? obj)

obj object?

bool

public bool Equals(TraceSpan? other)

other TraceSpan?

bool

public override int GetHashCode()

int

public override string ToString()

string

public static bool operator ==(TraceSpan? left, TraceSpan? right)

left TraceSpan?

right TraceSpan?

bool

public static bool operator !=(TraceSpan? left, TraceSpan? right)

left TraceSpan?

right TraceSpan?

bool