Skip to content

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.

Install

Create a project and install the Node package:

Terminal
npm init -y
npm install @pydantic/logfire-node

Set your Logfire write token in the environment:

Terminal
export LOGFIRE_TOKEN="your-write-token"

Send a Span

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:

Terminal
node hello.mjs

The span and nested log event will appear in your Logfire project.

Runtime Packages

Use the package that owns SDK setup for your runtime:

@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.