Skip to content

sdk/log: Deduplicate key-value collections in Record.SetBody #7002

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

Mojachieee
Copy link
Contributor

Fixes #6982

Copy link

codecov bot commented Jul 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@0485596). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff           @@
##             main   #7002   +/-   ##
======================================
  Coverage        ?   82.8%           
======================================
  Files           ?     262           
  Lines           ?   24362           
  Branches        ?       0           
======================================
  Hits            ?   20176           
  Misses          ?    3811           
  Partials        ?     375           
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.

@MrAlias
Copy link
Contributor

MrAlias commented Jul 14, 2025

This is not a part of the specification. Doesn't adding this move up further away from the defined specification behavior?

@pellared
Copy link
Member

pellared commented Jul 14, 2025

This is not a part of the specification. Doesn't adding this move up further away from the defined specification behavior?

@MrAlias, what do you have in mind?

"deduplication" of the key-values is part of the specification and it also involves Body of the log record.
Body is of any type (https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-body).
any can have a map<string, any> (https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#type-any).
map<string, any> does not allow duplicated keys (https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#type-mapstring-any).

Or are you concerned about the option added in #6968?

Or maybe #7002 (comment)? EDIT: already addressed

@pellared pellared moved this from Todo to In Progress in Go: Logs (GA) Jul 14, 2025
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.

nit comments

@@ -170,7 +170,11 @@ func (r *Record) Body() log.Value {

// SetBody sets the body of the log record.
func (r *Record) SetBody(v log.Value) {
r.body = v
if !r.allowDupKeys {
r.body = r.dedupeBodyCollections(v)
Copy link
Contributor

Choose a reason for hiding this comment

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

What affect does this have on the performance of SetBody?

Copy link
Member

Choose a reason for hiding this comment

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

At this point of time we should do the deduplication anyway (to be compliant with the specification).

The performance benefit of not doing (when allowDupKeys is true) it is pretty irrelevant given we will remove this opt-in performance optimization probably in v1.39.0. Therefore, I do not think it is worth adding a new benchmark. More here: #7002 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

This should likely be done in a lazy manner. Having performance information about the approach presented here will provide evidence to how critical that work is going to be.

Copy link
Member

@pellared pellared Jul 16, 2025

Choose a reason for hiding this comment

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

We have benchmarks for the same on log record attributes: #6968 (comment) this is also why I thought that maybe we do not more 😉

However, I think it would be easier and less-controversial to just add benchmarks for Record.SetBody.
@Mojachieee, can you add them and add the results to the PR description?

@pellared
Copy link
Member

pellared commented Jul 16, 2025

With OTEP: Extending attributes to support complex values #4485 finally being merged (which was not certain at all) we most likely would not need this change as we will get rid of log.Value in favor of attribute.Value which at this point of time does not allow key-value collections. The attribute.Map and attribute.MapValue that is going to be added is planned to be handling the deduplication on creation time (see #6809).

Still, I am fine having this PR merged as I think it is better to start changing the Logs API and SDK to use attribute.Value instead of log.Value (which is going to be removed) AFTER the upcoming release (so e.g. for v1.39.0).

EDIT: I created #7034

@pellared pellared requested a review from MrAlias July 16, 2025 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

sdk/log: Deduplicate key-value collections in Record.SetBody
4 participants