API reference for this.telemetry — custom spans, events, and attributes in execution contexts
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.
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.
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.
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.
Audit log records dropped (queue overflow / write failure)
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.
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.
import { metrics } from '@opentelemetry/api';import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';import { Resource } from '@opentelemetry/resources';import { MeterProvider, PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';const meterProvider = new MeterProvider({ resource: new Resource({ 'service.name': 'my-mcp-server' }), readers: [ new PeriodicExportingMetricReader({ exporter: new OTLPMetricExporter({ url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? 'http://localhost:4318/v1/metrics', }), exportIntervalMillis: 10_000, }), ],});metrics.setGlobalMeterProvider(meterProvider);