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

[API] DO not allow unsafe Logger::EmitLogRecord #2673

Merged

Conversation

owent
Copy link
Member

@owent owent commented May 21, 2024

Fixes #2666

Changes

  • Do not allow unsafe Logger::EmitLogRecord

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@owent owent requested a review from a team May 21, 2024 07:55
@@ -145,6 +146,10 @@ struct LogRecordSetterTrait<common::KeyValueIterable>
template <class ValueType>
struct LogRecordSetterTrait
{
static_assert(!std::is_same<nostd::unique_ptr<LogRecord>, ValueType>::value &&
!std::is_same<std::unique_ptr<LogRecord>, ValueType>::value,
"unique_ptr<LogRecord> is not allowed");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"unique_ptr<LogRecord> is not allowed");
"unique_ptr<LogRecord> is not allowed, use std::move()");

Also, consider adding an assert for LogRecord*

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, it's done

Copy link
Member

@marcalff marcalff 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 the fix, see suggestion.

@marcalff marcalff changed the title DO not allow unsafe Logger::EmitLogRecord [API] DO not allow unsafe Logger::EmitLogRecord May 23, 2024
Copy link

codecov bot commented May 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.70%. Comparing base (497eaf4) to head (eea093d).
Report is 66 commits behind head on main.

Current head eea093d differs from pull request most recent head 1f23592

Please upload reports for the commit 1f23592 to get more accurate results.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2673      +/-   ##
==========================================
+ Coverage   87.12%   87.70%   +0.58%     
==========================================
  Files         200      190      -10     
  Lines        6109     5852     -257     
==========================================
- Hits         5322     5132     -190     
+ Misses        787      720      -67     
Files Coverage Δ
...pi/include/opentelemetry/logs/logger_type_traits.h 100.00% <ø> (+16.00%) ⬆️

... and 56 files with indirect coverage changes

Copy link
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix.

@marcalff marcalff merged commit 17c3bc6 into open-telemetry:main May 28, 2024
48 checks passed
@owent owent deleted the do_now_allow_emit_unsafe_log_record branch June 21, 2024 06:18
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.

[API] Logger::EmitLogRecord() is unsafe to use
2 participants