Skip to content

Add optional distributed tracing (MoonlightTracer)#30

Open
AquiGorka wants to merge 6 commits intomainfrom
feat/otel-tracing
Open

Add optional distributed tracing (MoonlightTracer)#30
AquiGorka wants to merge 6 commits intomainfrom
feat/otel-tracing

Conversation

@AquiGorka
Copy link
Contributor

Summary

  • Adds framework-agnostic tracing interfaces (MoonlightTracer, MoonlightSpan, NOOP_TRACER) with zero runtime dependency on @opentelemetry/api
  • withTrace (async) and withTraceSync (sync) helpers with guaranteed span lifecycle, error recording, and exit_with_error events
  • Optional withActiveSpan method enables W3C traceparent propagation for distributed tracing — consumers bridge to their own OTel backend
  • Instruments PrivacyChannel (read/invoke/invokeRaw), UtxoBasedAccount (deriveBatch/batchLoad/selectUTXOsForTransfer), and MoonlightTransactionBuilder (addOperation/sign methods)
  • Tracing is fully opt-in: pass a tracer to constructors, or leave it undefined for zero overhead (NOOP_TRACER)

How to verify

Run the full E2E flow with Jaeger locally — see the step-by-step Jaeger guide in local-dev.

Note: To test locally before this SDK version is published, revert the last commit in the local-dev PR (chore: switch SDK import from local path to JSR) so that the E2E test imports the SDK from the local path.

Test plan

  • deno task test passes (no breaking changes — tracing is optional)
  • E2E with deno task e2e + deno task verify-otel passes 16/16 checks
  • Jaeger shows PrivacyChannel, UtxoBasedAccount, and MoonlightTransactionBuilder spans

Defines MoonlightTracer, MoonlightSpan, NOOP_TRACER, withTrace, and
withTraceSync — a framework-agnostic tracing contract that consumers
can bridge to any OpenTelemetry backend. Zero runtime dependency on
@opentelemetry/api.
Adds optional tracer to PrivacyChannel constructor and wraps read,
invoke, and invokeRaw with withTrace for span-level observability.
Adds tracer to account options, wraps deriveBatch and batchLoad with
withTrace, wraps selectUTXOsForTransfer with withTraceSync. Factory
method fromPrivacyChannel propagates tracer from the channel instance.
Wraps addOperation with withTraceSync and sign methods (signWithProvider,
signWithSpendUtxo, signExtWithEd25519) with withTrace. Factory method
fromPrivacyChannel propagates tracer from the channel instance.
@AquiGorka AquiGorka requested review from fazzatti and toruguera and removed request for fazzatti March 12, 2026 17:27
Adds Promise<void> return types to signWithProvider, signWithSpendUtxo,
signExtWithEd25519. Adds await to all withTrace calls in async methods
to satisfy require-await lint rule.
Cover all branches in withTrace and withTraceSync including
success/error paths, withActiveSpan delegation, non-Error throws,
and NOOP_TRACER behavior.
@Moonlight-Protocol Moonlight-Protocol deleted a comment from codecov bot Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant