Skip to content
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

[pdata] Implement Go 1.23 style iterators #11982

Open
yurishkuro opened this issue Dec 25, 2024 · 1 comment
Open

[pdata] Implement Go 1.23 style iterators #11982

yurishkuro opened this issue Dec 25, 2024 · 1 comment

Comments

@yurishkuro
Copy link
Member

yurishkuro commented Dec 25, 2024

Is your feature request related to a problem? Please describe.

Iterating through pdata structures today is pretty convoluted, e.g.

for i := 0; i < traces.ResourceSpans().Len(); i++ {
	resource := traces.ResourceSpans().At(i)
	for j := 0; j < resource.ScopeSpans().Len(); j++ {
		scope := resource.ScopeSpans().At(j)
		for k := 0; k < scope.Spans().Len(); k++ {
			span := scope.Spans().At(k)

Describe the solution you'd like
Go 1.23 introduced the ability to use iterators for looping through custom structs. The above code could look like this, if we introduce iterator functions to pdata, e.g. Seq() and Seq2():

for resource := range traces.ResourceSpans().Seq() {
	for scope := range resource.ScopeSpans().Seq() {
		for span := range scope.Spans().Seq() {
for i, resource := range traces.ResourceSpans().Seq2() {
	for j, scope := range resource.ScopeSpans().Seq2() {
		for k, span := range scope.Spans().Seq2() {
@bogdandrutu
Copy link
Member

@yurishkuro good call, will do when we move to minimum supported version to be 1.23

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

No branches or pull requests

2 participants