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

Add a Recordable interface, implementation, and tests for logs #438

Merged
merged 23 commits into from
Dec 14, 2020

Conversation

kxyr
Copy link
Contributor

@kxyr kxyr commented Dec 10, 2020

This PR implements a recordable for logs, as part of the logging prototype, and also resolving issue #412.

This PR:

  • Adds a Recordable interface for logs
  • Add a default LogRecord Recordable implementation, with unit tests
  • Changes the methods and signatures to take in a Recordable instead of the previous LogRecord struct, across the processor and exporter files
  • Refactors all affected files (e.g. tests for the logging API, SDK, and processors)

API/SDK changes:

  • Gets the TraceId, SpanId, TraceFlags, and current Timestamp in the SDK and injects into the LogRecord if it is not user-specified.
  • Removed the Severity::kDefault enum value (originally set as kInfo), and added a Severity::kInvalid= 0. (Setting the default Severity to kInfo has been moved to the SDK instead of the API)

Other minor changes:

  • Removes the LogRecord struct from the API
  • Stylistic change: Renames the log() methods to Log(), and adds this-> before calling Log() methods

This PR introduces changes that blocks a few other open PRs: #422, #430, #434, and #435.

cc @MarkSeufert @alolita

@kxyr kxyr requested a review from a team December 10, 2020 22:41
@codecov
Copy link

codecov bot commented Dec 10, 2020

Codecov Report

Merging #438 (eaeba47) into master (ec6b6c7) will decrease coverage by 0.32%.
The diff coverage is 80.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #438      +/-   ##
==========================================
- Coverage   94.52%   94.19%   -0.33%     
==========================================
  Files         178      182       +4     
  Lines        7701     7853     +152     
==========================================
+ Hits         7279     7397     +118     
- Misses        422      456      +34     
Impacted Files Coverage Δ
sdk/include/opentelemetry/sdk/logs/exporter.h 100.00% <ø> (ø)
sdk/include/opentelemetry/sdk/logs/logger.h 100.00% <ø> (ø)
...k/include/opentelemetry/sdk/logs/logger_provider.h 100.00% <ø> (ø)
sdk/include/opentelemetry/sdk/logs/processor.h 100.00% <ø> (ø)
...lude/opentelemetry/sdk/logs/simple_log_processor.h 100.00% <ø> (ø)
sdk/test/logs/logger_provider_sdk_test.cc 80.00% <0.00%> (-4.85%) ⬇️
...include/opentelemetry/sdk/common/attribute_utils.h 32.00% <32.00%> (ø)
api/test/logs/logger_test.cc 94.59% <33.33%> (-2.78%) ⬇️
sdk/src/logs/logger.cc 69.04% <64.86%> (-30.96%) ⬇️
sdk/test/logs/simple_log_processor_test.cc 92.72% <83.33%> (-3.50%) ⬇️
... and 17 more

sdk/src/logs/logger.cc Outdated Show resolved Hide resolved
Copy link
Contributor

@maxgolov maxgolov left a comment

Choose a reason for hiding this comment

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

Good, with minor suggestions.

Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

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

Thanks for working on this PR. We are now using the right approach to propagate logs to exporter : )

resource.begin(), resource.end()},
nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
attributes.begin(), attributes.end()},
trace_id, span_id, trace_flags);
Copy link
Member

Choose a reason for hiding this comment

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

Nice to see this initializer_list for resource and attributes.

api/include/opentelemetry/logs/logger.h Outdated Show resolved Hide resolved
sdk/include/opentelemetry/sdk/logs/attribute_utils.h Outdated Show resolved Hide resolved
sdk/src/logs/logger.cc Outdated Show resolved Hide resolved
@kxyr kxyr changed the title Implementing a Recordable interface for logs Add a Recordable interface and implementation for logs Dec 11, 2020
Copy link
Contributor

@pyohannes pyohannes left a comment

Choose a reason for hiding this comment

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

Thanks for refactoring this! That's much closer to a design that is production-ready.

sdk/src/logs/logger.cc Show resolved Hide resolved
sdk/src/logs/logger.cc Outdated Show resolved Hide resolved
sdk/src/logs/logger.cc Outdated Show resolved Hide resolved
sdk/src/logs/BUILD Outdated Show resolved Hide resolved

log(r);
// Set default values for unspecified fields, then call the base Log() method
void Log(Severity severity, nostd::string_view message, core::SystemTimestamp time) noexcept
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have time first in the virtual Log call, but severity first here? I think we should keep the order of the arguments consistent.

Copy link
Contributor Author

@kxyr kxyr Dec 12, 2020

Choose a reason for hiding this comment

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

Hmm since it seems most ergonomic/common use case is to users to specify severity, then message, since timestamp would be set by default in common use cases. I can move timestamp to the end of the main Log() method for consistent ordering with this method here

api/include/opentelemetry/logs/logger.h Outdated Show resolved Hide resolved
Copy link
Contributor

@jsuereth jsuereth left a comment

Choose a reason for hiding this comment

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

Nice work! Just a few minor nits from me, but thanks very much for tackling this!!

sdk/src/logs/logger.cc Outdated Show resolved Hide resolved
sdk/include/opentelemetry/sdk/logs/logger.h Outdated Show resolved Hide resolved
Copy link
Contributor

@jsuereth jsuereth left a comment

Choose a reason for hiding this comment

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

Great work!

@kxyr
Copy link
Contributor Author

kxyr commented Dec 13, 2020

@pyohannes @lalitb Would this be good to merge now?

@kxyr kxyr changed the title Add a Recordable interface and implementation for logs Add a Recordable interface, implementation, and tests for logs Dec 13, 2020
@lalitb
Copy link
Member

lalitb commented Dec 14, 2020

@xukaren - Please rebase the branch with base, so we should be ready to merge it. thanks.

@kxyr
Copy link
Contributor Author

kxyr commented Dec 14, 2020

@xukaren - Please rebase the branch with base, so we should be ready to merge it. thanks.

Done!

@lalitb lalitb merged commit 106c00a into open-telemetry:master Dec 14, 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.

6 participants