Logfire SDKs' own fleet option: a versioned hook in Python and Node.js

Merged
ST
1mo ago
+562-33

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.

PythonNode.js
Entry pointlogfire_fleet(endpoint=, headers=, state_dir=, heartbeat_interval=)logfireFleet({ endpoint, headers, stateDir, heartbeatIntervalMs })
Head samplerhead_sampler(sampler) → the live samplerheadSampler(sampler) → the live sampler
Instance UIDresource_attributes (service.instance.id)resourceAttributes
Export to Logfireredacting_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)
Startstart(resource, tracer_provider=, meter_provider=, logger_provider=)start(startSdk, resource): it starts the NodeSDK, so the providers it registers are the SDK's
Configured againthe new providers are governed under the same client (AGENT.rebuilt)same
ContractLOGFIRE_FLEET_CONTRACT = 1LOGFIRE_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 private logfire._internal modules, pinned to logfire>=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.py runs its 9 Logfire end-to-end tests both ways (configure_logfire and fleet). When the installed Logfire SDK lacks the option, which is what CI has today, the fleet cases 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.ts loads the hook with require(), as the synchronous Logfire configure() must, and covers:
    • redaction plus the server's instance UID
    • head_sampling: 0 carried out
    • configure() again
    • mutation-checked on the sampler and the re-govern.
  • End to end with the real @pydantic/logfire-node built from pydantic/logfire-js#422:
    • A redaction policy drops the attribute on the Logfire console.
    • head_sampling: 0 stops all spans.
    • Without this package, or without an endpoint, it warns and keeps sending.
  • public_check.py is clean.

https://claude.ai/code/session_01RQmH2Ahdo31QCsMGH8x97V


Generated by Claude Code