forked from open-telemetry/opentelemetry-cpp
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Logging API and SDK modifications #12
Closed
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a064d19
Moved log record from stack to heap, removed const
MarkSeufert cea306c
Changed log to Log (camelcase)
MarkSeufert 2c1586f
Added GetName() to logger API, along with tests
MarkSeufert 350097d
Processor accepts shared_ptr instead of unique_ptr
MarkSeufert 7646ea2
Added default values to the required log record fields
MarkSeufert 25a3b1e
Added timestamp injection and tests
MarkSeufert dc8f9b9
Return noop logger when logger limit reached, formatting
MarkSeufert 0ee12c6
Rename trace_flag to trace_flags in LogRecord
595ab5b
Set default traceid, spanid, traceflags in LogRecord.h
6083373
Inject spancontext (traceid, spanid, traceflags)
4c50ef2
Simplified logger context injection, added unit tests
MarkSeufert 18b921a
Changed log(LogRecord) back from log(shared_ptr<LogRecord>)
MarkSeufert ca60fe2
Remove test for default value injection, comments
a30826a
Added const to Log(const LogRecord) and const GetName()
MarkSeufert 36f7ba8
Change test names for better conventions / consistency
e7c67ad
Merge branch 'logs-API-SDK-update' of github.com:open-o11y/openteleme…
d3d13b4
change processor signatures for tests
0c97eae
Remove inMem exporter from build files
e153de5
Made processor.h interface match the processor PR
MarkSeufert d2cbd0f
Changed processor back to using unique_ptr from shared_ptr
MarkSeufert 206e8ca
Modified Log overloads, fixed LogRecord KViterable
MarkSeufert 30affaa
Added logger.Trace(~) overloads and test
MarkSeufert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
foreach(testname logger_provider_test logger_test) | ||
add_executable(${testname} "${testname}.cc") | ||
target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} | ||
foreach(testname provider_test logger_test) | ||
add_executable(logs_api_${testname} "${testname}.cc") | ||
target_link_libraries(logs_api_${testname} ${GTEST_BOTH_LIBRARIES} | ||
${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) | ||
gtest_add_tests(TARGET ${testname} TEST_PREFIX logs. TEST_LIST ${testname}) | ||
gtest_add_tests(TARGET logs_api_${testname} TEST_PREFIX logs. TEST_LIST logs_api_${testname}) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,43 +15,41 @@ using opentelemetry::nostd::shared_ptr; | |
using opentelemetry::nostd::span; | ||
using opentelemetry::nostd::string_view; | ||
|
||
TEST(Logger, GetLoggerDefault) | ||
TEST(LoggerTest, GetLoggerDefaultNoop) | ||
{ | ||
auto lp = Provider::GetLoggerProvider(); | ||
auto logger = lp->GetLogger("TestLogger"); | ||
EXPECT_NE(nullptr, logger); | ||
EXPECT_EQ(logger->GetName(), "noop logger"); | ||
} | ||
|
||
TEST(Logger, GetNoopLoggerName) | ||
{ | ||
auto lp = Provider::GetLoggerProvider(); | ||
auto logger = lp->GetLogger("TestLogger"); | ||
} | ||
|
||
TEST(Logger, GetNoopLoggerNameWithArgs) | ||
TEST(LoggerTest, GetLogger) | ||
{ | ||
auto lp = Provider::GetLoggerProvider(); | ||
|
||
// Get a logger with no arguments | ||
auto logger1 = lp->GetLogger("TestLogger1"); | ||
|
||
// Get a logger with options passed | ||
auto logger2 = lp->GetLogger("TestLogger2", "Options"); | ||
|
||
// Get a logger with arguments | ||
std::array<string_view, 1> sv{"string"}; | ||
span<string_view> args{sv}; | ||
auto logger = lp->GetLogger("NoopLoggerWithArgs", args); | ||
// should probably also test that arguments were set properly too | ||
// by adding a getArgs() method in NoopLogger | ||
auto logger3 = lp->GetLogger("TestLogger3", args); | ||
} | ||
|
||
TEST(Logger, NoopLog) | ||
{ | ||
auto lp = Provider::GetLoggerProvider(); | ||
auto logger = lp->GetLogger("TestLogger"); | ||
LogRecord r; | ||
r.name = "Noop log name"; | ||
logger->log(r); | ||
} | ||
// Define a global log record that will be modified when the Log() method is called | ||
static opentelemetry::nostd::shared_ptr<LogRecord> record_; | ||
|
||
// Define a basic Logger class | ||
class TestLogger : public Logger | ||
{ | ||
void log(const LogRecord &record) noexcept override {} | ||
void Log(const LogRecord &record) noexcept override | ||
{ | ||
record_ = opentelemetry::nostd::shared_ptr<LogRecord>(new LogRecord(record)); | ||
} | ||
const opentelemetry::nostd::string_view GetName() noexcept override { return "test logger"; }; | ||
}; | ||
|
||
// Define a basic LoggerProvider class that returns an instance of the logger class defined above | ||
|
@@ -68,19 +66,67 @@ class TestProvider : public LoggerProvider | |
} | ||
}; | ||
|
||
TEST(Logger, PushLoggerImplementation) | ||
TEST(LoggerTest, PushLoggerImplementation) | ||
{ | ||
// Push the new loggerprovider class into the global singleton | ||
// Push the new loggerprovider class into the API | ||
auto test_provider = shared_ptr<LoggerProvider>(new TestProvider()); | ||
Provider::SetLoggerProvider(test_provider); | ||
|
||
auto lp = Provider::GetLoggerProvider(); | ||
|
||
// GetLogger(name, options) function | ||
// Get a logger instance and check whether it's GetName() method returns | ||
// "test logger" as defined in the custom implementation | ||
auto logger = lp->GetLogger("TestLogger"); | ||
ASSERT_EQ("test logger", logger->GetName()); | ||
} | ||
|
||
// GetLogger(name, args) function | ||
std::array<string_view, 1> sv{"string"}; | ||
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. no harm in leaving this in? 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. Yup it's still in but the GitHub diff tool said that it was taken out and readded somewhere else... confusing |
||
span<string_view> args{sv}; | ||
auto logger2 = lp->GetLogger("TestLogger2", args); | ||
TEST(Logger, LogMethodOverloads) | ||
{ | ||
// Use the same TestProvider and TestLogger from the previous test | ||
auto test_provider = shared_ptr<LoggerProvider>(new TestProvider()); | ||
Provider::SetLoggerProvider(test_provider); | ||
|
||
auto lp = Provider::GetLoggerProvider(); | ||
auto logger = lp->GetLogger("TestLogger"); | ||
|
||
// Check that calling the Log() overloads correctly constructs a log record which is automatically put into the static logger_ for testing | ||
|
||
// Test Log(severity, name, message) method | ||
logger->Log(Severity::kError, "Log Name", "This is the log message"); | ||
ASSERT_EQ(record_->severity, Severity::kError); | ||
ASSERT_EQ(record_->name, "Log Name"); | ||
ASSERT_EQ(record_->body, "This is the log message"); | ||
|
||
// Test Trace(name, KVIterable) method | ||
std::map<std::string, std::string> m = {{"key1", "val1"}, {"key2", "val2"}}; | ||
logger->Trace("Logging a map", m); | ||
ASSERT_EQ(record_->severity, Severity::kTrace); | ||
ASSERT_EQ(record_->name, "Logging a map"); | ||
ASSERT_EQ(record_->attributes->size(), 2); | ||
} | ||
|
||
TEST(LogRecord, SetDefault) | ||
{ | ||
LogRecord r; | ||
|
||
// Check that the timestamp is set to 0 by default | ||
ASSERT_EQ(r.timestamp, opentelemetry::core::SystemTimestamp(std::chrono::seconds(0))); | ||
|
||
// Check that the severity is set to kDefault by default | ||
ASSERT_EQ(r.severity, Severity::kDefault); | ||
|
||
// Check that trace_id is set to all zeros by default | ||
char trace_buf[32]; | ||
r.trace_id.ToLowerBase16(trace_buf); | ||
ASSERT_EQ(std::string(trace_buf, sizeof(trace_buf)), "00000000000000000000000000000000"); | ||
|
||
// Check that span_id is set to all zeros by default | ||
char span_buf[16]; | ||
r.span_id.ToLowerBase16(span_buf); | ||
ASSERT_EQ(std::string(span_buf, sizeof(span_buf)), "0000000000000000"); | ||
|
||
// Check that trace_flags is set to all zeros by default | ||
char flags_buf[2]; | ||
r.trace_flags.ToLowerBase16(flags_buf); | ||
ASSERT_EQ(std::string(flags_buf, sizeof(flags_buf)), "00"); | ||
} |
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Add
ASSERT_EQ(logger2->GetName(), "TestLogger2")
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.
The API implementation returns a noop instance, so the name would always be "noop logger" which is what the first test checks for