Skip to content

Conversation

@mexirica
Copy link

@mexirica mexirica commented Dec 3, 2025

Fixes: #6983

This pull request enhances logging and error reporting in the log record attribute handling code, specifically around dropped attributes and duplicate key-value pairs. The main focus is to provide clearer warnings when key-value pairs are dropped due to duplication, and to ensure warnings are only logged when actual drops occur.

Improved logging and error handling for dropped attributes and duplicate keys:

  • Added a new logKeyValuePairDropped warning (using sync.OnceFunc) to log a warning message when key-value pairs are dropped due to key duplication. This ensures that duplicate key drops are clearly reported.
  • Updated methods (addDropped, setDropped) to only log attribute drop warnings when the number of dropped attributes is greater than zero, preventing unnecessary log spam.

Enhancements to attribute deduplication logic:

  • Inserted calls to logKeyValuePairDropped in multiple places within AddAttributes, SetAttributes, and applyValueLimitsAndDedup to log a warning whenever key-value pairs are dropped due to duplication, ensuring better visibility into attribute handling issues.

Code cleanup:

  • Removed redundant calls to addDropped after deduplication, as the logging is now handled directly where drops occur.

@codecov
Copy link

codecov bot commented Dec 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@a86bf87). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff           @@
##             main   #7662   +/-   ##
======================================
  Coverage        ?   86.2%           
======================================
  Files           ?     302           
  Lines           ?   21999           
  Branches        ?       0           
======================================
  Hits            ?   18972           
  Misses          ?    2646           
  Partials        ?     381           
Files with missing lines Coverage Δ
sdk/log/record.go 100.0% <100.0%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mexirica mexirica changed the title [WIP] Fix bad error log Fix bad error log Dec 4, 2025
@mexirica mexirica marked this pull request as ready for review December 4, 2025 18:30
Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

The new tests looks like created with help of GenAI. Can you check it there is no redundancy and try to minimize the amount of new tests? At the same time I do not want to increase the complexity of existing tests (I think it is better to have more tests then fewer that are more complex).

func (r *Record) setDropped(n int) {
logAttrDropped()
r.dropped = n
if n > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

This is another fix that should have a changelog entry.

Copy link
Author

Choose a reason for hiding this comment

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

Added to the changelog

Copy link
Member

Choose a reason for hiding this comment

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

@pellared
Copy link
Member

@mexirica , are you able to address the comments?

@mexirica
Copy link
Author

@mexirica , are you able to address the comments?

Hi, sorry for the delay, Will fix they

@mexirica
Copy link
Author

The new tests looks like created with help of GenAI. Can you check it there is no redundancy and try to minimize the amount of new tests? At the same time I do not want to increase the complexity of existing tests (I think it is better to have more tests then fewer that are more complex).

Reduced the number of tests. If that's still not okay, I can clean up more.

@flc1125 flc1125 mentioned this pull request Dec 29, 2025

- Fix bad log message when key-value pairs are dropped because of key duplication in `go.opentelemetry.io/otel/sdk/log`. (#7662)
- Fix `DroppedAttributes` in `go.opentelemetry.io/otel/sdk/log` to not count the non-attribute key-value pairs dropped because of key duplication. (#7662)
- Fix `setDropped` in `go.opentelemetry.io/otel/sdk/log` to log dropped keys only when the input quantity is greater than zero. (#7662)
Copy link
Member

@pellared pellared Jan 5, 2026

Choose a reason for hiding this comment

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

Suggested change
- Fix `setDropped` in `go.opentelemetry.io/otel/sdk/log` to log dropped keys only when the input quantity is greater than zero. (#7662)
- Fix `SetAttributes` in `go.opentelemetry.io/otel/sdk/log` to not log that attributes are dropped when they are actually not dropped. (#7662)

}
}

func (r *Record) setDropped(n int) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we can now remove setDropped and simply replace it with r.dropped = 0 in SetAttributes method.

}
}

func TestDroppedLoggingOnlyWhenNonZero(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

These test the internals, I do not see any value of these tests as other seem to already cover these cases. This would only make refactoring harder.

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.

sdk/log: Bad log message when key-value pairs are dropped because of key duplication

2 participants