Generated banner for Logfire Frontend
Generated logo for Logfire Frontend

Logfire Frontend

PydanticOfficialPublished by Pydantic

  • Skill
  • Tool integration
  • Software development
  • MIT
  • No issues found

From the author

Set up and troubleshoot Pydantic Logfire frontend observability and session replays in JavaScript/TypeScript browser applications. Use for browser errors, RUM, Web Vitals, replay recording, privacy controls, or reducing browser telemetry volume. Supports browser entrypoints, React/Vite, and the client side of Next.js; use logfire-instrumentation for server-side telemetry.
— the description by Pydantic

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides guidance on configuring Pydantic Logfire for browser-based applications using the @pydantic/logfire-browser and @pydantic/logfire-session-replay SDKs. It covers setup procedures for React, Vite, and Next.js, alongside strategies for managing observability signals, including Web Vitals, error tracking, and session replay recording. The skill emphasizes proper credential usage, privacy controls through data masking, and selecting appropriate capture profiles to balance telemetry volume with diagnostic needs.

What it does

  • Configures frontend observability using Logfire browser SDKs.
  • Implements session replay with configurable privacy masking and input blocking.
  • Supports integration with React, Vite, and Next.js client-side environments.
  • Provides capture profiles for varying levels of instrumentation and performance overhead.
  • Guides the setup of error tracking and Web Vitals monitoring.
  • Offers verification steps to ensure telemetry ingestion and replay playback.

When to use it

  • When you need to monitor browser-side errors and user interactions.
  • When you want to record user sessions for debugging complex frontend issues.
  • When you need to track Web Vitals and performance metrics in a web application.
  • When you need to reduce browser telemetry volume while maintaining critical error visibility.

Advantages

  • Enables end-to-end visibility by linking browser sessions to backend traces.
  • Provides granular control over data privacy through text and input masking.
  • Offers flexible capture profiles to optimize for performance or detail.
  • Integrates seamlessly with modern frontend frameworks like Next.js and React.

Usage examples

“How do I set up basic frontend observability in my React application?”
The agent provides the installation commands for @pydantic/logfire-browser and shows how to initialize the configuration in your main entrypoint before rendering the root component.
“How can I enable session replay while masking sensitive user input?”
The agent guides you to install the session replay package and configure the integration with maskAllInputs: true and blockSelector options to protect sensitive regions.
“I need to reduce the amount of telemetry data my frontend sends. What are my options?”
The agent explains the 'Minimal errors and replays' capture profile, showing how to disable automatic spans and RUM signals while keeping essential error reporting.

Install

  1. Download the skill as a ZIP:

    https://autogineer.com/agent-skills/pydantic/logfire-frontend/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip logfire-frontend.zip -d .agents/skills

Documentation by Pydantic

Set Up Frontend Observability and Session Replays

The application uses @pydantic/logfire-browser and, when replay is requested, @pydantic/logfire-session-replay. Configure one browser provider; preserve an existing OpenTelemetry provider, proxy, and application initialization pattern.

Confirm the browser application

Read repository instructions, the application manifest, browser entrypoint, router, and existing instrumentation. For Next.js, distinguish client code from server instrumentation before changing either. Respect dependency constraints; check the installed SDK's types before using a capture or sampling option.

Preserve the exact origin, organization, and project supplied by the user or setup handoff. Browser-only setup does not require a CLI login, a local SDK credential, or an ordinary project write token. Use existing native MCP access for verification when available; otherwise use the Logfire UI.

Create or select the frontend application under Frontend → Applications and use its generated regional URL and restricted frontend token. A normal project write token, server environment variable, or .logfire credential is unsuitable for browser code. The frontend application owns service identity. If no supported public API/tool can manage it, use the UI; do not invent a private endpoint.

Match capture to the request

Read browser setup, then the applicable section of capture profiles:

  • Full frontend observability: automatic page/request/interaction spans and Web Vitals. Add replay only when requested.

  • Errors and replays with automatic instrumentation: retain traces with Logfire error-level events or OpenTelemetry error status, while keeping replay independently enabled. This also retains other spans in a qualifying trace.

  • Minimal errors and replays: disable automatic spans and Web Vitals and explicitly report application errors. Use when the user requires lower browser instrumentation overhead or strictly limits the signals collected.

Preserve existing approved replay rates and masking. Trace sampling, replay sampling, and metric capture are separate decisions. Do not promise that minLevel filters automatic spans, that a trace sampler retains an entire browser session, or that every handled application failure is captured automatically.

Session replay is Early Access; check availability for the target organization and keep an existing application rollout flag. Mask text and inputs, leave console capture off, and block sensitive regions before recording them. Review attributes and URLs separately from visible-text masking. Add normalized route templates and opaque user IDs only when useful; names and emails are optional personal data.

Verify the selected behavior

Use verification and troubleshooting to exercise the real browser application, check the signals retained and omitted, query fresh errors in the exact project, and play the matching recording. For a sampling profile, test successful requests and the failure types the user cares about; inspect actual exported spans rather than assuming how HTTP status maps to error severity.

Run the application's normal typecheck/build and focused tests. Report browser execution, telemetry ingestion, and replay playback separately. A successful build, flush, upload response, or generated link does not prove all three. Return the verified project/application, capture policy, and a clean relevant UI link. If account reads or browser playback are unavailable, mark those parts unverified and state what evidence is missing.

For server-side Node.js or Next.js setup, use application instrumentation.

Files

references/setup.md

Browser Setup

Configure in a browser entrypoint before the application renders or makes requests. Use the application's package manager and compatible SDK versions. For tracing/RUM, install @pydantic/logfire-browser; install the replay package only when the user wants replay:

npm install @pydantic/logfire-browser
# When replay is requested:
npm install @pydantic/logfire-session-replay

One browser configuration

Copy baseUrl and the restricted token from Frontend → Applications. Keep the actual region and frontend application selected by the user. The following browser-only module enables full RUM and replay; adjust its one configuration using capture profiles before running it.

This example requires browser SDK 0.28.0 or later. If Frontend → Applications is unavailable, explain the missing prerequisite and link to Logfire support; do not substitute an ordinary server write token.

import * as logfire from '@pydantic/logfire-browser'
import { sessionReplayIntegration } from '@pydantic/logfire-session-replay/integration'

const frontendOptions = {
  baseUrl: '<generated-regional-base-url>',
  token: '<restricted-frontend-application-token>',
}

export const frontend = logfire.configureFrontend({
  ...frontendOptions,
  sessionReplay: sessionReplayIntegration({
    maskAllText: true,
    maskAllInputs: true,
    captureConsole: false,
    blockSelector: '[data-logfire-block]',
  }),
})

Omit sessionReplay and its import for RUM-only setup. The replay sampling rates are deliberately omitted above: preserve an existing policy or choose one with the user. Do not imply that every session will be recorded merely because replay is enabled. Add data-logfire-block to regions that should not appear in replay; do not replace an existing block selector and lose its protected regions.

The current SDK captures uncaught JavaScript errors and unhandled promise rejections by default. Do not add duplicate global listeners. Framework error boundaries and caught exceptions need explicit logfire.reportError() calls. Preserve existing error reporting without reporting the same failure twice. Review error messages and added attributes for sensitive values separately from replay masking.

configureFrontend() enables automatic instrumentation and Web Vitals metrics by default. Replay is opt-in, implies browser session identity, and shares session.id with browser spans. Do not set browser serviceName or environment to imitate a backend service; the frontend application pins those at ingest.

The configuration handle is immediate, but automatic instrumentation and replay load lazily. Do not assume the first request or error has a recording just because configuration returned. Verify that startup completes before exercising the behavior whose coverage matters.

React, Vite, and Next.js

  • React/Vite: import the browser-only module from the client entrypoint before createRoot(). Module initialization is shared; React Strict Mode does not repeat it when checking effects.

  • Next.js: use instrumentation-client.ts when the installed Next.js version supports it. Import the browser module there, keeping server instrumentation separate. For older versions, dynamically import it from a root Client Component's effect so it executes only in the browser. Repeated imports must resolve to the same module/provider, rather than configuring in every mount.

  • Other browser frameworks: use their browser entrypoint and current router state. Do not call configuration during SSR, SSG, or a component render.

In Next.js, import a Client Component normally from its Server Component. If using next/dynamic with ssr: false, put that dynamic import inside a Client Component; Next.js rejects it directly in a Server Component.

Keep instrumentation for the application's page lifetime. Do not return the async SDK shutdown handle from a React effect: Strict Mode cleanup would stop the shared provider. Tests/previews that replace the setup must remove any caller-owned error listeners, await SDK cleanup, and reset initialization guards before a new configuration. Prefer a page reload when development HMR re-executes the setup.

See Next.js client instrumentation and React Strict Mode for the framework's initialization and effect behavior.

Browser instrumentation does not emit automatic pending-span placeholders. Add startPendingSpan() only for a specific long operation; avoid high-volume manual spans for each mouse movement, render, or keystroke. Enable diagnostic logging only while troubleshooting, not in a deployed browser configuration.

Routes and user identity

Every single-page application should set rum.session.getRouteName. Without it, each id in a URL makes a separate page, so /projects/1 and /projects/2 show as two rows in page tables, filters, and Web Vitals breakdowns.

Use @pydantic/logfire-browser 0.28.0 or later for the router helpers. Use the helper for the app's router and add it to the existing configureFrontend() call:

RouterImportgetRouteName value
React Router 7 or 8 with createBrowserRouter or <BrowserRouter> (6 expected to work, not tested)reactRouterRouteName from @pydantic/logfire-browser/react-routerreactRouterRouteName({ routes, matchRoutes, basename })
TanStack Router (tested with React; Solid and Vue share its core, not tested)tanStackRouterRouteName from @pydantic/logfire-browser/tanstack-routertanStackRouterRouteName(router)
Vue Router 4 or 5vueRouterRouteName from @pydantic/logfire-browser/vue-routervueRouterRouteName(router)
import { reactRouterRouteName } from '@pydantic/logfire-browser/react-router'
import { createBrowserRouter, matchRoutes } from 'react-router'

const router = createBrowserRouter(routes)

logfire.configureFrontend({
  baseUrl: '<generated-regional-base-url>',
  token: '<frontend-application-token>',
  rum: { session: { getRouteName: reactRouterRouteName({ matchRoutes, routes }) } },
})

Pass React Router the same routes as the router, and its basename when it has one. In React Router 6, import from react-router-dom instead of react-router. The React Router helper does not support hash or memory routers. If the TanStack or Vue router is created after configureFrontend(), pass () => router. Do not write a callback that reads router.state.matches or router.currentRoute: router state keeps the previous route during back and forward navigation.

For other routers, follow the browser SDK guide's route-name contract: return the matched route template such as /projects/:id, never the concrete path; return a fixed name such as /* for not-found routes; keep the callback synchronous; and return undefined until the first route resolves.

For Next.js, use the SDK guide's Pages Router or App Router recipe; there is no Next.js-specific SDK helper. Do not guess templates by stripping URL segments.

rum.session.getUser may return an opaque { id } for the current user. Return undefined on logout. Include name/email only when requested and appropriate. Keep getSessionAttributes bounded, low-cardinality, and free of personal data. These client-asserted fields are observational context, never access control.

Privacy and transport

Keep text/input masking on and console capture off unless broader capture is requested. Masking does not scrub DOM attributes, CSS content, resource URLs, or custom events. Block affected subtrees and sanitize app-owned payloads. Default URL handling removes query strings/fragments; do not restore them accidentally when adding custom page attributes.

The restricted frontend token is designed to be public. Preserve an existing proxy or first-party ingest domain when present. Add a proxy only when the application needs its authentication, origin policy, or rate limits. A proxy must support replay separately from OTLP traces/metrics and retain gzip bytes and their content headers. Python's telemetry forwarding helpers do not forward replay. Keep exporters and recorder from capturing their own upload requests.

When maintaining a proxy, validate each request's Origin against an explicitly configured allowed origin. Reject missing configuration, missing Origin, or a mismatch; never derive the allowed value from the incoming request. Preserve authentication and rate limits: origin validation alone is not authentication.

Source: browser SDK configuration and replay integration.

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Published by
Pydantic
Publisher
Pydantic (Official)
Source
pydantic/skills · skills/logfire-frontend · commit 98f591c
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced
Also distributed in
pydantic/skills

AutoGineer is not affiliated with or endorsed by Pydantic or Pydantic.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download logfire-frontend.zip