Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile errors appear when i import api/opentelemetry/logs/logger.h #1590

Closed
NJU-Eden opened this issue Sep 2, 2022 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@NJU-Eden
Copy link

NJU-Eden commented Sep 2, 2022

I import opentelemetry-cpp with tag 1.5.0 in my project by bazel. My environment is centos7 with gcc 8.4.0.

if i include api/opentelemetry/logs/logger.h file and donot do anything else, the error appears

bazel-out/k8-fastbuild/bin/external/io_opentelemetry_cpp/api/_virtual_includes/api/opentelemetry/logs/logger.h:167:57: error: macro "Log" requires 4 arguments, but only 2 given
void Log(Severity severity, nostd::string_view message) noexcept
^
bazel-out/k8-fastbuild/bin/external/io_opentelemetry_cpp/api/_virtual_includes/api/opentelemetry/logs/logger.h:185:50: error: macro "Log" requires 4 arguments, but only 2 given
void Log(Severity severity, const T &attributes) noexcept
^
bazel-out/k8-fastbuild/bin/external/io_opentelemetry_cpp/api/_virtual_includes/api/opentelemetry/logs/logger.h:235:73: error: macro "Log" requires 4 arguments, but only 2 given
void Log(Severity severity, const common::KeyValueIterable &attributes) noexcept
^
bazel-out/k8-fastbuild/bin/external/io_opentelemetry_cpp/api/_virtual_includes/api/opentelemetry/logs/logger.h: In member function 'void opentelemetry::v1::logs::Logger::Trace(const T&)':
bazel-out/k8-fastbuild/bin/external/io_opentelemetry_cpp/api/_virtual_includes/api/opentelemetry/logs/logger.h:281:11: error: 'class opentelemetry::v1::logs::Logger' has no member named 'Log'; did you mean 'OI_Log'?
this->Log(Severity::kTrace, attributes);
^~~
OI_Log

@NJU-Eden NJU-Eden added the bug Something isn't working label Sep 2, 2022
@marcalff
Copy link
Member

marcalff commented Sep 2, 2022

Please check the project code, and any file included before api/opentelemetry/logs/logger.h, for a Log macro.

If such macro is present, it will confuse the compiler when reading the logger.h header file, causing the errors seen.

@owent
Copy link
Member

owent commented Sep 3, 2022

You may try to wrapper pragma push_macro/pop_macro when including logs headers if your project has define Log as a macro. e.g.

#pragma push_macro("Log")
#ifdef Log
#undef Log
#endif

#include < api/opentelemetry/logs/logger.h>

#pragma pop_macro("Log")

@lalitb
Copy link
Member

lalitb commented Sep 6, 2022

Not directly related to this issue, but with the recent changes in the Logs API (open-telemetry/opentelemetry-specification#2676), and potentially in Logs SDK ( open-telemetry/opentelemetry-specification#2768), we may want to change the method name to Logger::Emit() for both Logs and Events.

Closing this issue, as this seems to be macro with same name.

@lalitb lalitb closed this as completed Sep 6, 2022
@ThomsonTan
Copy link
Contributor

ThomsonTan commented Sep 6, 2022

As the names like Log or Emit is very common to be defined as macro in app code, perhaps we (in logger.h) could checked whether it is pre-defined and prompt the user with more helpful message?

#ifdef Log
#error macro Log is defined outside of opentelemetry, please consider rename it or wrap opentelemetry/logger.h with push_macro/pop_macro
#endif

@lalitb
Copy link
Member

lalitb commented Sep 6, 2022

Non capitalized macros are always evil and should be avoided for errors like above. I don't think we should handle these validations in opentelemetry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants