Getting Started
The fastest way to try the TypeScript SDK is a small Node.js script. You need a Logfire write token, Node.js 24 or newer, and a package manager such as npm or pnpm.
Create a project and install the Node package:
npm init -y
npm install @pydantic/logfire-node
Set your Logfire write token in the environment:
export LOGFIRE_TOKEN="your-write-token"
Create hello.mjs:
import * as logfire from '@pydantic/logfire-node'
logfire.configure({
serviceName: 'hello-logfire-js',
serviceVersion: '1.0.0',
})
await logfire.span('calculate checkout total', {
attributes: { cart_id: 'cart_123', item_count: 3 },
callback: async () => {
logfire.info('checkout total calculated', { total: 42.5 })
},
})
await logfire.forceFlush()
await logfire.shutdown()
Run it:
node hello.mjs
The span and nested log event will appear in your Logfire project.
Use the package that owns SDK setup for your runtime:
- Node.js scripts and servers:
@pydantic/logfire-node - Browser clients:
@pydantic/logfire-browser - Cloudflare Workers:
@pydantic/logfire-cf-workers - Runtime-agnostic manual API only:
logfire
@pydantic/logfire-node and @pydantic/logfire-browser re-export the logfire manual API, so a single import suffices in those runtimes. With @pydantic/logfire-cf-workers, import spans and logs from logfire alongside instrument from the Workers package.