Skip to content

fix(telemetry): warn once on uninitialized telemetry access and add explicit validation helpers - #877

Merged
Just-Bamford merged 2 commits into
Sorokit:mainfrom
Gezziy:initTelemetry
Oct 20, 2026
Merged

Just-Bamford merged 2 commits into
Sorokit:mainfrom
Gezziy:initTelemetry

Conversation

@Gezziy

@Gezziy Gezziy commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

closes #768

Summary of Changes

  • Warn-Once Session Diagnostics: Added session-level warning deduplication in src/performance/telemetry.ts via an internal warnIfUninitialized() dispatcher and warnedMethods set. Direct telemetry getters (getTelemetryManager(), getTelemetryData(), getTelemetryMetricsSummary(), getTelemetrySpans()) now log an actionable console.warn upon their first uninitialized call of a session.
  • Console Spam Prevention: Subsequent uninitialized calls within the same session proceed silently without repeatedly flooding logs.
  • Explicit Result-Based Validation Helpers:
    • validateTelemetryInitialized(): SorokitResult<void> — checks if telemetry is initialized and returns INVALID_CONFIG if inactive.
    • requireTelemetryManager(): SorokitResult<OpenTelemetryManager> — returns the active manager or an error result.
    • requireTelemetryData(): SorokitResult<TelemetryData> — returns the active telemetry data or an error result.
  • Public API Re-exports: Re-exported the new validation helpers in src/performance/index.ts and src/index.ts.
  • Lifecycle Cleanliness: initTelemetry(), resetTelemetry(), and shutdownTelemetry() automatically clear warning tracking state.
  • Test Coverage: Added 12 new unit tests in src/performance/telemetry.test.ts verifying warn-once behavior, deduplication, suppression on initialization, reset semantics, and explicit validator branching (total 51 passing tests).

Reason for the Changes

Fixes #768. getTelemetryManager() and getTelemetryData() previously returned null if initTelemetry() had not been invoked, leading to silent loss of observability metrics, error reporting, and distributed tracing. The warn-once approach alerts developers to missing initialization immediately without spamming logs or breaking existing code that depends on null returns.

@drips-wave

drips-wave Bot commented Oct 20, 2026

Copy link
Copy Markdown

@Gezziy 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! 🚀

Learn more about application limits

@Just-Bamford
Just-Bamford merged commit 4ef0124 into Sorokit:main Oct 20, 2026
5 checks passed
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.

initTelemetry does not validate that the configuration is set before use — uninitialized telemetry silently no-ops

2 participants