Skip to main content
The 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 as this.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.
You must call 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()).
Events are lightweight markers that appear on the parent span’s timeline. Use them for milestones rather than creating child spans.
Events go on the active execution span, not a new span. If called during tool.execute(), they appear on the "tool my_tool" span. If called outside an execution context, a short-lived child span is created as a fallback.

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 by startSpan() and passed to withSpan() callbacks. All setter methods return this for chaining.

Methods


Counters (Metrics)

Counters are cumulative, monotonically-increasing metrics. Unlike spans (which describe one request) or events (which mark a point on a span), counters aggregate across many requests and are scraped by your monitoring backend at a steady cadence.

createCounter(name, description?)

Built-in skill counters

When skillsConfig.enabled: true is set on @FrontMcp, the framework emits the following counters automatically: The framework also emits a skill.bundle.swap span (with source, bundle_id, version, skill_count, from_version attributes), and adds skill_search.query, skill_search.results, and skill_action.phase events to the active flow span when the skill HTTP catalog is exercised.

Wiring a MeterProvider

Counters become observable once you register a global OTel MeterProvider. Without one, counters still increment in an in-memory snapshot (getMetricSnapshot() from @frontmcp/observability) intended for tests and local debugging only.

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: { ... } }):

TracingOptions

SinkConfig


Observability Guide

Step-by-step setup with vendor integrations

Observability Feature

Overview of what FrontMCP observability provides