Skip to content

[pkg/ottl] Accept string (32 byte hex) {span,trace,profile} IDs#43882

Merged
songy23 merged 42 commits into
open-telemetry:mainfrom
andrewvc:accept-str-traceids
Dec 15, 2025
Merged

[pkg/ottl] Accept string (32 byte hex) {span,trace,profile} IDs#43882
songy23 merged 42 commits into
open-telemetry:mainfrom
andrewvc:accept-str-traceids

Conversation

@andrewvc
Copy link
Copy Markdown
Contributor

@andrewvc andrewvc commented Oct 29, 2025

Description

Currently {TraceID,SpanID,ProfileID} only support byte IDs, however in #43429 it was brought up that it is difficult to take a string representation of an ID and directly use that to set a trace ID. This would be for a hexadecimal string representation comprising 32 bytes. This change allows the {TraceID,SpanID,ProfileID} functions to also work on string inputs.

In short, the following now works:

statements:
  - set(span.trace_id, TraceID("a389023abaa839283293ed323892389d"))

Link to tracking issue

Fixes #43429

Testing

In addition to the included go tests the following config

test-str-trace.yml

was used to manually test by invoking make otelcontribcol && ./bin/otelcontribcol_darwin_arm64 --config test-str-trace.yml in one window and telemetrygen traces --otlp-insecure --traces 1 in another. The output is as shown:

CLI Output
Span #0
    Trace ID       : a389023abaa839283293ed323892389d
    Parent ID      : e5c516b0c8942eab
    ID             : 1914136d5f9ca838
    Name           : okey-dokey-0
    Kind           : Server
    Start time     : 2025-10-29 18:59:03.312829 +0000 UTC
    End time       : 2025-10-29 18:59:03.312952 +0000 UTC
    Status code    : Unset
    Status message :
Attributes:
     -> network.peer.address: Str(1.2.3.4)
     -> peer.service: Str(telemetrygen-client)
Span #1
    Trace ID       : a389023abaa839283293ed323892389d
    Parent ID      :
    ID             : e5c516b0c8942eab
    Name           : lets-go
    Kind           : Client
    Start time     : 2025-10-29 18:59:03.312829 +0000 UTC
    End time       : 2025-10-29 18:59:03.312952 +0000 UTC
    Status code    : Unset
    Status message :
Attributes:
     -> network.peer.address: Str(1.2.3.4)
     -> peer.service: Str(telemetrygen-server)

Documentation

I don't currently see documentation for these functions, but I'm new here, maybe I'm missing something? Glad to update it

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Oct 29, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: andrewvc / name: Andrew Cholakian (9ba8c4e)

@github-actions github-actions Bot added the first-time contributor PRs made by new contributors label Oct 29, 2025
@github-actions
Copy link
Copy Markdown
Contributor

Welcome, contributor! Thank you for your contribution to opentelemetry-collector-contrib.

Important reminders:

A maintainer will review your pull request soon. Thank you for helping make OpenTelemetry better!

Comment thread pkg/ottl/ottlfuncs/func_trace_id.go Outdated
Comment thread pkg/ottl/ottlfuncs/func_trace_id.go Outdated
Comment thread pkg/ottl/ottlfuncs/func_trace_id.go
@andrewvc
Copy link
Copy Markdown
Contributor Author

andrewvc commented Nov 2, 2025

I've added a fix for the linter issues, but it looks like perhaps an approval is required to run CI again?

@github-actions
Copy link
Copy Markdown
Contributor

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 Nov 18, 2025
@edmocosta edmocosta removed the Stale label Nov 19, 2025
@atoulme
Copy link
Copy Markdown
Contributor

atoulme commented Nov 20, 2025

please take a look at the conflict and mark ready to review again.

@atoulme atoulme marked this pull request as draft November 20, 2025 04:50
Copy link
Copy Markdown
Contributor

@edmocosta edmocosta left a comment

Choose a reason for hiding this comment

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

Thank you @andrewvc and I'm sorry for the long delay to review.
To keep it consistent, we also need to change the SpanID and ProfileID functions. If you agree, I'd be fine reviewing/including them on this same PR (changes are small enough), otherwise we can open separate PRs for that. Thanks!

Comment thread pkg/ottl/ottlfuncs/func_trace_id.go
Comment thread pkg/ottl/ottlfuncs/func_trace_id_test.go
Comment thread pkg/ottl/ottlfuncs/func_trace_id_test.go
Comment thread pkg/ottl/ottlfuncs/func_profile_id.go
@andrewvc
Copy link
Copy Markdown
Contributor Author

andrewvc commented Dec 5, 2025

Comment thread pkg/ottl/ottlfuncs/id_helpers.go Outdated
Comment thread pkg/ottl/ottlfuncs/func_profile_id.go
Comment thread pkg/ottl/ottlfuncs/id_helpers.go
Comment thread pkg/ottl/ottlfuncs/id_test_helpers.go Outdated
b.Run("literal_bytes_get_and_set", func(b *testing.B) {
literalBytes := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
literalGetter := makeLiteralIDGetter(literalBytes)
literalGetter, _ := ottl.NewTestingLiteralGetter(true, makeIDGetter(literalBytes))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a benchmark, no need to handle the possible error here IMHO

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Adding require.NoError(b, err) would do the work and make any possible failure clearer than panicking while executing the function. It's ok for this specific one, but considering how easy it's for handling that, I wouldn't ignore it :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's not a huge deal for me, so I've added it. I don't love adding unneeded code in benchmarks, but in this case it makes no difference

Comment thread pkg/ottl/ottlfuncs/func_trace_id_test.go Outdated
Copy link
Copy Markdown
Contributor

@edmocosta edmocosta left a comment

Choose a reason for hiding this comment

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

Great work @andrewvc! thank you!
I've left a few final nits, otherwise LGTM!

b.Run("literal_bytes_get_and_set", func(b *testing.B) {
literalBytes := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
literalGetter := makeLiteralIDGetter(literalBytes)
literalGetter, _ := ottl.NewTestingLiteralGetter(true, makeIDGetter(literalBytes))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Adding require.NoError(b, err) would do the work and make any possible failure clearer than panicking while executing the function. It's ok for this specific one, but considering how easy it's for handling that, I wouldn't ignore it :)

Comment thread pkg/ottl/ottlfuncs/func_trace_id_test.go Outdated
Comment thread pkg/ottl/ottlfuncs/func_trace_id_test.go
@edmocosta edmocosta added ready to merge Code review completed; ready to merge by maintainers and removed waiting-for-code-owners labels Dec 15, 2025
@songy23 songy23 merged commit 63e042d into open-telemetry:main Dec 15, 2025
219 of 222 checks passed
@otelbot
Copy link
Copy Markdown
Contributor

otelbot Bot commented Dec 15, 2025

Thank you for your contribution @andrewvc! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey. If you are getting started contributing, you can also join the CNCF Slack channel #opentelemetry-new-contributors to ask for guidance and get help.

@github-actions github-actions Bot added this to the next release milestone Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

first-time contributor PRs made by new contributors pkg/ottl ready to merge Code review completed; ready to merge by maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TraceID method needs to work with hex or string inputs

5 participants