Skip to content
Merged
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
5 changes: 3 additions & 2 deletions otlpclient/protobuf_span.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ func StringMapAttrsToProtobuf(attributes map[string]string) []*commonpb.KeyValue
for k, v := range attributes {
av := new(commonpb.AnyValue)

// try to parse as numbers, and fall through to string
if i, err := strconv.ParseInt(v, 0, 64); err == nil {
// try to parse as decimal numbers, and fall through to string
// base 10 only: base 0 would auto-detect hex/octal prefixes (#373)
if i, err := strconv.ParseInt(v, 10, 64); err == nil {
av.Value = &commonpb.AnyValue_IntValue{IntValue: i}
} else if f, err := strconv.ParseFloat(v, 64); err == nil {
av.Value = &commonpb.AnyValue_DoubleValue{DoubleValue: f}
Expand Down
18 changes: 18 additions & 0 deletions otlpclient/protobuf_span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ func TestCliAttrsToOtel(t *testing.T) {
"test 5 - bool, false": "false",
"test 6 - bool, True": "True",
"test 7 - bool, False": "False",
"test 8 - hex string": "0x0",
"test 9 - hex string2": "0xFF",
"test 10 - octal str": "0o777",
Comment on lines +195 to +197
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

The PR description mentions binary-prefixed strings (e.g., 0b1010) were also being parsed via base-0 autodetection, but the new tests only cover hex and octal. Add a test case asserting a 0b... value remains a string to fully cover the stated behavior.

Copilot uses AI. Check for mistakes.
Comment on lines +196 to +197
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

Test case names like "hex string2" and "octal str" are a bit unclear/inconsistent. Consider renaming to something more descriptive and consistent (e.g., "hex string - uppercase" / "octal-prefixed string"), since these names show up in failures and help quickly identify intent.

Copilot uses AI. Check for mistakes.
}

otelAttrs := StringMapAttrsToProtobuf(testAttrs)
Expand Down Expand Up @@ -228,6 +231,21 @@ func TestCliAttrsToOtel(t *testing.T) {
if attr.Value.GetBoolValue() != false {
t.Errorf("expected value '%s' for key '%s' but got %t", testAttrs[key], key, attr.Value.GetBoolValue())
}
case "test 8 - hex string":
// #373: 0x0 should be treated as a string, not parsed as hex int
if attr.Value.GetStringValue() != "0x0" {
t.Errorf("expected string value '0x0' for key '%s' but got parsed as different type", key)
}
case "test 9 - hex string2":
// #373: 0xFF should be treated as a string, not parsed as hex int
if attr.Value.GetStringValue() != "0xFF" {
t.Errorf("expected string value '0xFF' for key '%s' but got parsed as different type", key)
}
case "test 10 - octal str":
// 0o777 should be treated as a string, not parsed as octal int
if attr.Value.GetStringValue() != "0o777" {
t.Errorf("expected string value '0o777' for key '%s' but got parsed as different type", key)
}
}
}
}