[BUILD] Revisit EventLogger deprecation#3855
[BUILD] Revisit EventLogger deprecation#3855marcalff wants to merge 10 commits intoopen-telemetry:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3855 +/- ##
=======================================
Coverage 89.99% 89.99%
=======================================
Files 225 225
Lines 7170 7170
=======================================
Hits 6452 6452
Misses 718 718
🚀 New features to boost your workflow:
|
|
I'm not fully clear on the intent behind these changes. My understanding is that anyone using EventLogger should receive a deprecation warning. That was broken in #3845, and from what I can tell, this change doesn't restore that behavior either - so what's the purpose of removing the warning? |
|
The main problem is to decide clearly what opentelemetry-cpp wants to do with deprecation for EventLogger in particular. Option 1We mark code with Anyone who uses a deprecated class gets a warning. This includes:
This creates a problem for applications, even when not using EventLogger, because the simple fact of including "provider.h" (which is required and can not be avoided) causes the build to fail with -Wall -Werr. Option 2We do not mark code with This is what this PR does. Option 1 is what was done since the beginning with #3285, but recently issue #3835 was reported complaining (correctly) that there is no way to have a clean build, and this was "fixed" by suppressing all warnings with #3845. If we prefer to have warnings, we need to rollback #3845. If we prefer to not have warnings, we need this PR to clean up the code. Leaving both The root cause of all this is that, when a deprecation is added, there should be a migration path for users to take and avoid using the deprecated code. In this case, because the Get/Set EventLoggerProvider methods are inline, part of the API, and located in a mandatory header file, there is no way for user code to avoid compiling deprecated code, so there is no way to resolve deprecation warnings if present. We can not (even with conditional compilation) opt out for these methods either, as this will break the ABI for version 1. |
|
Thanks @marcalff. I agree that having both However, I don't think this is strictly Option 1 vs Option 2. There's an Option 3: The concern with Option 1 is that including The fix is to put
This is true for MSVC (which warns at declaration), but pragma push/pop around the method declarations in the header handles exactly that - it suppresses the MSVC declaration-site warning so including the header is clean. On GCC/Clang, So:
This gives users a clean build when they only use We could also enforce this in CI by adding a small compile test target that compiles with |
|
Thanks for the comments. I implemented:
which is basically option 3. The claim that MSVC raises a deprecation warning at declaration site is very weird to me, so I wanted to see this for myself to confirm, and used deprecated provider set/get methods without the warning suppression code. It turns out, from the CI logs even on windows, that no warning are generated, unless I missed something in build logs. Starting fresh with all the related cleanup done in EventLogger classes, code like: OPENTELEMETRY_DEPRECATED static nostd::shared_ptr<EventLoggerProvider>
GetEventLoggerProvider() noexcept
{
std::lock_guard<common::SpinLockMutex> guard(GetLock());
return nostd::shared_ptr<EventLoggerProvider>(GetEventProvider());
}behaves as it should. I suspect that the following helps:
so that no warnings are generated at declaration time, even on MSVC. Please double check with a local build if possible. |
|
For MSVC, that’s generally true—especially for deprecation warnings (e.g., C4996), which are typically emitted at the point of use (the call site) rather than at the declaration.
|
| PUBLIC $<BUILD_INTERFACE:${EXAMPLES_COMMON_DIR}>) | ||
|
|
||
| target_link_libraries(common_logs_foo_library PUBLIC opentelemetry-cpp::api) | ||
|
|
There was a problem hiding this comment.
This ensures users don’t see deprecation warnings or warnings-as-errors when including opentelemetry/logs/logger.h or opentelemetry/logs/logger_provider.h without using deprecated APIs. Should we keep it here?
Fixes # (issue)
Changes
Please provide a brief description of the changes here.
EventLogger.For significant contributions please make sure you have completed the following items:
CHANGELOG.mdupdated for non-trivial changes