Skip to main content
Logfire for TypeScript

TypeScript observability with OpenTelemetry

OpenTelemetry-native observability for any TypeScript or Node.js app, from the team behind Pydantic. A first-party SDK, automatic instrumentation for the libraries you already use, and SQL over everything it collects. Free for 10 million spans, logs, and metrics a month.

Start free with TypeScript As Markdown
Getting started

One file to your first trace

npm install @pydantic/logfire-node @opentelemetry/auto-instrumentations-node
export LOGFIRE_TOKEN=your-write-token   # Settings > Write tokens
// instrumentation.ts
import * as logfire from '@pydantic/logfire-node'

logfire.configure({
  serviceName: 'my-app',
  serviceVersion: '1.0.0',
  environment: 'production',
})
npx tsx --import ./instrumentation.ts server.ts

The instrumentation file has to load first. Automatic instrumentation wraps each library as Node loads it, so anything imported before logfire.configure() runs is never patched. Full details are in the TypeScript setup guide.

What you get

One request, one trace

A Logfire trace of a Node request: undici, the Express router, pg queries and the outbound call, with an errored request below

What lands in Logfire:

  • the undici and http spans for the request
  • the Express router span, with the matched route
  • every pg query and pool checkout, timed
  • your own spans, nested where you opened them
  • a 404 marked red, at the span that produced it
Your code

Trace your own logic

await logfire.span('process-order', {
  callback: async () => {
    logfire.info('Order processed')
  },
})

Spans nest inside whatever is already open, so your own operations sit in the same trace as the request and queries that triggered them. Call await logfire.shutdown() before a short-lived script exits so pending telemetry is flushed.

How it works

Instrument the edges, see the whole request

A first-party SDK, not a generic exporter

Logfire ships maintained TypeScript packages: @pydantic/logfire-node for the server, plus browser and Cloudflare Workers builds. You configure a service and start tracing, rather than assembling an OpenTelemetry exporter, a resource, and a tracer provider by hand.

Automatic instrumentation for the libraries you already use

Add @opentelemetry/auto-instrumentations-node and your HTTP server, database driver, and outbound calls become spans without touching their call sites. Every incoming request opens a trace, and the work inside it is attached as timed child spans.

Load order is the whole game, and we document it

Automatic instrumentation wraps each library as Node loads it, which is why the instrumentation file must load first, and why bundling breaks it. Rather than pretend one snippet works everywhere, there are specific guides for Express, Next.js, Deno, and the Vercel AI SDK.

The widest agent-framework coverage outside Python

Mastra, the Vercel AI SDK, VoltAgent, LangChain.js, LangGraph.js and LlamaIndex.TS all send telemetry to Logfire, so your agent runs and model calls land in the same traces as the HTTP requests and queries around them. Pick your framework on its merits, not on what your observability tool happens to support.

Traces, metrics, and logs in one place

Logfire is not just tracing. Send metrics and structured logs alongside your traces, build dashboards, and set alerts, all in the same OpenTelemetry-native project, and query all of it with the same SQL.

OpenTelemetry-native, no lock-in

Because Logfire speaks OpenTelemetry natively, standard OTel instrumentation and manual spans work unchanged, and you can send the same data to another backend or self-host without touching your instrumentation. Your instrumentation is an asset you own, not rented from a vendor.

Query

Query your telemetry with SQL

select
  attributes->>'http.route' as route,
  count(*) as requests,
  avg(duration) as avg_seconds
from records
where duration > 1
group by route
order by avg_seconds desc;

Your traces, metrics, and logs are queryable with real SQL, no proprietary query language to learn. Any question you can express becomes a dashboard, an alert, or a one-off investigation.

Proof

In production

“You can tell that Pydantic Logfire was built by people who use it.”
Dennis Griffin, VP of Engineering, Sophos Read the case study
Decision guide

Is Logfire right for you?

Choose Logfire if

  • You want a maintained TypeScript SDK rather than assembling OTel by hand
  • You want your existing libraries traced automatically, not instrumented one by one
  • You run Next.js, Express, Deno, or Cloudflare Workers and want setup that accounts for bundling
  • You want to query traces, metrics, and logs with PostgreSQL-compatible SQL
  • You want the portability of OpenTelemetry rather than a proprietary agent

Choose a traditional APM if

  • You are already deeply integrated with a specific APM vendor's ecosystem
  • You need a vendor-only integration or compliance capability Logfire does not offer
  • You want one vendor's agent and dashboards, and are comfortable with their pricing model
FAQ

Common questions

How do I add OpenTelemetry to a Node.js application?

Install @pydantic/logfire-node, create an instrumentation.ts file that calls logfire.configure() with your service name, and load that file before your application starts, for example with npx tsx --import ./instrumentation.ts server.ts. Add @opentelemetry/auto-instrumentations-node and the libraries you already use are traced automatically.

Why are no automatic traces showing up?

Almost always load order or bundling. Automatic instrumentation wraps each library as Node loads it, so the instrumentation file has to load before anything it is meant to patch. Bundlers also prevent automatic traces from working because modules are inlined rather than loaded at runtime; in that case follow the framework-specific guide instead of the generic setup.

Does this work with Next.js, Express, Deno, or the Vercel AI SDK?

Yes. Each has its own guide, because how and when you load the instrumentation differs by framework and bundler. The underlying SDK is the same; only the loading strategy changes.

Do I need to flush telemetry before my process exits?

For short-lived scripts, yes. Call await logfire.shutdown() before exit so buffered spans are sent. Long-running servers export continuously in the background and do not need this on every request.

Is Pydantic Logfire locked to a proprietary format?

No. Logfire is built on OpenTelemetry, the open industry standard. Standard OTel instrumentation works unchanged, your instrumentation is portable to any OTel-compatible backend, and you can self-host without rewriting it.

Start seeing your TypeScript app

Get started with 10 million free spans, logs, and metrics per month. No credit card required.