Skip to content

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

Merged
lalitb merged 23 commits intoopen-telemetry:masterfrom
open-o11y:logs-recordable
Dec 14, 2020
Merged

Add a Recordable interface, implementation, and tests for logs#438
lalitb merged 23 commits intoopen-telemetry:masterfrom
open-o11y:logs-recordable

Conversation

@kxyr
Copy link
Copy Markdown
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
Copy Markdown

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

Comment thread api/include/opentelemetry/logs/logger.h Outdated
Comment thread api/include/opentelemetry/logs/logger.h Outdated
Comment thread api/include/opentelemetry/logs/logger.h Outdated
Comment thread api/include/opentelemetry/logs/logger.h
Comment thread api/include/opentelemetry/logs/logger.h Outdated
Comment thread api/include/opentelemetry/logs/severity.h Outdated
Comment thread sdk/include/opentelemetry/sdk/logs/attribute_utils.h Outdated
Comment thread sdk/include/opentelemetry/sdk/logs/attribute_utils.h Outdated
Comment thread sdk/src/logs/logger.cc
Comment thread sdk/src/logs/logger.cc
Comment thread sdk/src/logs/logger.cc Outdated
Copy link
Copy Markdown
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
Copy Markdown
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 : )

Comment thread api/include/opentelemetry/logs/logger.h Outdated
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
Copy Markdown
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.

Comment thread api/include/opentelemetry/logs/logger.h Outdated
Comment thread sdk/include/opentelemetry/sdk/logs/attribute_utils.h Outdated
Comment thread api/include/opentelemetry/logs/logger.h Outdated
Comment thread sdk/include/opentelemetry/sdk/logs/attribute_utils.h Outdated
Comment thread sdk/src/logs/logger.cc Outdated
@kxyr kxyr changed the title Implementing a Recordable interface for logs Add a Recordable interface and implementation for logs Dec 11, 2020
Copy link
Copy Markdown
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.

Comment thread sdk/src/logs/logger.cc
Comment thread sdk/src/logs/logger.cc Outdated
Comment thread sdk/src/logs/logger.cc Outdated
Comment thread sdk/src/logs/BUILD Outdated
Comment thread api/include/opentelemetry/logs/logger.h Outdated

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

Comment thread api/include/opentelemetry/logs/logger.h Outdated
Copy link
Copy Markdown
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!!

Comment thread sdk/src/logs/logger.cc Outdated
Comment thread sdk/include/opentelemetry/sdk/logs/logger.h Outdated
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
GerHobbelt pushed a commit to GerHobbelt/opentelemetry-cpp that referenced this pull request Mar 6, 2026
…ctions/actions/download-artifact-634f93cb2916e3fdff6788551b99b062d0335ce0

Bump actions/download-artifact from 448e3f862ab3ef47aa50ff917776823c9946035b to 634f93cb2916e3fdff6788551b99b062d0335ce0
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