Skip to content

Commit

Permalink
fix nil value conversion (open-telemetry#34673)
Browse files Browse the repository at this point in the history
**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->

fix nil value conversion

**Link to tracking Issue:** <Issue number if applicable>

Fixes open-telemetry#34672 

**Testing:** <Describe what testing was performed and which tests were
added.>

added.

**Documentation:** <Describe the documentation added.>

n/a
  • Loading branch information
newly12 authored and f7o committed Sep 12, 2024
1 parent c93320e commit 3ca4caf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .chloggen/pkg-stanza-nil-handling.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg/stanza

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: fix nil value conversion

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [34672]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
1 change: 1 addition & 0 deletions pkg/stanza/adapter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ func upsertToAttributeVal(value any, dest pcommon.Value) {
upsertToMap(t, dest.SetEmptyMap())
case []any:
upsertToSlice(t, dest.SetEmptySlice())
case nil:
default:
dest.SetStr(fmt.Sprintf("%v", t))
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/stanza/adapter/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ func TestConvertMetadata(t *testing.T) {
"int": 123,
"double": 12.34,
"string": "hello",
"empty": nil,
},
}
e.Body = true
Expand Down Expand Up @@ -595,7 +596,7 @@ func TestConvertMetadata(t *testing.T) {
require.True(t, ok)

mapVal := attVal.Map()
require.Equal(t, 4, mapVal.Len())
require.Equal(t, 5, mapVal.Len())

attVal, ok = mapVal.Get("bool")
require.True(t, ok)
Expand All @@ -613,6 +614,10 @@ func TestConvertMetadata(t *testing.T) {
require.True(t, ok)
require.Equal(t, "hello", attVal.Str())

attVal, ok = mapVal.Get("empty")
require.True(t, ok)
require.Equal(t, pcommon.ValueTypeEmpty, attVal.Type())

bod := result.Body()
require.Equal(t, pcommon.ValueTypeBool, bod.Type())
require.True(t, bod.Bool())
Expand Down

0 comments on commit 3ca4caf

Please sign in to comment.