RunTraceCollector
AgentPrism.Core.dllListens to AgentPrism spans, buffers them per run, and writes them to ITraceStore when the run completes, based on the sampling decision.
public sealed class RunTraceCollector : IDisposableInheritance
Section titled “Inheritance”Implements
Section titled “Implements”Inherited Members
Section titled “Inherited Members”object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
Section titled “Remarks”Why scoped to a run’s lifetime? Spans are spread out over time and there is no general way to know a trace has ended; a timeout-based buffer produces both leaks and late writes. Here, the owner of the buffer is RunRecordingAgent: it opens the run, closes it, and drains the buffer in both cases (success or failure). A leak is therefore structurally impossible.
Why sample at the end? The spans of failed runs are the most valuable input for debugging, but whether a run will fail is not known at the start. The decision is made at the end; the cost of this is that spans are held in memory until then, bounded by AgentPrismObservabilityOptions.MaxSpansPerRun.
Does not take over the stream. Diagnostics.ActivityListener
is a passive listener; the consumer’s own OpenTelemetry SDK keeps sending
the same spans to its own exporter.
Constructors
Section titled “Constructors”RunTraceCollector(ITraceStore, IOptions<AgentPrismOptions>, ILogger<RunTraceCollector>)
Section titled “ RunTraceCollector(ITraceStore, IOptions<AgentPrismOptions>, ILogger<RunTraceCollector>)”Creates a new collector and starts listening.
public RunTraceCollector(ITraceStore store, IOptions<AgentPrismOptions> options, ILogger<RunTraceCollector> logger)Parameters
Section titled “Parameters”store ITraceStore
Span store.
options IOptions<AgentPrismOptions>
AgentPrism settings.
logger ILogger<RunTraceCollector>
Logger.
Exceptions
Section titled “Exceptions”One of the dependencies is null.
Properties
Section titled “Properties”IsCollecting
Section titled “ IsCollecting”Whether the collector is persisting spans.
public bool IsCollecting { get; }Property Value
Section titled “Property Value”Methods
Section titled “Methods”BeginRun(string, string)
Section titled “ BeginRun(string, string)”Starts collecting spans for a run.
public bool BeginRun(string traceId, string rootSpanId)Parameters
Section titled “Parameters”traceId string
The W3C trace id of the run’s root span.
rootSpanId string
The span id of the activity this run opened. A trace id is inherited from the incoming request, so it alone does not identify one run.
Returns
Section titled “Returns”false when collection is disabled or this run is already being tracked.
CompleteRunAsync(string, string, Guid, string, RunStatus, CancellationToken)
Section titled “ CompleteRunAsync(string, string, Guid, string, RunStatus, CancellationToken)”Ends collection and writes the spans if the sampling decision is positive. The buffer is released in every case.
public ValueTask<bool> CompleteRunAsync(string traceId, string rootSpanId, Guid runId, string tenantId, RunStatus status, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”traceId string
The W3C trace id of the root span.
rootSpanId string
The span id of the activity this run opened.
runId Guid
Run identifier.
tenantId string
Tenant identifier.
status RunStatus
The run’s final status.
cancellationToken CancellationToken
Cancellation token.
Returns
Section titled “Returns”true when spans were written.
Dispose()
Section titled “ Dispose()”public void Dispose()