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

feat(ottl): enable managing trace flags in span context #36768

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pkg/ottl/contexts/internal/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
},
}
}
12 changes: 12 additions & 0 deletions pkg/ottl/contexts/internal/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -674,6 +685,7 @@ func createSpan() ptrace.Span {

span.Status().SetCode(ptrace.StatusCodeOk)
span.Status().SetMessage("good span")
span.SetFlags(0x01)

return span
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/ottl/contexts/ottlspan/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ The following paths are supported.
| kind.deprecated_string | the kind of the span in deprecated string format. Valid values are `SPAN_KIND_UNSPECIFIED`, `SPAN_KIND_INTERNAL`, `SPAN_KIND_SERVER`, `SPAN_KIND_CLIENT`, `SPAN_KIND_PRODUCER`, and `SPAN_KIND_CONSUMER`. When setting, if an invalid value is used `SPAN_KIND_UNSPECIFIED` will be set. This accessor will eventually be removed, use `kind` or `kind.string` instead. | string |
| start_time_unix_nano | the start time in unix nano of the span | int64 |
| end_time_unix_nano | the end time in unix nano of the span | int64 |
| start_time | the start time in `time.Time` of the span | `time.Time` |
| end_time | the end time in `time.Time` of the span | `time.Time` |
| start_time | the start time in `time.Time` of the span | `time.Time` |
| end_time | the end time in `time.Time` of the span | `time.Time` |
| dropped_attributes_count | the dropped attributes count of the span | int64 |
| events | the events of the span | ptrace.SpanEventSlice |
| 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 | the trace flags of the span | int64 |

## Enums

Expand All @@ -61,8 +61,8 @@ The Span Context supports the enum names from the [traces proto](https://github.
| SPAN_KIND_INTERNAL | 1 |
| SPAN_KIND_SERVER | 2 |
| SPAN_KIND_CLIENT | 3 |
| SPAN_KIND_PRODUCER | 4 |
| SPAN_KIND_CONSUMER | 5 |
| STATUS_CODE_UNSET | 0 |
| STATUS_CODE_OK | 1 |
| STATUS_CODE_ERROR | 2 |
| SPAN_KIND_PRODUCER | 4 |
| SPAN_KIND_CONSUMER | 5 |
| STATUS_CODE_UNSET | 0 |
| STATUS_CODE_OK | 1 |
| STATUS_CODE_ERROR | 2 |
Loading