Skip to content

fix(core): buffer chat compression telemetry until SDK is initialized#28093

Open
AriaZhao-coder wants to merge 1 commit into
google-gemini:mainfrom
AriaZhao-coder:fix/buffer-chat-compression-telemetry
Open

fix(core): buffer chat compression telemetry until SDK is initialized#28093
AriaZhao-coder wants to merge 1 commit into
google-gemini:mainfrom
AriaZhao-coder:fix/buffer-chat-compression-telemetry

Conversation

@AriaZhao-coder

Copy link
Copy Markdown

Summary

logChatCompression() in packages/core/src/telemetry/loggers.ts emitted its OpenTelemetry log record and recorded its metrics directly, bypassing the bufferTelemetryEvent() 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 the recordChatCompressionMetrics() 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). The ClearcutLogger call stays outside the wrapper, unchanged — consistent with the rest of the file.

ClearcutLogger.getInstance(config)?.logChatCompressionEvent(event);
bufferTelemetryEvent(() => {
  const logger = logs.getLogger(SERVICE_NAME);
  logger.emit(logRecord);
  recordChatCompressionMetrics(config, { ... });
});

Tests

Added a regression test to the existing logChatCompression block: when the buffered callback is held back (simulating the SDK not yet initialized), the OTel emit and recordChatCompressionMetrics must not be called directly.

Verified locally (Node 20):

  • The new test fails without the fix and passes with it (red/green)
  • loggers.test.ts — all 53 tests pass
  • prettier --check, eslint --max-warnings 0, tsc --noEmit — all clean

Fixes #23445

`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
@AriaZhao-coder AriaZhao-coder requested a review from a team as a code owner June 22, 2026 14:05
@github-actions github-actions Bot added the size/s A small PR label Jun 22, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/S

  • Lines changed: 42
  • Additions: +32
  • Deletions: -10
  • Files changed: 2

@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/enterprise Issues related to Telemetry, Policy, Quota / Licensing labels Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/enterprise Issues related to Telemetry, Policy, Quota / Licensing priority/p2 Important but can be addressed in a future release. size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug(telemetry): logChatCompression bypasses bufferTelemetryEvent wrapper

1 participant