Skip to content

InMemoryTraceStore

Namespace AgentPrism · Assembly AgentPrism.Core.dll

A store that keeps spans in process memory.

public sealed class InMemoryTraceStore : ITraceStore

objectInMemoryTraceStore

ITraceStore

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

Limits: process lifetime, one node, and limited capacity. When InMemoryTraceStore.MaxTraces is exceeded, it removes the oldest trace. Use AgentPrism.PostgreSql in production.

Reads are limited to the current tenant. Writes take the tenant from the batch, while reads take it from ITenantContext. This is the same rule as the SQL implementation.

Initializes a new in-memory span store.

public InMemoryTraceStore(ITenantContext? tenantContext = null)

tenantContext ITenantContext?

The current tenant context. If omitted, the store behaves as single tenant.

The maximum number of traces to keep in memory.

public int MaxTraces { get; init; }

int

GetTraceByRunAsync(Guid, CancellationToken)

Section titled “ GetTraceByRunAsync(Guid, CancellationToken)”

Fetches a run’s span tree.

public ValueTask<RunTrace?> GetTraceByRunAsync(Guid runId, CancellationToken cancellationToken = default)

runId Guid

The run identifier.

cancellationToken CancellationToken

The cancellation token.

ValueTask<RunTrace?>

The trace; null if no record exists.

WriteSpansAsync(TraceSpanBatch, CancellationToken)

Section titled “ WriteSpansAsync(TraceSpanBatch, CancellationToken)”

Writes a trace’s spans. Can be called multiple times for the same trace; spans are merged by identifier.

public ValueTask WriteSpansAsync(TraceSpanBatch batch, CancellationToken cancellationToken = default)

batch TraceSpanBatch

The span set to write.

cancellationToken CancellationToken

The cancellation token.

ValueTask

The completion task.