Skip to content

Suppress logging mechanism to support console instrumentations#6355

Draft
martinkuba wants to merge 2 commits intoopen-telemetry:mainfrom
martinkuba:suppress-logging
Draft

Suppress logging mechanism to support console instrumentations#6355
martinkuba wants to merge 2 commits intoopen-telemetry:mainfrom
martinkuba:suppress-logging

Conversation

@martinkuba
Copy link
Contributor

Which problem is this PR solving?

In the browser repo, we are introducing an instrumentation for capturing console logs. There is an issue with the diagnostics logger - capturing console logs triggers work by the SDK, which may generate console logs using the diagnostics logger, which creates more work by the SDK ... infinite loop.

The issue has been discussed here.

Short description of the changes

This PR introduces a similar mechanism to the existing suppressTracing function. If users wanted to use the console instrumentation, they would configure the diagnostics logger this way:

import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
import { createSuppressedDiagLogger } from '@opentelemetry/core';

diag.setLogger(createSuppressedDiagLogger(new DiagConsoleLogger()), DiagLogLevel.DEBUG);

The console instrumentation would then check if logging is suprressed:

import { context } from '@opentelemetry/api';
import { isLoggingSuppressed } from '@opentelemetry/core';

if (!isLoggingSuppressed(context.active())) {
  captureAsLogRecord(args);
}

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@codecov
Copy link

codecov bot commented Jan 30, 2026

Codecov Report

❌ Patch coverage is 20.00000% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.30%. Comparing base (b97b488) to head (8d3f3cb).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
...pentelemetry-core/src/diag/SuppressedDiagLogger.ts 8.69% 21 Missing ⚠️
...es/opentelemetry-core/src/diag/suppress-logging.ts 57.14% 3 Missing ⚠️

❌ Your patch check has failed because the patch coverage (20.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6355      +/-   ##
==========================================
- Coverage   95.68%   95.30%   -0.38%     
==========================================
  Files         313      367      +54     
  Lines        9671    11639    +1968     
  Branches     2227     2678     +451     
==========================================
+ Hits         9254    11093    +1839     
- Misses        417      546     +129     
Files with missing lines Coverage Δ
...es/opentelemetry-core/src/diag/suppress-logging.ts 57.14% <57.14%> (ø)
...pentelemetry-core/src/diag/SuppressedDiagLogger.ts 8.69% <8.69%> (ø)

... and 73 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant

Comments