Logfire SDKs' own fleet option: a versioned hook in Python and Node.js
Requested by Bill · project thread
What
The Logfire SDKs get their own fleet option: logfire.configure(fleet=True) in Python (installed with logfire[fleet]) and configure({ fleet: true }) in @pydantic/logfire-node (with this package as its optional peer dependency). This PR is the side those options call. The Logfire SDK builds its own SDK and calls this package at each point where the policy has to act.
| Python | Node.js | |
|---|---|---|
| Entry point | logfire_fleet(endpoint=, headers=, state_dir=, heartbeat_interval=) | logfireFleet({ endpoint, headers, stateDir, heartbeatIntervalMs }) |
| Head sampler | head_sampler(sampler) → the live sampler | headSampler(sampler) → the live sampler |
| Instance UID | resource_attributes (service.instance.id) | resourceAttributes |
| Export to Logfire | redacting_spans under its retries, spans above them, logs, metrics (the same placement as configure_logfire()) | through start (the exporters are governed as manage() governs them) |
| Start | start(resource, tracer_provider=, meter_provider=, logger_provider=) | start(startSdk, resource): it starts the NodeSDK, so the providers it registers are the SDK's |
| Configured again | the new providers are governed under the same client (AGENT.rebuilt) | same |
| Contract | LOGFIRE_FLEET_CONTRACT = 1 | LOGFIRE_FLEET_CONTRACT = 1 |
If the Logfire SDK doesn't know the installed contract, it warns and runs unmanaged.
Why this replaces configure_logfire() and manage() for Logfire users:
configure_logfire()rebuilds the Logfire SDK's exporters from 7 privatelogfire._internalmodules, pinned tologfire>=5.1,<6. Now the Logfire SDK builds them and this package only wraps them.manage()keeps the application's sampler, so it refuses the sampling controls and debug mode. With the hook the sampler is ours, so they are carried out. In Node.js the instrumentation switches are still refused, because the instrumentations are the Logfire SDK's own.
configure_logfire() stays for Logfire SDKs that don't have the option yet. Once they do, removing it can be a separate change.
Release
- Base: main. The rename (#126) shipped as SDK 0.2.0 without this hook, so it goes out in 0.2.1.
- Logfire side: pydantic/logfire#2736 (Python) and pydantic/logfire-js#422 (Node.js). Their pins (
logfire-fleet-otel>=0.2.1,<0.3, npm peer^0.2.1) need that release before their CI can resolve.
Spec
Nothing about OpAMP changes here. The hook is in-process API between two of our SDKs.
Checks (local)
- Python otel: 611 passed, against a local Logfire SDK with the option.
test_logfire.pyruns its 9 Logfire end-to-end tests both ways (configure_logfireandfleet). When the installed Logfire SDK lacks the option, which is what CI has today, thefleetcases skip. - New Python tests:
- The gate sits above Logfire's retries with redaction under them, for both ways in.
- A second
logfire.configure(fleet=...)stays governed, including an exporter only the second one has. - Both were mutation-checked: each fails when the wrap or the re-govern is removed.
- Node.js otel: all tests pass. The new
test/logfire.test.tsloads the hook withrequire(), as the synchronous Logfireconfigure()must, and covers:- redaction plus the server's instance UID
head_sampling: 0carried outconfigure()again- mutation-checked on the sampler and the re-govern.
- End to end with the real
@pydantic/logfire-nodebuilt from pydantic/logfire-js#422:- A redaction policy drops the attribute on the Logfire console.
head_sampling: 0stops all spans.- Without this package, or without an endpoint, it warns and keeps sending.
public_check.pyis clean.
https://claude.ai/code/session_01RQmH2Ahdo31QCsMGH8x97V
Generated by Claude Code