Skip to content

[pdata] Implement Go 1.23 style iterators #11982

Closed
@yurishkuro

Description

@yurishkuro

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() {

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions