← Back to Pull requests

Add configure(fleet=...) to manage the SDK from Logfire Fleet #2736

Closed
unknown closed this pull request without merging on Nov 06, 2026 21:32 UTC
View on GitHub
unknown unknown commented on Nov 05, 2026 21:39 UTC
Author

<!-- claude-projects-attribution: {"github_login":"strawgate"} -->
_Requested by Bill · project thread_

What

logfire.configure() gets a fleet option. With it, a Logfire Fleet policy governs everything the SDK sends: sampling, which signals are sent, log levels, redaction and volume limits, on every exporter, the console included.

pip install 'logfire[fleet]'

logfire.configure(service_name='checkout', fleet=True)  # or LOGFIRE_FLEET=true

  • fleet=True reads the Fleet server from OTEL_OPAMP_ENDPOINT and OTEL_OPAMP_HEADERS, which the Fleet setup page gives you.

  • fleet=logfire.fleet.FleetOptions(endpoint=..., headers=..., state_dir=..., heartbeat_interval=...) gives the server in code instead.

  • The client is the new fleet extra, logfire-fleet-otel>=0.2.1,<0.3; python_version >= '3.11'. Its native core is about 1 MB per platform wheel, so it stays out of the base install. It is imported only when fleet is set.
  • How

    logfire/_internal/fleet.py finds the client and checks its contract version. _initialize() then calls it where the policy has to act:

    1. Head sampler: the head sampler goes in, and the live sampler comes out for the tracer provider.
    2. Resource: Fleet's instance UID is merged into the resource as service.instance.id.
    3. Export to Logfire:
    - redaction goes under RetryFewerSpansSpanExporter, so a span the retries make is redacted too
    - the gate goes above it, so each span is decided and counted once
    - the log and metric exporters get gates too.
    4. Start: the client gets the built providers. Every other exporter on them gets the gates (the console, additional_span_processors, OTEL_EXPORTER_OTLP_*), and the client joins the fleet. A later configure() is governed under the same client.

    None of this blocks or raises. Until Fleet answers, the last saved policy is in force, else the SDK's own settings. In these cases it warns with LogfireFleetWarning and the SDK runs as it does today:

  • the extra isn't installed

  • no endpoint is set

  • the installed client speaks another contract version (LOGFIRE_FLEET_CONTRACT)

  • Emscripten, which has no threads
  • Smaller changes:

  • fleet_enabled is added to the "Logfire configured" span.

  • FleetOptions survives the executor round trip as a dict, like the other option dataclasses.

  • The logfire-api stubs are regenerated for the changed files only.
  • The client side is pydantic/opamp-clients#127. Today that package's configure_logfire() rebuilds these exporters from logfire._internal modules. With this PR it no longer has to. pydantic/logfire-js#422 adds the same option to @pydantic/logfire-node.

    Before it can merge (why it's a draft)

  • logfire-fleet-otel with the hook (#127) has to be published. Until then uv lock can't resolve the fleet extra, so uv.lock isn't updated in this PR and CI's lock check will fail.

  • Agreement from the SDK maintainers on the option's name and shape.

  • User docs: the Fleet docs PR (#2726) has the applications page this belongs on.
  • Checks (local, Python 3.13)

  • tests/test_fleet.py (new, with a fake client) covers:

  • - where each wrapper sits in the exporter chain
    - the call order
    - LOGFIRE_FLEET
    - off by default
    - each case where it runs unmanaged.
  • test_configure.py and test_logfire_api.py pass. The configuration span snapshot gains fleet_enabled.

  • Full suite: 3329 passed. Four tests didn't pass, none touching this change:

  • - Two need Docker (MySQL, Celery) and were deselected.
    - One unraisable-socket warning in test_openai_agents.py passes on its own.
    - The fourth is the stack of two xfails.
  • End to end with the real client from #127: its Logfire suite runs every test both through configure_logfire() and through logfire.configure(fleet=...) against an OpAMP server and a fake ingest. All pass, covering redaction, traces off, log levels, console governance, sampling, credentials file, zstd, reconfigure and exporter placement.

  • ruff and pyright are clean on the changed files.
  • ---
    _Generated by Claude Code_

    <!-- This is an auto-generated description by cubic. -->
    <a href="https://cubic.dev/pr/pydantic/logfire/pull/2736?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
    <!-- End of auto-generated description by cubic. -->

    Diff: 610 lines (+457 / -153) across 7 files Reviewer: Viicos Review duration: 1433m
    All Vouch review confidence checks passed
    Residual risk 0.31 = Change Risk (0.78) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.78 · 610 lines diff across 7 files
    0.78
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.384
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.078
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #2736"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 78.3% (HIGH) · Higher = larger blast radius
    78.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 30.9% · Safe to merge
    30.9%