Skip to content

feat(telemetry): add span log correlation#969

Merged
EhabY merged 4 commits into
mainfrom
feat/issue-925-span-log-correlation
May 22, 2026
Merged

feat(telemetry): add span log correlation#969
EhabY merged 4 commits into
mainfrom
feat/issue-925-span-log-correlation

Conversation

@EhabY
Copy link
Copy Markdown
Collaborator

@EhabY EhabY commented May 21, 2026

Summary

  • Adds Span.log() and Span.logError() for point-in-time telemetry logs correlated to the active span.
  • Auto-composes span log names under the owning span and emits traceId plus parentEventId without durationMs.
  • Resolves the auth interceptor TODO by emitting auth.unauthorized_intercepted.received when 401 recovery starts.

Tests

  • pnpm test:extension ./test/unit/telemetry/service.test.ts ./test/unit/api/authInterceptor.test.ts
  • pnpm typecheck
  • pnpm lint
  • pnpm format:check

Closes #925

Generated by Coder Agents.

Plan and decisions
  • Use durationMs presence as the span/log discriminator; do not add eventKind.
  • Drop and warn for span.log() / span.logError() after a span has completed.
  • Auto-compose span log event names as ${span.eventName}.${logName}.
  • Resolve the auth interceptor TODO with auth.unauthorized_intercepted.received.
  • Keep parent/correlation docs concise.

@EhabY EhabY self-assigned this May 21, 2026
@EhabY EhabY force-pushed the feat/issue-925-span-log-correlation branch from bd29095 to e1f34f2 Compare May 21, 2026 13:06
@EhabY EhabY requested a review from jakehwll May 21, 2026 13:24
@EhabY EhabY force-pushed the feat/issue-925-span-log-correlation branch from e1f34f2 to a016d9a Compare May 21, 2026 13:44
@EhabY
Copy link
Copy Markdown
Collaborator Author

EhabY commented May 21, 2026

/coder-agents-review

Copy link
Copy Markdown

@coder-agents-review coder-agents-review Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, proportional addition. The Span.log()/logError() API surface is small, consistent with the existing phase() pattern, and tested across the full lifecycle: correlation, child spans, name sanitization, post-emit guards, throwing sinks, level-off suppression, and the auth interceptor integration. Test-to-code ratio is ~2:1. Netero found no mechanical issues.

The phase post-emit guard (new completed check on phase()) is a pre-existing bug fix bundled with this feature. Before this PR, calling phase() on an escaped span after the parent completed would emit an orphaned child event. Now it warns and delegates to NOOP_SPAN. Correct fix, properly tested, not mentioned in the PR description. Four reviewers independently noted this.

3 P3, 1 P4.

"'Correlated' is weasel-word territory: every event in a trace is correlated." (Leorio)

🤖 This review was automatically generated with Coder Agents.

Comment thread test/unit/telemetry/service.test.ts
Comment thread test/unit/telemetry/service.test.ts
Comment thread src/telemetry/wireFormat.ts Outdated
Comment thread src/telemetry/span.ts Outdated
@EhabY EhabY force-pushed the feat/issue-925-span-log-correlation branch from 45db4dd to 9afaa96 Compare May 21, 2026 14:54
@EhabY
Copy link
Copy Markdown
Collaborator Author

EhabY commented May 21, 2026

/coder-agents-review

EhabY and others added 3 commits May 21, 2026 18:14
- Restore the OTel mapping on `parentEventId` and call out the dual
  case (phase children vs span logs).
- Match `phase`'s doc style on `Span.log` / `logError`, noting absence
  of framework-set `result` and `durationMs`.
- Replace "correlated" in test names with the concrete contract
  (traceId, parentEventId).
The behavior tests for post-emit guards now assert only on the visible
contract (no event leak, fn still runs). One dedicated test exercises
all post-emit methods (`setProperty`, `setMeasurement`, `markAborted`,
`markFailure`, `log`, `logError`, `phase`) and verifies the
developer-facing warn fires once for each.
@EhabY EhabY force-pushed the feat/issue-925-span-log-correlation branch from 9afaa96 to 7595903 Compare May 21, 2026 15:15
Copy link
Copy Markdown

@coder-agents-review coder-agents-review Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All four R1 findings addressed. The test restructuring is well done: behavioral tests focused on observable contracts (event suppression, callback execution) separated from the consolidated warning-count test that covers all 7 post-emit methods. wireFormat.ts doc now properly distinguishes the two OTel mappings. span.ts docs now match the phase() standard.

1 P3 (new). Otherwise clean.

"'Mutation dropped' misnames what happened. A developer debugging would look for a lost property change, not a suppressed log event." (Gon)

🤖 This review was automatically generated with Coder Agents.

Comment thread src/telemetry/service.ts
Copy link
Copy Markdown
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see anything blocking; left a few comments 👍

Comment thread src/telemetry/service.ts
Comment thread test/unit/telemetry/service.test.ts
Comment thread src/telemetry/service.ts
Comment thread test/unit/telemetry/service.test.ts
`warnPostEmit` is shared by seven methods now, including `log`,
`logError`, and `phase`, which aren't strictly mutations. "mutation
dropped" was accurate only for the original setProperty/setMeasurement
callers. Generalize to "call ignored".
@EhabY EhabY force-pushed the feat/issue-925-span-log-correlation branch from fdc2eec to 3d6c632 Compare May 22, 2026 12:01
Copy link
Copy Markdown
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@EhabY EhabY merged commit 4f67960 into main May 22, 2026
13 checks passed
@EhabY EhabY deleted the feat/issue-925-span-log-correlation branch May 22, 2026 12:17
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.

Telemetry: span.log() / span.logError() for log-in-trace correlation

2 participants