Class InMemoryTracer
- Namespace
- LMKit.Agents.Observability
- Assembly
- LM-Kit.NET.dll
A tracer that stores spans in memory for inspection.
Useful for testing, debugging, and building custom trace visualizations.
public sealed class InMemoryTracer : IAgentTracer
- Inheritance
-
InMemoryTracer
- Implements
- Inherited Members
Examples
var tracer = new InMemoryTracer();
AgentTracing.SetTracer(tracer);
// Execute agents...
// Inspect traces
foreach (var span in tracer.GetSpans())
{
Console.WriteLine($"{span.OperationName}: {span.Duration?.TotalMilliseconds}ms");
}
Properties
- MaxLogs
Gets or sets the maximum number of log entries to retain.
- MaxSpans
Gets or sets the maximum number of spans to retain.
Set to 0 for unlimited. Default is 1000.
- SpanCount
Gets the number of spans currently stored.
Methods
- Clear()
Clears all stored spans, metrics, and logs.
- GetLogs()
Gets all log entries.
- GetLogs(LogLevel)
Gets log entries at or above the specified level.
- GetMetrics()
Gets all recorded metrics.
- GetSpans()
Gets all completed spans.
- GetSpans(Func<AgentSpan, bool>)
Gets spans matching a filter.
- GetSpansByKind(SpanKind)
Gets spans of a specific kind.
- GetSummary()
Gets a summary of the stored traces.
- GetTraceSpans(string)
Gets spans for a specific trace.
- Log(LogLevel, string, AgentSpan)
Records a log message associated with a span.
- RecordMetric(string, double, Dictionary<string, string>)
Records a metric value.
- StartAgentSpan(Agent, string, AgentSpan)
Starts a new span for an agent execution.
- StartDelegationSpan(string, string, AgentSpan)
Starts a new span for a delegation operation.
- StartInferenceSpan(string, AgentSpan)
Starts a new span for a model inference call.
- StartOrchestrationSpan(string, string)
Starts a new span for an orchestration operation.
- StartPlanningSpan(PlanningStrategy, AgentSpan)
Starts a new span for a planning operation.
- StartToolSpan(string, string, AgentSpan)
Starts a new span for a tool invocation.