Skip to content

Conversation

@bogdandrutu
Copy link
Member

This new API is intended to be similar with "LoadOrStore" from the sync.Map and a helper to avoid iterating over the map (lookup) twice for when we need to only insert a key if it does not exists.

Example https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/internal/coreinternal/attraction/attraction.go#L307:

if _, found = attrs.Get(action.Key); found {
	continue
}
av.CopyTo(attrs.PutEmpty(action.Key))

We lookup key in Get as well as PutEmpty, and this can be re-written as:

if val, found = attrs.GetOrPutEmpty(action.Key); !found {
	av.CopyTo(val)
}

@bogdandrutu bogdandrutu requested review from a team and dmitryax as code owners October 14, 2025 20:26
@codecov
Copy link

codecov bot commented Oct 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.68%. Comparing base (1169338) to head (349e0e1).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14023      +/-   ##
==========================================
+ Coverage   91.66%   91.68%   +0.02%     
==========================================
  Files         654      654              
  Lines       42626    42633       +7     
==========================================
+ Hits        39072    39087      +15     
+ Misses       2741     2735       -6     
+ Partials      813      811       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dmitryax
Copy link
Member

Hm.. The new chlogen validation doesn't work for this case. pkg/pdata would make it, not ideal though

Can you please add some coverage as well?

@bogdandrutu bogdandrutu added this pull request to the merge queue Oct 16, 2025
Merged via the queue into open-telemetry:main with commit 5a0883d Oct 16, 2025
60 checks passed
@bogdandrutu bogdandrutu deleted the get-or-put-empty branch October 16, 2025 15:28
@github-actions github-actions bot added this to the next release milestone Oct 16, 2025
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.

2 participants