# TraceSpan

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.tracespan/
> Summary: TraceSpan: A single persisted OpenTelemetry span.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Abstractions.dll</code></div>

A single persisted OpenTelemetry span.

```csharp
public sealed record TraceSpan : IEquatable<TraceSpan>
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.tracespan/">TraceSpan</a></dd><dt>Implements</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.iequatable-1">IEquatable&lt;TraceSpan&gt;</a></dd><dt>Inherited Members</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Remarks

[TraceSpan.Id](/api/tracon.tracespan/#Tracon_TraceSpan_Id) and [TraceSpan.ParentId](/api/tracon.tracespan/#Tracon_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](/api/tracon.tracespan/#Tracon_TraceSpan_SpanId)
field: this is needed so the user can find the same span in their own APM
system (Jaeger, Application Insights).

## Constructors

### <a id="Tracon_TraceSpan__ctor"></a> TraceSpan\(\)

```csharp
public TraceSpan()
```

## Properties

### <a id="Tracon_TraceSpan_Attributes"></a> Attributes

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

```csharp
public IReadOnlyDictionary<string, string> Attributes { get; init; }
```

#### Property Value

 [IReadOnlyDictionary](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlydictionary\-2)<[string](https://learn.microsoft.com/dotnet/api/system.string), [string](https://learn.microsoft.com/dotnet/api/system.string)\>

### <a id="Tracon_TraceSpan_Duration"></a> Duration

The span's duration. [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if the span has not ended.

```csharp
[JsonIgnore]
public TimeSpan? Duration { get; }
```

#### Property Value

 [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan)?

### <a id="Tracon_TraceSpan_EndedAt"></a> EndedAt

The end time (UTC).

```csharp
public DateTimeOffset? EndedAt { get; init; }
```

#### Property Value

 [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset)?

### <a id="Tracon_TraceSpan_Id"></a> Id

The database identifier. Derived from the W3C identifiers.

```csharp
public required Guid Id { get; init; }
```

#### Property Value

 [Guid](https://learn.microsoft.com/dotnet/api/system.guid)

### <a id="Tracon_TraceSpan_Kind"></a> Kind

The span kind.

```csharp
public TraceSpanKind Kind { get; init; }
```

#### Property Value

 [TraceSpanKind](/api/tracon.tracespankind/)

### <a id="Tracon_TraceSpan_Name"></a> Name

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

```csharp
public required string Name { get; init; }
```

#### Property Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)

### <a id="Tracon_TraceSpan_ParentId"></a> ParentId

The parent span's database identifier. [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) for the root span.

```csharp
public Guid? ParentId { get; init; }
```

#### Property Value

 [Guid](https://learn.microsoft.com/dotnet/api/system.guid)?

### <a id="Tracon_TraceSpan_SpanId"></a> SpanId

The W3C span identifier (16-character hex).

```csharp
public required string SpanId { get; init; }
```

#### Property Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)

### <a id="Tracon_TraceSpan_StartedAt"></a> StartedAt

The start time (UTC).

```csharp
public required DateTimeOffset StartedAt { get; init; }
```

#### Property Value

 [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset)

### <a id="Tracon_TraceSpan_Status"></a> Status

The result status.

```csharp
public TraceSpanStatus Status { get; init; }
```

#### Property Value

 [TraceSpanStatus](/api/tracon.tracespanstatus/)

## Methods

### <a id="Tracon_TraceSpan_Equals_System_Object_"></a> Equals\(object?\)

```csharp
public override bool Equals(object? obj)
```

#### Parameters

`obj` [object](https://learn.microsoft.com/dotnet/api/system.object)?

#### Returns

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### <a id="Tracon_TraceSpan_Equals_Tracon_TraceSpan_"></a> Equals\(TraceSpan?\)

```csharp
public bool Equals(TraceSpan? other)
```

#### Parameters

`other` [TraceSpan](/api/tracon.tracespan/)?

#### Returns

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### <a id="Tracon_TraceSpan_GetHashCode"></a> GetHashCode\(\)

```csharp
public override int GetHashCode()
```

#### Returns

 [int](https://learn.microsoft.com/dotnet/api/system.int32)

### <a id="Tracon_TraceSpan_ToString"></a> ToString\(\)

```csharp
public override string ToString()
```

#### Returns

 [string](https://learn.microsoft.com/dotnet/api/system.string)

## Operators

### <a id="Tracon_TraceSpan_op_Equality_Tracon_TraceSpan_Tracon_TraceSpan_"></a> operator ==\(TraceSpan?, TraceSpan?\)

```csharp
public static bool operator ==(TraceSpan? left, TraceSpan? right)
```

#### Parameters

`left` [TraceSpan](/api/tracon.tracespan/)?

`right` [TraceSpan](/api/tracon.tracespan/)?

#### Returns

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### <a id="Tracon_TraceSpan_op_Inequality_Tracon_TraceSpan_Tracon_TraceSpan_"></a> operator \!=\(TraceSpan?, TraceSpan?\)

```csharp
public static bool operator !=(TraceSpan? left, TraceSpan? right)
```

#### Parameters

`left` [TraceSpan](/api/tracon.tracespan/)?

`right` [TraceSpan](/api/tracon.tracespan/)?

#### Returns

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)
