Skip to content

[BUILD] Ignore deprecated warning#3845

Merged
marcalff merged 5 commits intoopen-telemetry:mainfrom
owent:fixes_3835
Feb 7, 2026
Merged

[BUILD] Ignore deprecated warning#3845
marcalff merged 5 commits intoopen-telemetry:mainfrom
owent:fixes_3835

Conversation

@owent
Copy link
Member

@owent owent commented Feb 5, 2026

Fixes #3835

Changes

  • Fixes deprecated warning scope

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@owent owent requested a review from a team as a code owner February 5, 2026 06:37
Copilot AI review requested due to automatic review settings February 5, 2026 06:37
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request aims to fix deprecated warning (C4996) in MSVC when including opentelemetry/logs/provider.h. The issue reported that users including this header for legitimate APIs (GetLoggerProvider/SetLoggerProvider) were encountering build failures due to deprecation warnings from internal implementation details involving the deprecated EventLogger APIs.

Changes:

  • Adjusted pragma warning scopes to suppress deprecation warnings around internal uses of deprecated EventLogger/EventLoggerProvider types in both the Provider class and noop implementations
  • Added explicit destructors to NoopEventLogger and NoopEventLoggerProvider classes

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
api/include/opentelemetry/logs/provider.h Moved pragma warning suppressions to wrap public deprecated methods and private GetEventProvider() method that instantiates deprecated types
api/include/opentelemetry/logs/noop.h Expanded pragma warning scope to cover entire NoopEventLogger and NoopEventLoggerProvider class definitions, added explicit destructors

# elif defined(__GNUC__) && !defined(__clang__) && !defined(__apple_build_version__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The pragma directive #pragma GCC diagnostic warning "-Wdeprecated-declarations" will cause deprecation warnings to be emitted as warnings for GCC, which contradicts the intent of suppressing these internal implementation warnings. This should be #pragma GCC diagnostic ignored "-Wdeprecated-declarations" to suppress the warnings like it was before, matching the behavior for MSVC which uses disable : 4996.

Copilot uses AI. Check for mistakes.
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
# pragma clang diagnostic warning "-Wdeprecated-declarations"
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The pragma directive #pragma clang diagnostic warning "-Wdeprecated-declarations" will cause deprecation warnings to be emitted as warnings for Clang, which contradicts the intent of suppressing these internal implementation warnings. This should be #pragma clang diagnostic ignored "-Wdeprecated-declarations" to suppress the warnings like it was before, matching the behavior for MSVC which uses disable : 4996.

Copilot uses AI. Check for mistakes.
Comment on lines 99 to 102
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic push
# pragma clang diagnostic warning "-Wdeprecated-declarations"
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The pragma directive #pragma GCC diagnostic warning "-Wdeprecated-declarations" will cause deprecation warnings to be emitted as warnings for GCC, which contradicts the intent of suppressing these internal implementation warnings. This should be #pragma GCC diagnostic ignored "-Wdeprecated-declarations" to suppress the warnings like it was before, matching the behavior for MSVC which uses disable : 4996.

Suggested change
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic push
# pragma clang diagnostic warning "-Wdeprecated-declarations"
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdeprecated-declarations"

Copilot uses AI. Check for mistakes.
Comment on lines 99 to 102
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic push
# pragma clang diagnostic warning "-Wdeprecated-declarations"
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The pragma directive #pragma clang diagnostic warning "-Wdeprecated-declarations" will cause deprecation warnings to be emitted as warnings for Clang, which contradicts the intent of suppressing these internal implementation warnings. This should be #pragma clang diagnostic ignored "-Wdeprecated-declarations" to suppress the warnings like it was before, matching the behavior for MSVC which uses disable : 4996.

Suggested change
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic push
# pragma clang diagnostic warning "-Wdeprecated-declarations"
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdeprecated-declarations"

Copilot uses AI. Check for mistakes.
Comment on lines 56 to 59
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic push
# pragma clang diagnostic warning "-Wdeprecated-declarations"
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The pragma directive #pragma GCC diagnostic warning "-Wdeprecated-declarations" will cause deprecation warnings to be emitted as warnings for GCC, which contradicts the intent of suppressing these internal implementation warnings. This should be #pragma GCC diagnostic ignored "-Wdeprecated-declarations" to suppress the warnings like it was before, matching the behavior for MSVC which uses disable : 4996.

Suggested change
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic push
# pragma clang diagnostic warning "-Wdeprecated-declarations"
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdeprecated-declarations"

Copilot uses AI. Check for mistakes.
Comment on lines 56 to 59
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic push
# pragma clang diagnostic warning "-Wdeprecated-declarations"
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The pragma directive #pragma clang diagnostic warning "-Wdeprecated-declarations" will cause deprecation warnings to be emitted as warnings for Clang, which contradicts the intent of suppressing these internal implementation warnings. This should be #pragma clang diagnostic ignored "-Wdeprecated-declarations" to suppress the warnings like it was before, matching the behavior for MSVC which uses disable : 4996.

Suggested change
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic push
# pragma clang diagnostic warning "-Wdeprecated-declarations"
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdeprecated-declarations"

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.99%. Comparing base (bb5fff0) to head (d798baa).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3845      +/-   ##
==========================================
+ Coverage   89.99%   89.99%   +0.01%     
==========================================
  Files         225      225              
  Lines        7168     7170       +2     
==========================================
+ Hits         6450     6452       +2     
  Misses        718      718              
Files with missing lines Coverage Δ
api/include/opentelemetry/logs/event_logger.h 90.00% <ø> (ø)
...include/opentelemetry/logs/event_logger_provider.h 100.00% <ø> (ø)
api/include/opentelemetry/logs/noop.h 79.32% <100.00%> (+1.54%) ⬆️
api/include/opentelemetry/logs/provider.h 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ThomsonTan
Copy link
Contributor

Could a test be tested for validation?

@owent
Copy link
Member Author

owent commented Feb 5, 2026

Could a test be tested for validation?

Yes, tests are added.

list(REMOVE_ITEM COMMON_LOGS_FOO_COMPILE_OPTS
-Wno-error=deprecated-declarations)
set_target_properties(
common_logs_foo_library PROPERTIES COMPILE_OPTIONS
Copy link
Contributor

Choose a reason for hiding this comment

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

Would remove the option from the target property work? The option -Wno-error=deprecated-declarations seems added to the directory level at

add_compile_options(-Wno-error=deprecated-declarations)

Copy link
Member

Choose a reason for hiding this comment

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

The code already builds in CI in maintainer mode, why do we need extra changes in CMakeLists.txt ?

@ThomsonTan
Copy link
Contributor

CHANGELOG needs to be updated.

Comment on lines +18 to +28
# if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4996)
# elif defined(__GNUC__) && !defined(__clang__) && !defined(__apple_build_version__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
# endif

Copy link
Member

Choose a reason for hiding this comment

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

This header file declares a deprecated class:

class OPENTELEMETRY_DEPRECATED EventLogger

Not tested on windows, but I in my understanding:

  • DECLARING a deprecated code does not raise a warning
  • USING a deprecated code does raise a warning

so there should be no changes in file event_logger.h and event_logger_provider.h.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is different for MSVC. MSVC with /sdl fires C4996 at declaration sites too, not just usage, in that case the suppression here is needed.

Copy link
Member

Choose a reason for hiding this comment

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

@ThomsonTan @lalitb

With this change, code is deprecated and the deprecation warning is always suppressed and ignored, due to the pragma added.

This makes no sense to me, why deprecating in the first place then ?

Given that this patch is already approved by two maintainers, and given how it unblocks an issue downstream in opentelemetry-cpp-contribs (geneva), I am not blocking this merge it so it can be part of the 1.25 release, but I don't agree with this change.

If we don't want deprecation warnings at all, why not remove the OPENTELEMETRY_DEPRECATED tag, and remove all the pragma pilled up on top, to achieve exactly the same effect ?

This area should be simplified in a follow up PR, in my opinion.

Preparing the 1.25 release with warnings disabled for now, again, to unblock downstream.

# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
# endif
Copy link
Member

Choose a reason for hiding this comment

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

nit - not blocker, can be done in subsequent PR - this suppression block is repeated quite often in code. Probably we can use the macros

OTEL_INTERNAL_SUPPRESS_WARNING_PUSH
OTEL_INTERNAL_SUPPRESS_DEPRECATED
// ... code referencing deprecated types ...
OTEL_INTERNAL_SUPPRESS_WARNING_POP

Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

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

LGTM. Good to include in the new release if rest of the reviewers agree.

@marcalff marcalff changed the title Fixes deprecated warning [BUILD] Ignore deprecated warning Feb 7, 2026
@marcalff marcalff merged commit a61d05b into open-telemetry:main Feb 7, 2026
67 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.

Build failure (C4996) when including opentelemetry/logs/provider.h with opentelemetry-cpp[geneva]

4 participants