Skip to content

fix(logs): log discarded attributes once per record - #2463

Open
naveedsajjdawan wants to merge 7 commits into
open-telemetry:mainfrom
naveedsajjdawan:fix/log-record-discard-logging
Open

naveedsajjdawan wants to merge 7 commits into
open-telemetry:mainfrom
naveedsajjdawan:fix/log-record-discard-logging

Conversation

@naveedsajjdawan

Copy link
Copy Markdown

Summary

Fixes #2351 by ensuring attribute-discard diagnostics are emitted at most once for each LogRecord.

Changes

  • Log when attributes are removed by the configured attribute-count limit.
  • Route invalid-key and invalid-value diagnostics through a per-record guard so multiple invalid attributes do not produce repeated messages.
  • Add regression tests for repeated invalid attributes, count-limit truncation, and both paths occurring on the same record.

Testing

The regression tests have been added but have not been run locally in this environment. Please check CI before merging.

@kaylareopelle kaylareopelle left a comment

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.

Hi @naveedsajjdawan! Thanks for opening this PR. I have a few comments. It also looks like there's a Rubocop offense to address.

OpenTelemetry.handle_error(message: "Invalid log record attribute key type #{k.class} for " \
"key #{k.inspect} on record: '#{body}'. Attribute keys must be Strings. Dropping attribute.")
log_attribute_discard("Invalid log record attribute key type #{k.class} for " \
"key #{k.inspect} on record: '#{body}'. Attribute keys must be Strings. Dropping attribute.")

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.

We've had some feedback that body shouldn't be included here.

Suggested change
"key #{k.inspect} on record: '#{body}'. Attribute keys must be Strings. Dropping attribute.")
"key #{k.inspect}. Attribute keys must be Strings. Dropping attribute.")

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.

We're also missing a test that makes sure that attribute key warnings are only logged once per log record.

OpenTelemetry.handle_error(message: "Invalid log record attribute value type #{v.class} for key '#{k}' " \
"on record: '#{body}'. Dropping attribute.")
log_attribute_discard("Invalid log record attribute value type #{v.class} for key '#{k}' " \
"on record: '#{body}'. Dropping attribute.")

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.

We've had some feedback that body shouldn't be included in the message. This will keep things less verbose.

Suggested change
"on record: '#{body}'. Dropping attribute.")
". Dropping attribute.")

return if @attribute_discard_logged

@attribute_discard_logged = true
OpenTelemetry.handle_error(message: message)

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.

Though this is what was there before, other language implementations use OpenTelemetry.logger.warn here instead. This seems more appropriate since there isn't an error with the Logs SDK, and rather a user mismatch with our limits. Let's change this to a warn-level log.

Suggested change
OpenTelemetry.handle_error(message: message)
OpenTelemetry.logger.warn(message)

attributes: { 'a' => Class.new, 'b' => Class.new, 'c' => 'c' }
)

assert_equal(1, log_stream.string.lines.length)

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.

Could we add an assertion to make sure the right message is emitted?

This branch has not been deployed

No deployments
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.

Log attribute-discard messages at most once per LogRecord (both truncation paths)

2 participants