Skip to content

[pkg/ottl] Add GetOr function to ottl.Optional#40243

Merged
evan-bradley merged 6 commits intoopen-telemetry:mainfrom
edmocosta:add-ottl-optional-getor
Jul 7, 2025
Merged

[pkg/ottl] Add GetOr function to ottl.Optional#40243
evan-bradley merged 6 commits intoopen-telemetry:mainfrom
edmocosta:add-ottl-optional-getor

Conversation

@edmocosta
Copy link
Contributor

Description

The main goal of this new function is to avoid repeating the following common pattern in functions with optional arguments:

value := "foo"
if !optArgument.IsEmpty() {
    value = optArgument.Get()
}

This utility was discussed here, and would simplify the above code as:

value := optArgument.GetOr("foo")

Testing

Unit tests

@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2025

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jul 4, 2025
@edmocosta
Copy link
Contributor Author

Hey @evan-bradley, could you please take a look at this when you get a chance? Thanks!

@edmocosta edmocosta removed the Stale label Jul 4, 2025
Copy link
Contributor

@evan-bradley evan-bradley left a comment

Choose a reason for hiding this comment

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

Sorry it took me so long to get to this. This looks good to me, but I think we should add an API changelog entry.

@edmocosta edmocosta changed the title [chore][pkg/ottl] Add GetOr function to ottl.Optional [pkg/ottl] Add GetOr function to ottl.Optional Jul 7, 2025
@edmocosta edmocosta requested a review from evan-bradley July 7, 2025 08:53
@evan-bradley evan-bradley merged commit 8cfe2aa into open-telemetry:main Jul 7, 2025
177 of 178 checks passed
@github-actions github-actions bot added this to the next release milestone Jul 7, 2025
Dylan-M pushed a commit to Dylan-M/opentelemetry-collector-contrib that referenced this pull request Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants