feat(telemetry): add OpenTelemetry-compatible instrumentation hooks - #191
Conversation
457e61f to
4171b1a
Compare
|
@collinsezedike Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
Thanks @collinsezedike. Exporting the Everything else is green, including all the examples jobs, so that single commit should clear it. This gate has now caught five PRs across two waves, so it is us, not you. I am going to make it print the fix command directly. |
|
Fixed. Regenerated the api-extractor baseline:
While regenerating I caught a real gap along the way: |
|
Merged. Thanks for the quick baseline fix @collinsezedike. A no-op default tracer with the adapter kept out of runtime deps is the right shape, and the OTel example being an example rather than a dependency is exactly what the issue wanted. |
Summary
Tracer/Spaninterface (src/telemetry.ts) plussetTracer()/getTracer(), exported from the package root. Zero runtime dependency on@opentelemetry/*or any tracing library — every instrumented call site defaults to a no-op tracer untilsetTracer()is called.deriveStealthKeys()/deriveStealthKeysFromSigner()(stellar.deriveStealthKeys)scanAnnouncementsStream()— onestellar.scanspan per call with aggregate counts, plus astellar.scan.matchspan per (comparatively rare) match, deliberately not per-candidate to avoid dwarfing scan cost with span overheadRpcClient.request()(stellar.rpc.request, covering internal retries/failover)ClaudeAgentToolsmethod (agent.tool.*)traceroption that overrides the global tracer for that one call.scanAnnouncementsStreamwas never exported from the public@wraith-protocol/sdk/chains/stellarentry point (only reachable via a relative import) — needed to make its newtraceroption actually usable.docs/observability.mddocuments every instrumented span and its stable attribute names.examples/otel/ships a reference adapter targeting@opentelemetry/api'sTracer/Spanshape. It's written against local structural types (not an import of@opentelemetry/api), so it has no dependency on the package — a real OTel tracer already satisfies the shape. A tiny console-based stand-in tracer lets the example run standalone end-to-end (key derivation → stealth address generation → scan) without installing any tracing library. Added to the Examples CI matrix.Closes #177.
Semver
Additive-only: new
src/telemetry.tsmodule and root exports (setTracer,getTracer,withSpan,NOOP_TRACER,Tracer,Span), new optionaltracer/optsparameters on existing functions (all optional, existing call sites unaffected), andscanAnnouncementsStreambecoming a public export it previously wasn't. No existing signature or behavior changes.Test plan
pnpm buildandpnpm test— full suite passes (1136 tests, 0 failures)test/telemetry.test.ts—Tracer/Span/setTracer/getTracer/withSpanunit coverage (no-op default, sync/async success and failure paths, per-call override, attribute mutation)test/bench/telemetry.bench.ts— no-op tracer overhead vs. uninstrumented calltest/chains/stellar/keys.test.ts,test/chains/stellar/scan.test.ts,test/chains/stellar/rpc.test.ts,test/agent/tools.test.ts— span emission, per-call override precedence, global tracer fallbackpnpm-lock.yamldiff is scoped to exactly the newexamples/otelworkspace importer (verified against the pinnedpnpm@10.34.4)pnpm format:checkNote on CI
The Examples CI type-check step for
otel(like all CLI-style examples) runs withcontinue-on-error: true, matching the existing convention for examples that lag the SDK API slightly — non-blocking either way.