fix(core): buffer chat compression telemetry until SDK is initialized#28093
Open
AriaZhao-coder wants to merge 1 commit into
Open
fix(core): buffer chat compression telemetry until SDK is initialized#28093AriaZhao-coder wants to merge 1 commit into
AriaZhao-coder wants to merge 1 commit into
Conversation
`logChatCompression()` in `telemetry/loggers.ts` emitted its OTel log record and recorded its metrics directly, bypassing the `bufferTelemetryEvent()` wrapper used by every other logging function in the file. When chat compression fires before the OpenTelemetry SDK finishes initializing — likely during early, history-heavy sessions — the log event and metrics are emitted against a no-op provider and silently dropped. Wrap the OTel emit and `recordChatCompressionMetrics()` call in `bufferTelemetryEvent()`, matching the pattern used by `logApiResponse` and the rest of the loggers. The `ClearcutLogger` call stays outside the wrapper, unchanged. Add a regression test asserting the emit and metrics are deferred (not called directly) when the buffered callback is held back. Fixes google-gemini#23445
|
📊 PR Size: size/S
|
This was referenced Jun 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
logChatCompression()inpackages/core/src/telemetry/loggers.tsemitted its OpenTelemetry log record and recorded its metrics directly, bypassing thebufferTelemetryEvent()wrapper that every other logging function in the file uses.bufferTelemetryEvent()defers telemetry emission until the OTel SDK has finished initializing. Without it, if chat compression fires before initialization completes — which is likely, since compression happens during early, history-heavy sessions — the log event and therecordChatCompressionMetrics()data point are emitted against a no-op provider and silently dropped.Fix
Wrap the OTel emit and metrics call in
bufferTelemetryEvent(), matching the established pattern (e.g.logApiResponse,logMalformedJsonResponse). TheClearcutLoggercall stays outside the wrapper, unchanged — consistent with the rest of the file.Tests
Added a regression test to the existing
logChatCompressionblock: when the buffered callback is held back (simulating the SDK not yet initialized), the OTelemitandrecordChatCompressionMetricsmust not be called directly.Verified locally (Node 20):
loggers.test.ts— all 53 tests passprettier --check,eslint --max-warnings 0,tsc --noEmit— all cleanFixes #23445