TheDocumentation Index
Fetch the complete documentation index at: https://docs.agentfront.dev/llms.txt
Use this file to discover all available pages before exploring further.
this.telemetry API is available on all execution contexts (ToolContext, ResourceContext, PromptContext, AgentContext) when observability is enabled. It provides a simple interface for creating custom spans, recording events, and setting attributes — with automatic trace context propagation.
Requires
@frontmcp/observability installed and observability config enabled. See the Observability Guide for setup.TelemetryAccessor
Available asthis.telemetry in all execution contexts. One instance per request (context-scoped). Automatically inherits the current request’s trace ID, session ID, and scope.
startSpan(name, attributes?)
Create a child span under the current execution span.
span.end() or span.endWithError() when done.
withSpan(name, fn, attributes?)
Run a function within a span. The span is automatically ended on success or error.
addEvent(name, attributes?)
Add an event to the active flow execution span (e.g., the tool span during execute()).
setAttributes(attrs)
Set attributes on the active flow execution span.
traceId
Get the current request’s trace ID. Useful for including in external API calls or logs.
sessionId
Get the privacy-safe session tracing ID (16-char SHA-256 hash).
TelemetrySpan
Returned bystartSpan() and passed to withSpan() callbacks. All setter methods return this for chaining.
Methods
| Method | Signature | Description |
|---|---|---|
setAttribute | (key: string, value: string | number | boolean) => this | Set a single attribute |
setAttributes | (attrs: Record<string, string | number | boolean>) => this | Set multiple attributes |
addEvent | (name: string, attributes?: Record<...>) => this | Add a named event |
recordError | (error: Error) => this | Record an exception on the span |
end | () => void | End the span with OK status |
endWithError | (error: Error | string) => void | End with ERROR status |
raw | Span (getter) | Access the underlying OTel Span |
Testing Utilities
Import from@frontmcp/observability:
createTestTracer(name?)
Create an isolated test tracer with in-memory span exporter. Does not register globally — safe for parallel tests.
assertSpanExists(spans, name)
Assert that a span with the given name exists. Returns the span or throws.
assertSpanAttribute(span, key, value)
Assert a span has a specific attribute value.
findSpan(spans, name) / findSpansByAttribute(spans, key, value)
Query helpers for finding spans in test assertions.
Configuration Types
ObservabilityOptionsInterface
The config object for@FrontMcp({ observability: { ... } }):
| Property | Type | Default | Description |
|---|---|---|---|
tracing | boolean | TracingOptions | true | Enable/configure OTel tracing |
logging | boolean | LoggingOptions | false | Enable/configure structured logging |
requestLogs | boolean | RequestLogOptions | false | Enable/configure per-request log collection |
TracingOptions
| Property | Type | Default | Description |
|---|---|---|---|
httpSpans | boolean | true | HTTP request spans |
executionSpans | boolean | true | Tool/resource/prompt/agent spans |
fetchSpans | boolean | true | Outbound ctx.fetch() spans |
flowStageEvents | boolean | true | Flow stage events on execution spans |
hookSpans | boolean | false | Individual hook spans (verbose) |
transportSpans | boolean | true | SSE/HTTP transport spans |
authSpans | boolean | true | Auth/session verify spans |
oauthSpans | boolean | true | OAuth flow spans |
elicitationSpans | boolean | true | Elicitation request/result spans |
startupReport | boolean | true | Emit startup telemetry on first request |
SinkConfig
| Type | Description | Platform |
|---|---|---|
{ type: 'stdout' } | NDJSON to stdout (12-factor) | Node.js |
{ type: 'console' } | console.log/warn/error | Browser, Node.js |
{ type: 'otlp', endpoint, headers? } | OTLP HTTP to any backend | Node.js |
{ type: 'winston', logger } | Forward to winston instance | Node.js |
{ type: 'pino', logger } | Forward to pino instance | Node.js |
{ type: 'callback', fn } | Custom callback function | Any |
Related
Observability Guide
Step-by-step setup with vendor integrations
Observability Feature
Overview of what FrontMCP observability provides