loading…
Search for a command to run...
loading…
OpenTelemetry instrumentation for Model Context Protocol (MCP) with distributed tracing support
OpenTelemetry instrumentation for Model Context Protocol (MCP) with distributed tracing support
npm version npm subscribers License: MIT
Write once, observe everywhere.
Instrument your Node.js code a single time, keep the DX you love, and stream traces, metrics, logs, and product events to any observability stack without vendor lock-in.
One init(), wrap functions with trace(), and get automatic traces, metrics, and events:
import { init, trace, track } from 'autotel';
import { PostHogSubscriber, SlackSubscriber } from 'autotel-subscribers';
// Initialize once at startup
init({
service: 'checkout-api',
devtools: true, // Local traces + metrics + logs in autotel-devtools
subscribers: [
new PostHogSubscriber({ apiKey: process.env.POSTHOG_KEY! }),
new SlackSubscriber({ webhookUrl: process.env.SLACK_WEBHOOK! }),
],
});
// Wrap any function - automatic spans, error tracking, and context
export const processOrder = trace(async function processOrder(
orderId: string,
amount: number,
) {
const user = await db.users.findById(orderId);
const payment = await chargeCard(user.cardId, amount);
// Product events automatically enriched with trace context
// Sent to: OTLP + PostHog + Slack (all in one call!)
track('order.completed', { orderId, amount, userId: user.id });
return payment;
});
That's it. Every call to processOrder() now:
traceId and spanId to all adapters→ See complete examples and API docs
autotel ships 35 Agent Skills for AI assistants (Claude Code, Cursor, Windsurf, Continue, …) — one per package plus a flagship "review-otel-patterns" skill that surveys 13+ frameworks. Skills are auto-discovered by compatible agents.
npx skills add https://github.com/jagreehal/autotel
Or browse the skills/ directory directly. Highlights:
See skills/README.md for the full index.
This monorepo contains the following packages:
Core library providing ergonomic OpenTelemetry instrumentation with:
trace(), span(), and decoratorsProduct events subscribers for:
→ View subscribers documentation
Edge runtime support for:
Composable framework DX adapters on top of autotel core:
useLogger(...) style ergonomics for framework handlerswithAutotel(...) wrappers for Next/Nitro-style handler DXparseError() and drain pipeline compositionAudit-focused helpers for compliance logging with automatic tail-sampling bypass:
withAudit(...) — Structured audit metadata with automatic outcome taggingforceKeepAuditEvent(...) — Ensure critical audit trails bypass tail-drop samplingsetAuditAttributes(...) — Normalized audit.* span attributesMigration Guide - Migrate from vanilla OpenTelemetry to autotel:
Typical migration: Replace NODE_OPTIONS and 30+ lines of SDK boilerplate with init(), wrap functions with trace() instead of manual span.start()/span.end().
npm install autotel
# Optional: Add event subscribers (PostHog, Slack, Mixpanel, etc.)
npm install autotel-subscribers
# Optional but recommended for local DX
npm install -D autotel-devtools
# or
pnpm add autotel
pnpm add autotel-subscribers # Optional
pnpm add -D autotel-devtools # Optional but recommended
For the fastest feedback loop, run local devtools and point autotel at it:
import { init, trace } from 'autotel';
init({
service: 'my-app',
devtools: true,
});
const result = await trace(async () => 'success')();
That gives you:
init() surface you can later point at Grafana, Datadog, or any OTLP backendIf you want autotel to boot the local devtools server for you:
init({
service: 'my-app',
devtools: { embedded: true },
});
This requires autotel-devtools to be installed. If it is not installed, autotel falls back to http://127.0.0.1:4318.
See traces instantly during development - perfect for progressive development:
import { init, trace } from 'autotel';
// Start with console-only (no backend needed)
init({
service: 'my-app',
debug: true // Outputs spans to console
});
// Your traced functions work as normal
const result = await trace(async () => {
// Your code here
return 'success';
})();
// Span printed to console automatically!
How it works:
debug: true - Print spans to console AND send to backend (if endpoint configured)Or use environment variable:
AUTOTEL_DEBUG=true node server.js
Configure autotel using standard OpenTelemetry environment variables:
export OTEL_SERVICE_NAME=my-app
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
export OTEL_EXPORTER_OTLP_HEADERS=x-honeycomb-team=YOUR_API_KEY
export OTEL_RESOURCE_ATTRIBUTES=deployment.environment=production
For local development, devtools: true is usually a better default than setting OTEL_EXPORTER_OTLP_ENDPOINT manually.
Then call init() without any config - it picks up env vars automatically:
init({ service: 'my-app' }); // Minimal config, env vars fill the rest
→ See complete environment variable documentation
# Clone and install dependencies
git clone https://github.com/jagreehal/autotel.git
cd autotel
pnpm install
# Build all packages
pnpm build
# Run tests
pnpm test
# Run example apps
pnpm --filter @jagreehal/example-basic start
pnpm --filter @jagreehal/example-http start
autotel/
├── packages/
│ ├── autotel/ # Core library
│ ├── autotel-subscribers/ # Event subscribers
│ └── autotel-edge/ # Edge runtime support
├── apps/
│ ├── example-basic/ # Basic usage example
│ ├── example-http/ # Express server example
│ └── cloudflare-example/ # Cloudflare Workers example
└── turbo.json # Turborepo configuration
# Development
pnpm dev # Watch mode for all packages
pnpm build # Build all packages
pnpm test # Run all tests
pnpm test:integration # Run integration tests
# Code quality
pnpm lint # Lint all packages
pnpm format # Format code with Prettier
pnpm type-check # TypeScript type checking
# Releases
pnpm changeset # Create a changeset
pnpm version-packages # Version packages
pnpm release # Publish to npm
pnpm --filter @jagreehal/example-basic start
pnpm --filter @jagreehal/example-http start
pnpm --filter cloudflare-example dev
We welcome contributions! Please see our contributing guidelines for details.
git checkout -b feature/my-featurepnpm testpnpm changesetgit commit -am "Add new feature"git push origin feature/my-featureWe use changesets for version management:
pnpm changeset
Follow the prompts to:
Autotel is built on top of OpenTelemetry and provides:
| Challenge | With autotel |
|---|---|
| Raw OpenTelemetry is verbose | One-line trace() wrapper with automatic lifecycle |
| Vendor SDKs create lock-in | OTLP-native, works with any backend |
| Need both observability & events | Unified API for traces, metrics, logs, and events |
| Production safety concerns | Built-in sampling, rate limiting, redaction |
Having issues seeing your traces? Use ConsoleSpanExporter for visual debugging or InMemorySpanExporter for testing. See the full troubleshooting guide in the detailed docs.
MIT - See LICENSE for details.
Add this to claude_desktop_config.json and restart Claude Desktop.
{
"mcpServers": {
"autotel-mcp-instrumentation": {
"command": "npx",
"args": [
"-y",
"autotel-mcp-instrumentation"
]
}
}
}pro tip
Just installed Autotel Mcp Instrumentation? Say to Claude: "remember why I installed Autotel Mcp Instrumentationand what I want to try" — it'll save into your Vault.
how this works →