Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions api/include/opentelemetry/logs/event_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ OPENTELEMETRY_BEGIN_NAMESPACE
namespace logs
{
#if OPENTELEMETRY_ABI_VERSION_NO < 2
# 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.

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


Comment on lines +18 to +28
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.

/**
* Handles event log record creation.
**/
Expand Down Expand Up @@ -77,6 +88,14 @@ class OPENTELEMETRY_DEPRECATED EventLogger
void IgnoreTraitResult(ValueType &&...)
{}
};

# if defined(_MSC_VER)
# pragma warning(pop)
# elif defined(__GNUC__) && !defined(__clang__) && !defined(__apple_build_version__)
# pragma GCC diagnostic pop
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic pop
# endif
#endif
} // namespace logs
OPENTELEMETRY_END_NAMESPACE
19 changes: 19 additions & 0 deletions api/include/opentelemetry/logs/event_logger_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ class EventLogger;
class Logger;

#if OPENTELEMETRY_ABI_VERSION_NO < 2
# 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

/**
* Creates new EventLogger instances.
*/
Expand All @@ -32,6 +43,14 @@ class OPENTELEMETRY_DEPRECATED EventLoggerProvider
nostd::shared_ptr<Logger> delegate_logger,
nostd::string_view event_domain) noexcept = 0;
};

# if defined(_MSC_VER)
# pragma warning(pop)
# elif defined(__GNUC__) && !defined(__clang__) && !defined(__apple_build_version__)
# pragma GCC diagnostic pop
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic pop
# endif
#endif
} // namespace logs
OPENTELEMETRY_END_NAMESPACE
40 changes: 21 additions & 19 deletions api/include/opentelemetry/logs/noop.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,22 @@ class NoopLoggerProvider final : public LoggerProvider
};

#if OPENTELEMETRY_ABI_VERSION_NO < 2
# 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

class NoopEventLogger final : public EventLogger
{
public:
NoopEventLogger() : logger_{nostd::shared_ptr<NoopLogger>(new NoopLogger())} {}
~NoopEventLogger() override = default;

const nostd::string_view GetName() noexcept override { return "noop event logger"; }

Expand All @@ -112,27 +124,9 @@ class NoopEventLogger final : public EventLogger
class NoopEventLoggerProvider final : public EventLoggerProvider
{
public:
# 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

NoopEventLoggerProvider() : event_logger_{nostd::shared_ptr<EventLogger>(new NoopEventLogger())}
{}

# if defined(_MSC_VER)
# pragma warning(pop)
# elif defined(__GNUC__) && !defined(__clang__) && !defined(__apple_build_version__)
# pragma GCC diagnostic pop
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic pop
# endif
~NoopEventLoggerProvider() override = default;

nostd::shared_ptr<EventLogger> CreateEventLogger(
nostd::shared_ptr<Logger> /*delegate_logger*/,
Expand All @@ -144,6 +138,14 @@ class NoopEventLoggerProvider final : public EventLoggerProvider
private:
nostd::shared_ptr<EventLogger> event_logger_;
};

# if defined(_MSC_VER)
# pragma warning(pop)
# elif defined(__GNUC__) && !defined(__clang__) && !defined(__apple_build_version__)
# pragma GCC diagnostic pop
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic pop
# endif
#endif

} // namespace logs
Expand Down
27 changes: 22 additions & 5 deletions api/include/opentelemetry/logs/provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ class OPENTELEMETRY_EXPORT Provider
}

#if OPENTELEMETRY_ABI_VERSION_NO < 2
# 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
/**
* Returns the singleton EventLoggerProvider.
*
Expand All @@ -70,6 +80,13 @@ class OPENTELEMETRY_EXPORT Provider
std::lock_guard<common::SpinLockMutex> guard(GetLock());
GetEventProvider() = tp;
}
# if defined(_MSC_VER)
# pragma warning(pop)
# elif defined(__GNUC__) && !defined(__clang__) && !defined(__apple_build_version__)
# pragma GCC diagnostic pop
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic pop
# endif
#endif

private:
Expand All @@ -80,10 +97,6 @@ class OPENTELEMETRY_EXPORT Provider
}

#if OPENTELEMETRY_ABI_VERSION_NO < 2
OPENTELEMETRY_DEPRECATED
OPENTELEMETRY_API_SINGLETON static nostd::shared_ptr<EventLoggerProvider> &
GetEventProvider() noexcept
{
# if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4996)
Expand All @@ -95,8 +108,13 @@ class OPENTELEMETRY_EXPORT Provider
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
# endif

OPENTELEMETRY_DEPRECATED
OPENTELEMETRY_API_SINGLETON static nostd::shared_ptr<EventLoggerProvider> &
GetEventProvider() noexcept
{
static nostd::shared_ptr<EventLoggerProvider> provider(new NoopEventLoggerProvider);
return provider;
}

# if defined(_MSC_VER)
# pragma warning(pop)
Expand All @@ -105,7 +123,6 @@ class OPENTELEMETRY_EXPORT Provider
# elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic pop
# endif
}
#endif

OPENTELEMETRY_API_SINGLETON static common::SpinLockMutex &GetLock() noexcept
Expand Down
21 changes: 21 additions & 0 deletions examples/common/logs_foo_library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,24 @@ target_include_directories(common_logs_foo_library
PUBLIC $<BUILD_INTERFACE:${EXAMPLES_COMMON_DIR}>)

target_link_libraries(common_logs_foo_library PUBLIC opentelemetry-cpp::api)

# Internal deprecated API calling should not failed the build in maintainer mode
if(OTELCPP_MAINTAINER_MODE)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
get_target_property(COMMON_LOGS_FOO_COMPILE_OPTS common_logs_foo_library
COMPILE_OPTIONS)
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 ?

"${COMMON_LOGS_FOO_COMPILE_OPTS}")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
get_target_property(COMMON_LOGS_FOO_COMPILE_OPTS common_logs_foo_library
COMPILE_OPTIONS)
list(REMOVE_ITEM COMMON_LOGS_FOO_COMPILE_OPTS /wd4996)
list(APPEND COMMON_LOGS_FOO_COMPILE_OPTS /w34996)
set_target_properties(
common_logs_foo_library PROPERTIES COMPILE_OPTIONS
"${COMMON_LOGS_FOO_COMPILE_OPTS}")
endif()
endif()
Loading