Prerequisites: A working FrontMCP server with at least one tool. See Your First Tool if you need to get started.
What You’ll Get
- Automatic spans for every tool call, resource read, auth flow, and HTTP request
- Structured JSON logs with trace correlation (
trace_id,span_id) this.telemetryAPI for custom spans in your tools and plugins- Per-request log aggregation
Step 1: Install
@opentelemetry/api as the only hard dependency (~50KB). OTel SDK packages are optional peers — install only what you need.
Step 2: Enable Observability
Add theobservability field to your @FrontMcp config:
Step 3: Configure a Backend
The
@FrontMcp({ ... }) snippets below show only the observability block for brevity. Your full config still needs info: { name, version } and the rest of your server fields.- Console (Dev)
- OTLP (Any Backend)
- Coralogix
- Datadog
- Logz.io
- Winston
- Pino
See spans printed to your terminal — great for development:
Step 4: Use this.telemetry in Tools
Every execution context (tools, resources, prompts, agents) gets a this.telemetry API when observability is enabled. No context construction: it inherits the current request’s trace.
observability: true installs this.telemetry at runtime, but its type comes from @frontmcp/observability, which declares it on ExecutionContextBase and PromptContext with a declare module '@frontmcp/sdk' augmentation. TypeScript applies that augmentation only when the package is part of the compilation, so import it in the file that uses this.telemetry (a type-only import is enough, and is erased at runtime), or once in any file the project compiles, such as the server entry:
Step 5: Structured Logging
Whenlogging is enabled, every this.logger.info() call produces a structured JSON entry with automatic trace correlation:
Step 6: Request Log Collection
EnablerequestLogs to get a complete aggregated view of each request:
onRequestComplete once with the HTTP method and path, the JSON-RPC method, the tool, resource or prompt it served,
the entries logged while it ran, its status (error for an HTTP status of 400 or more, or when the tool, resource or
prompt failed, with the failure in error; status_code is the status the server actually answered with, a 401 from
authentication or a 429 from the throttle included) and its duration. The callback runs off the response path: the
response is sent without waiting for it. Up to 1.9.1 the callback never fired.
A tool, resource or prompt that fails ends its spans with an error status, the execution span included; up to 1.9.1 a
failed tool’s span was left open and never exported. The “tracing enabled but no TracerProvider configured” warning
appears only when no provider is registered; up to 1.9.1 it appeared even after setupOTel() or another SDK
registered one.
Step 7: Testing with Telemetry
Use the built-in testing utilities to verify your spans:Span Hierarchy
Every request produces a span tree like this:Attributes Reference
MCP Protocol Attributes (interoperable)
Standard OTel Attributes
FrontMCP Vendor Attributes
Best Practices
1. Use this.telemetry for custom instrumentation
1. Use this.telemetry for custom instrumentation
Don’t create spans with raw OTel API. Use
this.telemetry.withSpan() or this.telemetry.startSpan() — they automatically inherit the trace context and add base attributes.2. Add events, not child spans, for lightweight markers
2. Add events, not child spans, for lightweight markers
this.telemetry.addEvent('step-done') is cheaper than this.telemetry.startSpan('step'). Use events for milestones, spans for timed operations.3. Redact sensitive fields in structured logs
3. Redact sensitive fields in structured logs
Always configure
redactFields in production: ['password', 'token', 'secret', 'authorization', 'cookie'].4. Use OTLP for vendor integrations
4. Use OTLP for vendor integrations
The
otlp sink type works with all major platforms (Coralogix, Datadog, Logz.io, Grafana). Don’t build vendor-specific integrations.5. Don't over-instrument
5. Don't over-instrument
The auto-instrumentation covers all SDK flows. Only add
this.telemetry spans for your business logic operations (API calls, database queries, complex processing).Next Steps
Telemetry API Reference
Full API docs for TelemetryAccessor, TelemetrySpan, and testing utilities
Rate Limiting
Add rate limiting alongside observability for production readiness