manage(): put an SDK the application set up already under the server (Python, Node.js)
Merged
ST
1mo ago+711+711+012345678901234567890123456789-20-20-01234567890123456789
Requested by Bill · project thread
Stacked on #109 (base is its branch): it reuses #109's exporter walk (govern). Retarget to main once #109 merges.
Why
As a newcomer, I wired each SDK to a local OpAMP server that pushed a redact-secrets and warn-level policy, then checked what reached a telemetry sink:
| Setup | Before | With this PR |
|---|---|---|
Python, Logfire SDK, configure_logfire() | works | unchanged |
Python, opentelemetry-instrument (even with opentelemetry-distro installed) | works | unchanged |
Node.js, node --import @pydantic/opamp-otel/register | works | unchanged |
Python, SDK built in code (contrib's way), then configure() | "Overriding of current TracerProvider is not allowed"; APPLIED, but secrets exported unredacted; described as unknown_service | configure() sees the SDK and governs it, with a warning; or call manage() |
Node.js, own NodeSDK + register() | the app's NodeSDK silently dead (its exporter and resource ignored), last spans lost at exit | manage() after sdk.start() governs the app's own SDK |
| Logfire JS SDK + our register | duplicate-registration errors; telemetry to the OTLP variables instead of Logfire; warn level ignored for Logfire's log lines (APPLIED anyway); our OpAMP requests traced | manage() after logfire.configure(): redaction and log level reach Logfire's own exporter and its console |
What changes
manage()(Python, Node.js): called once, after the application's own setup (its providers, its own NodeSDK, orlogfire.configure()). It joins the fleet, describes the instance by the tracer provider's resource, and puts the gates in front of every exporter on the global providers (#109's walk). The sampler and instrumentations stay the application's, sohead_sampling,sampling_rules,trace_rate_limit,debugandinstrumentationsare undeclared: a policy overriding one is FAILED (naming it), and a warning at start lists them. No SDK set up: it warns, and the app runs unmanaged.- Python
configure()that finds an SDK tracer provider already set as the global one builds none and does whatmanage()does, with a warning (its other kwargs aren't used). - Node.js, Logfire SDK logs: under
manage(), when the resource'stelemetry.sdk.nameislogfire, spans withlogfire.span_type: loggo through the log controls (send_logs, level bylogfire.level_numand scope, the rate cap) and are counted as logs. This is the Node.js version of what Python's #98 did forconfigure_logfire(). - Node.js
govern: processors a processor holds are now looked through. Logfire JS keeps itsBatchSpanProcessoraswrappedand its console (console: true) as aSimpleSpanProcessorunderconsole; both exporters now get the gates (and are listed). Before, neither was gated nor reported. - Docs: adds "An SDK set up already:
manage()" to python-otel.md and node-otel.md, the Logfire JS SDK to the Logfire guide and getting started, and the'./python/otel[logfire]'checkout install line. The package READMEs are updated: the first connection line shows by default, and the key is called a connection key.
Spec and our choices
No protocol change. Every choice here is ours, where the spec leaves it open:
manage()reports the sampler controls as undeclared, the same narrowing #109 keeps for "another sampler in place of the SDK's".- The OpAMP instance UID isn't forced into the app's resource, so the telemetry keeps the app's own
service.instance.id. The docs say so.
Checked
- Python otel suite: 583 passed. Node.js otel suite: 162 passed. Both ran against core 0.15.0 built locally from opamp#772's branch (the lock in this branch stays at #109's).
- New tests: Python
test_an_sdk_the_application_set_up_itself_is_put_under_the_server[manage|configure],test_manage_refuses_a_policy_that_overrides_the_applications_samplerandtest_manage_without_an_sdk_says_how_to_call_it; Node.jstest/manage.test.ts(4 tests, one with a Logfire-shaped wrapper holding a batch processor and a console processor). - Mutation checks: each change undone fails its test (configure's branch,
AGENT.govern,narrow,logSpans, the wrapper walk). - End to end, with the real
@pydantic/logfire-node0.21 andlogfire5.4 againstopamp-server -scenarioand an OTLP sink: redaction (mask and drop) and the warn level applied to Logfire's own exporter; withconsole: true, the console printeduser.email: '[REDACTED]'and no dropped attribute. scripts/public_check.pyandredact_mutants.py --checkpass.
CI: "Python client (2/3)" fails on a missing testdata/sdk-settings/exporters.json. That comes from #109's base, which needs the core 0.15.0 test vectors locked; it clears when #109 locks the 0.15.0 prerelease.
🤖 Generated with Claude Code