Skip to content

fix(ext/console): make timer and counter state per-instance to fix OTEL console wrapping#32719

Merged
bartlomieju merged 4 commits intomainfrom
fix/otel-console-time
Mar 15, 2026
Merged

fix(ext/console): make timer and counter state per-instance to fix OTEL console wrapping#32719
bartlomieju merged 4 commits intomainfrom
fix/otel-console-time

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

Summary

  • Fixes console.time / console.timeEnd / console.count / console.countReset producing spurious warnings when OTEL is enabled (OTEL_DENO=true)
  • Root cause: timerMap and countMap were module-level singletons shared across all Console instances. When OTEL wraps the console via wrapConsole, both the OTEL Console and the original Console methods are called sequentially, but they were sharing the same timer/counter state, so the second call would see already-modified state.
  • Fix: move timerMap and countMap to private instance fields (#timerMap, #countMap) so each Console instance maintains independent state.

Fixes #28818

Test plan

  • Added tests/specs/cli/otel_basic/console_time spec test that exercises console.time/console.timeEnd/console.count with OTEL enabled
  • Existing console tests pass (cargo test console)
  • Existing OTEL spec tests unaffected (pre-existing metric test failures are unrelated)

🤖 Generated with Claude Code

…EL console wrapping

When OTEL is enabled, `wrapConsole` calls both the OTEL Console and the
original Console methods sequentially. Since `timerMap` and `countMap` were
module-level singletons shared across all Console instances, the OTEL Console
would modify timer/counter state before the original Console ran, causing
spurious "Timer already exists" and "Timer does not exist" warnings.

Move `timerMap` and `countMap` to private instance fields so each Console
instance maintains independent state.

Fixes #28818

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@kajukitli kajukitli left a comment

Choose a reason for hiding this comment

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

Reviewed the changes with full repo context. No issues found.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bartlomieju bartlomieju enabled auto-merge (squash) March 15, 2026 12:09
bartlomieju and others added 2 commits March 15, 2026 13:23
Console methods time/timeEnd/timeLog/count/countReset previously called
this.info()/this.warn() internally. Since these are arrow functions with
lexically captured `this`, they always invoked the original info/warn,
bypassing the callConsole wrapper. This meant otelLog was never called
for their output. Using this.#printFunc() directly ensures each Console
instance's own print function is invoked.

Also update console_time.out for log.iostream attribute from main.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bartlomieju bartlomieju merged commit 895fa89 into main Mar 15, 2026
216 of 222 checks passed
@bartlomieju bartlomieju deleted the fix/otel-console-time branch March 15, 2026 16:16
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.

OTEL breaks console.time

3 participants