Pydantic Logfire Documentation

repository·main·Indexed 26 days ago

https://github.com/pydantic/logfire

An observability platform for Python developers that provides insights into Python objects, event loops, profiling, and database queries. It serves as an opinionated wrapper around OpenTelemetry and includes a Python SDK, a JavaScript SDK, and the logfire-api shim for optional library integrations.

Tokens
201.3K
Snippets
416
Records
935
Agent score
89%

What's inside Pydantic Logfire

  1. Overview of Pydantic Logfire capabilities

    main

    Pydantic Logfire is an AI-native observability platform designed to provide full-stack visibility into AI applications. Unlike AI-only tools, Logfire correlates LLM calls with the surrounding application context, such as HTTP requests, database queries, and business logic.

    Key capabilities include:

    • Full-stack AI observability: Contextualized traces including LLM calls, APIs, and databases.
    • OpenTelemetry-based: Compatible with any language or framework that supports OpenTelemetry.
    • LLM-specific features: Token tracking, cost monitoring, conversation inspection, and tool call visibility.
    • SQL-based querying: Query observability data using PostgreSQL-compatible syntax via the Apache DataFusion engine.
  2. Overview of Enterprise Dedicated Single Tenant Deployment

    main

    Enterprise Dedicated is a fully managed, single-tenant deployment of Logfire. It provides a fully isolated environment for each tenant, including a dedicated virtual network, managed Kubernetes cluster, managed database, and object storage. This ensures complete data separation.

    Key features:

    • Configurable Region: Choose deployment regions based on latency, data residency, or compliance needs.
    • Managed Infrastructure: Pydantic handles all provisioning, upgrades, and operations.
    • Cloud Support: Currently supports GCP (Google Cloud Platform). Additional providers are planned.
    • Access: Customers access their dedicated instance via a unique hostname.
  3. Overview of Logfire Dashboards

    main

    Logfire dashboards allow you to visualize observability data using SQL-powered charts and tables. There are two types of dashboards available:

    • Standard dashboards: Pre-configured and maintained by the Logfire team. They provide continuous updates and improvements. You can enable or disable them for your project, but they cannot be modified directly.
    • Custom dashboards: Fully editable and customizable dashboards created by you. You can define your own queries, layouts, chart types, and variables.

    It is recommended to start with standard dashboards and then use them as templates for custom dashboards if they do not meet your specific needs.

  4. Choose a Pydantic Logfire Enterprise offering

    main

    Pydantic Logfire provides three enterprise-tier deployment models depending on your organization's compliance, infrastructure, and management needs:

    • Enterprise Cloud: A fully managed, SLA-backed SaaS service. Best for organizations needing custom retention, custom SSO, and industry-specific compliance (like HIPAA BAAs).
    • Enterprise Dedicated: A fully managed, single-tenant deployment on isolated infrastructure.
    • Enterprise Self-Hosted: An on-premises deployment via Kubernetes. Best for organizations with strict data sovereignty or highly sensitive data requirements.

    To inquire about these plans, contact the sales team at sales@pydantic.dev.

  5. Compare Logfire vs Braintrust

    main

    Logfire and Braintrust are both observability platforms for AI applications, but they serve different primary purposes:

    Logfire

    • Primary Focus: AI observability for agents and full-stack applications.
    • Strengths: Production monitoring, debugging, and full-stack visibility (AI + application monitoring).
    • Instrumentation: Native support for non-AI components (databases, APIs, etc.) via OpenTelemetry.
    • Evaluation: Code-first approach using pydantic-evals, allowing version-controlled, type-safe evaluations that run in CI/CD or locally.
    • Data Analysis: Supports complex, PostgreSQL-compatible SQL queries for ad-hoc analysis and agentic debugging.

    Braintrust

    • Primary Focus: AI evaluation and testing.
    • Strengths: Prompt iteration and structured evaluation workflows.
    • Instrumentation: Primarily focused on the LLM layer; non-AI instrumentation requires manual OpenTelemetry setup.
    • Evaluation: UI-driven workflows for defining and running evaluations.
    • Data Analysis: Optimized for evaluation workflows with a custom query interface (BQL for complex joins).
  6. Understand AI observability concepts: Traces and Spans

    main

    When monitoring AI agents and LLM calls, Logfire uses two primary concepts to organize data:

    • Trace: The full, complete record of a single request or agent run.
    • Span: An individual step or unit of work contained within a trace (e.g., a single model call or a tool execution).
  7. Understand Logfire Prompt Management

    main

    Logfire Prompt Management allows you to author, version, test, and ship LLM prompts directly from the Logfire UI. Instead of hardcoding prompts in your application code, you treat them as first-class configuration objects that your application fetches via the Logfire SDK.

    The Production Workflow:

    1. Author a prompt template in the Logfire UI.
    2. Save versions to freeze the template text as you iterate.
    3. Test using scenarios (saved test cases), datasets (sweeping scenarios over many cases), and runs (execution records).
    4. Promote a version by pointing a label (e.g., production) at a specific version on the Managed Variables page.
    5. Consume the prompt in your application using the Logfire SDK, which fetches the version associated with your specified label or rollout targeting.
  8. Understand the AI evaluation scaffold

    main

    Logfire uses a five-part scaffold to build offline evaluations. Understanding these components is essential for setting up repeatable tests for your AI system:

    1. Dataset: A collection of test cases (inputs and optional expected outputs).
    2. Task: The AI system under test (e.g., a function, an LLM call, or a Pydantic AI agent).
    3. Scorers (evaluators): Judges attached to the task that produce a score. Scorers can be code-based (exact match), LLM-as-a-judge, or human-based.
    4. Score: The individual rating produced by a scorer for a specific output.
    5. Experiment: A single run of a Task over an entire Dataset, resulting in a table of scores used for version comparison.
  9. Compare Logfire and Sentry

    main

    Logfire is an AI-native observability platform built on OpenTelemetry, focusing on full-stack monitoring (logs, traces, and AI). Sentry is a mature error-monitoring platform focused primarily on catching and triaging exceptions.

    Key Feature Comparison

    FeatureLogfireSentry
    Primary FocusFull observability (logs, traces, AI)Error monitoring
    App TracingCore capabilityAvailable, not a core focus
    AI/LLM SupportFirst-class: auto-instrumentation, evals, prompt management, AI gatewayGeneric function tracing only
    LoggingStructured logs with full contextError-focused
    Live ViewReal-time "pending spans"Not available
    Query InterfaceSQL (Postgres-compatible)Custom UI
    Pricing10M spans/logs/metrics free, then $2/MPer-event + quotas

    When to Choose Logfire

    • Full observability: You need logs, traces, and error tracking in one tool.
    • AI/LLM applications: You need to observe prompts, responses, and token usage.
    • Real-time debugging: You want to see live application behavior via "pending spans."
    • Frontend + backend debugging: Using the JavaScript SDK to trace the entire stack.
    • SQL analysis: You want to query observability data using PostgreSQL-compatible syntax.
    • Agentic Coding: You want to use AI coding agents to query production behavior via SQL.

    When to Choose Sentry

    • Error-focused workflow: Your primary need is catching and triaging errors.
    • Frontend error tracking: You require robust JavaScript error tracking with source maps.
    • Issue tracker integration: You rely on deep integrations with Jira, GitHub Issues, etc.
  10. Understand Logfire telemetry concepts

    main

    Logfire uses four types of telemetry to provide observability:

    • Span: A single unit of work (an operation) with a name, a start time, and a duration. Spans can be nested.
    • Trace: A tree of spans representing the complete path of a single request (e.g., an API call or an LLM run) through your system.
    • Metric: A value measured and aggregated over time (e.g., latency, CPU load) to reveal trends and trigger alerts.
    • Log: A timestamped record of a single event without a duration.
  11. Compare Logfire and Langfuse

    main

    Logfire and Langfuse are both observability tools for AI/LLM applications, but they serve different primary purposes:

    • Logfire is an AI-native full-stack observability platform. It provides unified monitoring for both AI traces and general application telemetry (APIs, databases, etc.). It is built on OpenTelemetry and uses SQL (Postgres-compatible) for querying.
    • Langfuse is an LLM-specific observability tool. It focuses heavily on LLM tracing, prompt management, and evaluations, but has limited support for non-AI application tracing.

    Feature Comparison

    FeatureLogfireLangfuse
    FocusFull-stack observabilityLLM-specific observability
    Language SupportPython, JS/TS, Rust SDKs + any OTelPython, JS/TS SDKs
    Query LanguageSQL (Postgres-compatible)Custom UI / API
    Self-hostingEnterprise optionOpen source, self-hostable
    Pricing ModelPer-span ($2/million)*Per-event + usage-based
    Python SupportFirst-class (Pydantic team)Good
    Non-AI TracingFull supportLimited
    LLM FeaturesToken tracking, costs, panels, evals (UI + code), prompt mgmt, playground, AI gatewayToken tracking, costs, evals, prompt mgmt
    OpenTelemetryNativeExport support

    *Logfire Cloud pricing (Team or Growth plans).