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

Log a warning when log Record attribute is dropped #5376

Merged
merged 11 commits into from
May 28, 2024

Conversation

MrAlias
Copy link
Contributor

@MrAlias MrAlias commented May 17, 2024

Fix #5317

According to the specification, there should be a message printed in the SDK's log to indicate to the user that an attribute was discarded due to such a limit. To prevent excessive logging, the message must be printed at most once per LogRecord (i.e., not per discarded attribute).

This change centralizes the Record dropped field writes and calls a global logging function. This will at most log once per any Record dropping attributes, meeting the specification requirement.

This does not log once per Record when an attribute is dropped. To do that we would need to maintain state within the Record (i.e. sync.Mutex or sync.Once). These types cannot be copied, meaning the Record would take on this "no copy" requirement. This seems too restrictive and with the permissive specification allowing a single log line, that is the solution added.

@MrAlias MrAlias added pkg:SDK Related to an SDK package area:logs Part of OpenTelemetry logs labels May 17, 2024
Copy link

codecov bot commented May 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.5%. Comparing base (515d2c4) to head (111adce).

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #5376   +/-   ##
=====================================
  Coverage   84.5%   84.5%           
=====================================
  Files        268     268           
  Lines      17808   17818   +10     
=====================================
+ Hits       15064   15074   +10     
  Misses      2430    2430           
  Partials     314     314           
Files Coverage Δ
sdk/log/record.go 100.0% <100.0%> (ø)

@MrAlias MrAlias marked this pull request as ready for review May 17, 2024 19:17
CHANGELOG.md Outdated Show resolved Hide resolved
@MrAlias MrAlias merged commit be1b9cf into open-telemetry:main May 28, 2024
27 checks passed
@MrAlias MrAlias deleted the log-dropped-attr branch May 28, 2024 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:logs Part of OpenTelemetry logs pkg:SDK Related to an SDK package
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

sdk/log: Log when an attribute was discarded or truncated due to limits
5 participants