-
Notifications
You must be signed in to change notification settings - Fork 455
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
Fix global log handle symbols when using dlopen #1420
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,18 @@ cc_library( | |
include_prefix = "src/common", | ||
deps = [ | ||
"//api", | ||
"//sdk:headers", | ||
"//sdk/src/common/platform:fork", | ||
], | ||
) | ||
|
||
cc_library( | ||
name = "global_log_handler", | ||
srcs = [ | ||
"global_log_handler.cc", | ||
], | ||
deps = [ | ||
"//api", | ||
"//sdk:headers", | ||
], | ||
) | ||
Comment on lines
+35
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not familiar with BAZEL, and I am confused by the build script here. The bazel build defines two libraries, "random" and "global_log_handler", while the CMake build defines only one library, named "opentelemetry_common" This is a pre existing issue, but how come file random.cc is compiled in library "random" with bazel, and "opentelemetry_common" with CMake ? I would expect both build to produce the same libraries with the same name, and put the same *.cc code in the same *.so library. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, though not related to this PR, it would be good to have both cmake and bazel produce a consistent set of libraries. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree too. We can raise another PR to produce a consistent set of libraries between bazel and cmake.There are more libraries names need be reviewed. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "opentelemetry/sdk/common/global_log_handler.h" | ||
|
||
#include <cstring> | ||
#include <random> | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace common | ||
{ | ||
namespace internal_log | ||
{ | ||
|
||
LogHandler::~LogHandler() {} | ||
|
||
void DefaultLogHandler::Handle(LogLevel level, | ||
const char *file, | ||
int line, | ||
const char *msg, | ||
const sdk::common::AttributeMap &attributes) noexcept | ||
{ | ||
std::stringstream output_s; | ||
output_s << "[" << LevelToString(level) << "] "; | ||
if (file != nullptr) | ||
{ | ||
output_s << "File: " << file << ":" << line; | ||
} | ||
if (msg != nullptr) | ||
{ | ||
output_s << msg; | ||
} | ||
output_s << std::endl; | ||
// TBD - print attributes | ||
std::cout << output_s.str(); // thread safe. | ||
} | ||
|
||
void NoopLogHandler::Handle(LogLevel, | ||
const char *, | ||
int, | ||
const char *, | ||
const sdk::common::AttributeMap &) noexcept | ||
{} | ||
|
||
std::pair<nostd::shared_ptr<LogHandler>, LogLevel> &GlobalLogHandler::GetHandlerAndLevel() noexcept | ||
{ | ||
static std::pair<nostd::shared_ptr<LogHandler>, LogLevel> handler_and_level{ | ||
nostd::shared_ptr<LogHandler>(new DefaultLogHandler), LogLevel::Warning}; | ||
Comment on lines
+49
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The singleton is in the *.cc file now, great. As a side note, I reviewed every occurrence of the There are a few other static variables used, but none of them are required to be unique, so the scope of the fix is really narrowed down to this one alone, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we can raise another issue to move all static variables into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, filed issue #1429 then. |
||
return handler_and_level; | ||
} | ||
|
||
} // namespace internal_log | ||
} // namespace common | ||
} // namespace sdk | ||
OPENTELEMETRY_END_NAMESPACE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add this for other exporters too. Eg, zipkin exporter includes sdk_config.h, which further includes global_log_handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exporters shoud denpend on
//sdk/src/logs
,//sdk/src/metrics
or//sdk/src/trace
, which already depend//sdk/src/common:global_log_handler