Skip to content

Add SSE fan-out tracing span and propagate correlation/trace id into emitted SSE events #362

Description

@Jagadeeshftw

📌 Description

src/tracing/hooks.ts provides traceDbQuery, traceRedisCommand, traceStellarRpc, and traceWebhookDispatch, but no helper traces SSE fan-out. Meanwhile src/streams/sseEmitter.ts carries a correlationId on the update event but does not propagate trace context into the emitted SSE frames, so the trace chain breaks at the SSE boundary. Add a traceSseDispatch() helper and include the correlation/trace id in the SSE event so consumers can correlate.

💡 Why it matters: SSE delivery is currently a tracing blind spot, breaking end-to-end request correlation.

🧩 Requirements and context

  • Add traceSseDispatch() to src/tracing/hooks.ts wrapping the fan-out with subscriber-count and stream-id attributes.
  • Include the correlation/trace id as a field/comment line in emitted SSE frames in src/streams/sseEmitter.ts.
  • Keep cardinality bounded (no per-subscriber spans by default).
  • Ensure the span closes even when a subscriber write throws.
  • Document the SSE trace-propagation contract.

Non-functional requirements

  • Must be secure, tested, and documented.
  • Should be efficient and easy to review.

🛠️ Suggested execution

1. Fork the repo and create a branch

git checkout -b sse-tracing

2. Implement changes

  • Write/modify the relevant source: src/tracing/hooks.ts, src/streams/sseEmitter.ts
  • Write comprehensive tests: tests/tracing/hooks.test.ts, tests/routes/streams-sse.test.ts
  • Add documentation: inline TSDoc + README tracing section
  • Include TSDoc doc comments on traceSseDispatch
  • Validate security assumptions: trace ids exposed to clients are non-sensitive

3. Test and commit

  • Run tests:
npm test
  • Cover edge cases: subscriber write error, zero subscribers, span closure
  • Include test output and security notes in the PR description.

Example commit message

feat(tracing): add SSE fan-out span and propagate correlation id into SSE events

✅ Acceptance criteria

  • traceSseDispatch() exists and is used in the emitter
  • SSE frames carry the correlation/trace id
  • Span includes subscriber-count and stream-id attributes
  • Span closes on subscriber write error
  • Trace-propagation contract documented

🔒 Security notes

Only expose non-sensitive correlation/trace identifiers in client-visible SSE frames; never embed internal tokens.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial CampaignGrantFox official campaign issueStellar WaveIssues in the Stellar wave programbackendBackend service workobservabilityLogging / metrics / tracing

Fields

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions