Skip to content

Logging API and SDK modifications#12

Closed
MarkSeufert wants to merge 22 commits intomasterfrom
logs-API-SDK-update
Closed

Logging API and SDK modifications#12
MarkSeufert wants to merge 22 commits intomasterfrom
logs-API-SDK-update

Conversation

@MarkSeufert
Copy link
Copy Markdown

@MarkSeufert MarkSeufert commented Dec 1, 2020

This PR addresses many of the comments we received when we PRed the initial Logging API and initial Logging SDK.

  • Added default values to several LogRecord fields in API, which the SDK overwrites if the user didn’t specify. The values the SDK overwrites are the timestamp, traceid, spanid, and traceflags.
  • Added a logger limit to the SDK LoggerProvider, which returns a noop logger if the limit has been reached. This is to ensure no unbounded memory usage if the user accidentally creates an arbitrary number.
  • Added GetName() method to logger API and SDK.
  • Added overloads for the Logger API methods
  • Added unit tests for all the above functionality
  • Made updates to the test suite and file names for better consistency with trace naming conventions

Note this PR relies on #403 to be merged to compile.

cc - @alolita @xukaren

Comment thread api/include/opentelemetry/logs/logger.h Outdated
* which should at minimum assign the trace_id, span_id, and timestamp
*/
virtual void log(const LogRecord &record) noexcept = 0;
virtual void Log(LogRecord &record) noexcept = 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const?

Comment thread api/test/logs/logger_test.cc Outdated
logger->log(r);
r.name = "Log Record";
r.severity = Severity::kInfo;
logger->Log(r);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verify what log record actually gets created by Log() methods?

* @param record The record to write into the processor.
*/
void log(const opentelemetry::logs::LogRecord &record) noexcept override;
void Log(opentelemetry::logs::LogRecord &record) noexcept override;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more const?

Comment thread sdk/src/logs/logger.cc Outdated
// Inject values into record if not user specified
// Timestamp
if (r->timestamp == opentelemetry::core::SystemTimestamp(std::chrono::seconds(0)))
r->timestamp = core::SystemTimestamp(std::chrono::system_clock::now());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with other single line if statements recommend using { and }

auto logger = lp->GetLogger("TestLogger");

// GetLogger(name, args) function
std::array<string_view, 1> sv{"string"};
Copy link
Copy Markdown

@kxyr kxyr Dec 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no harm in leaving this in?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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

std::array<string_view, 1> sv{"string"};
span<string_view> args{sv};
auto logger2 = lp->GetLogger("TestLogger2", args);
ASSERT_EQ("test logger", logger->GetName());
Copy link
Copy Markdown

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")

Copy link
Copy Markdown
Author

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

Comment thread api/include/opentelemetry/logs/logger.h Outdated
/* Returns the name of the logger */
// TODO: decide whether this is useful and/or should be kept, as this is not a method required in
// the specification. virtual nostd::string_view getName() = 0;
virtual nostd::string_view GetName() noexcept = 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make const?

@kxyr kxyr closed this Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants