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

Logging API and SDK modifications #12

Closed
wants to merge 22 commits into from
Closed

Conversation

MarkSeufert
Copy link

@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

@@ -59,47 +58,51 @@ class Logger
* A default LogRecord that will be assigned if no parameters are passed to Logger's .log() method
* 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;

Choose a reason for hiding this comment

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

const?

logger->log(r);
r.name = "Log Record";
r.severity = Severity::kInfo;
logger->Log(r);

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?


/**
* Writes a log record into the processor.
* @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;

Choose a reason for hiding this comment

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

No more const?

// 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());

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

@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
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

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

@@ -39,8 +39,7 @@ class Logger
virtual ~Logger() = default;

/* 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

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