Add configure(fleet=...) to manage the SDK from Logfire Fleet
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=Truereads the Fleet server fromOTEL_OPAMP_ENDPOINTandOTEL_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
fleetextra,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 whenfleetis set.
How
logfire/_internal/fleet.py finds the client and checks its contract version. _initialize() then calls it where the policy has to act:
- Head sampler: the head sampler goes in, and the live sampler comes out for the tracer provider.
- Resource: Fleet's instance UID is merged into the resource as
service.instance.id. - 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.
- redaction goes under
- 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 laterconfigure()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_enabledis added to the "Logfire configured" span.FleetOptionssurvives the executor round trip as a dict, like the other option dataclasses.- The
logfire-apistubs 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-otelwith the hook (#127) has to be published. Until thenuv lockcan't resolve thefleetextra, souv.lockisn'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.pyandtest_logfire_api.pypass. The configuration span snapshot gainsfleet_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.pypasses 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 throughlogfire.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. ruffandpyrightare clean on the changed files.
Generated by Claude Code