Add Pydantic Logfire observability to application code — traces, logs, metrics, and AI/agent spans. Use when the user asks to add or configure Logfire, observability, tracing, logging, or monitoring; maximize useful telemetry; or understand what an app is doing. Supports Python, JavaScript/TypeScript, Rust, and major AI agent frameworks including Pydantic AI, OpenAI Agents SDK, Claude Agent SDK, LangChain, LangGraph, CrewAI, AutoGen, and Google ADK. For infrastructure-only monitoring (hosts, Docker, Kubernetes, databases, or cloud metrics with no app-code changes), use `logfire-infrastructure`. For evaluating AI/agent behavior against test datasets, use `logfire-evals`.
Use this for edge runtimes that are not ordinary Node.js servers.
Cloudflare Workers
Install:
npm install @pydantic/logfire-cf-workers logfire
Enable Node.js compatibility:
{
"compatibility_flags": ["nodejs_compat"]
}
For wrangler.toml:
compatibility_flags = ["nodejs_compat"]
Set local development values in .dev.vars. Workers don't auto-read .logfire/logfire_credentials.json the way Python's SDK does, but the token in it is still the one to reuse here rather than minting a new one — see auth.md's "If the calling skill needs a write token" section:
Store production tokens as Worker secrets, minted separately from Project Settings → Write tokens (a long-lived deployed Worker shouldn't share a credential with your local CLI session):
npx wrangler secret put LOGFIRE_TOKEN
Wrap the exported handler. Import manual spans and logs from logfire.
If wrapping a business function, avoid the name collision by aliasing:
import { instrument as instrumentFunction } from 'logfire'
import { instrument as instrumentWorker } from '@pydantic/logfire-cf-workers'
Cloudflare export is tied to request lifetime through ctx.waitUntil(). Use ctx.waitUntil() for asynchronous work that should be included in request-lifetime telemetry.
Cloudflare Tail Workers
For Tail Worker flows, use instrumentTail() in the producer Worker and exportTailEventsToLogfire() in the Tail Worker. Follow the SDK examples when wiring producer and tail projects; do not improvise the event shape.
Deno
Deno has built-in OpenTelemetry support. Configure OTLP export to Logfire and use the core package for manual spans. Deno is a generic-OpenTelemetry setup like any non-native-SDK language — for the write token in the header below, reuse what projects use already created rather than minting a new one; see auth.md's "If the calling skill needs a write token" section: