diff --git a/pkg/ottl/contexts/internal/span.go b/pkg/ottl/contexts/internal/span.go index 607cb2e110f9..cb8831842656 100644 --- a/pkg/ottl/contexts/internal/span.go +++ b/pkg/ottl/contexts/internal/span.go @@ -127,6 +127,8 @@ func SpanPathGetSetter[K SpanContext](path ottl.Path[K]) (ottl.GetSetter[K], err } } return accessStatus[K](), nil + case "flags": + return accessFlags[K](), nil default: return nil, FormatDefaultErrorMessage(path.Name(), path.String(), SpanContextName, SpanRef) } @@ -585,3 +587,17 @@ func accessStatusMessage[K SpanContext]() ottl.StandardGetSetter[K] { }, } } + +func accessFlags[K SpanContext]() ottl.StandardGetSetter[K] { + return ottl.StandardGetSetter[K]{ + Getter: func(_ context.Context, tCtx K) (any, error) { + return int64(tCtx.GetSpan().Flags()), nil + }, + Setter: func(_ context.Context, tCtx K, val any) error { + if i, ok := val.(uint32); ok { + tCtx.GetSpan().SetFlags(i) + } + return nil + }, + } +} diff --git a/pkg/ottl/contexts/internal/span_test.go b/pkg/ottl/contexts/internal/span_test.go index 899d12493424..443fef1c1867 100644 --- a/pkg/ottl/contexts/internal/span_test.go +++ b/pkg/ottl/contexts/internal/span_test.go @@ -600,6 +600,17 @@ func TestSpanPathGetSetter(t *testing.T) { span.SetEndTimestamp(pcommon.NewTimestampFromTime(time.UnixMilli(200))) }, }, + { + name: "flags", + path: &TestPath[*spanContext]{ + N: "flags", + }, + orig: 0x01, + newVal: 0x00, + modified: func(span ptrace.Span) { + span.SetFlags(0x00) + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -675,6 +686,8 @@ func createSpan() ptrace.Span { span.Status().SetCode(ptrace.StatusCodeOk) span.Status().SetMessage("good span") + span.SetFlags(0x01) + return span } diff --git a/pkg/ottl/contexts/ottlspan/README.md b/pkg/ottl/contexts/ottlspan/README.md index 6caf0a94862c..b998fee99af7 100644 --- a/pkg/ottl/contexts/ottlspan/README.md +++ b/pkg/ottl/contexts/ottlspan/README.md @@ -49,6 +49,7 @@ The following paths are supported. | dropped_events_count | the dropped events count of the span | int64 | | links | the links of the span | ptrace.SpanLinkSlice | | dropped_links_count | the dropped links count of the span | int64 | +| flags | trace flags of the span | int64 | ## Enums