Skip to content
Open
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
25 changes: 25 additions & 0 deletions .chloggen/20260723_fix-sample-formatting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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. receiver/otlp)
component: exporter/debug

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix profile sample attribute formatting for non-string values

# One or more tracking issues or pull requests related to the change
issues: [15647]

# (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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: Maybe elaborate briefly on the before and after?


# 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: [user]
2 changes: 1 addition & 1 deletion exporter/debugexporter/internal/otlptext/databuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func (b *dataBuffer) logProfileSamples(ss pprofile.SampleSlice, dic pprofile.Pro
if keyIdx < dic.StringTable().Len() {
key = dic.StringTable().At(keyIdx)
}
b.logEntry(" -> %s: %s", key, attr.Value().AsRaw())
b.logEntry(" -> %s: %v", key, attr.Value().AsRaw())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is certainly better, but I think it would be even better to align with how pcommon.Values are serialized in other locations (like resource attributes) and not rely on Go's %v formatting. This would mean using the valueToString function, which looks like Str(my string) or Int(42). This would be a breaking change on the output format for strings, but we do warn in the README that "The output formats for all verbosity levels is not guaranteed and may be changed at any time without a breaking change".

}
}
}
Expand Down
50 changes: 50 additions & 0 deletions exporter/debugexporter/internal/otlptext/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pprofile"
"go.opentelemetry.io/collector/pdata/testdata"
)
Expand Down Expand Up @@ -50,6 +51,55 @@ func TestProfilesText(t *testing.T) {
}
}

func TestProfilesTextSampleAttributeValues(t *testing.T) {
tests := []struct {
name string
setValue func(pcommon.Value)
expected string
}{
{name: "empty", setValue: func(_ pcommon.Value) {}, expected: "<nil>"},
{name: "string", setValue: func(v pcommon.Value) { v.SetStr("value") }, expected: "value"},
{name: "integer", setValue: func(v pcommon.Value) { v.SetInt(42) }, expected: "42"},
{name: "double", setValue: func(v pcommon.Value) { v.SetDouble(3.14) }, expected: "3.14"},
{name: "boolean", setValue: func(v pcommon.Value) { v.SetBool(true) }, expected: "true"},
{
name: "bytes",
setValue: func(v pcommon.Value) { v.SetEmptyBytes().FromRaw([]byte{1, 2, 3}) },
expected: "[1 2 3]",
},
{
name: "map",
setValue: func(v pcommon.Value) { _ = v.SetEmptyMap().FromRaw(map[string]any{"nested": "value"}) },
expected: "map[nested:value]",
},
{
name: "slice",
setValue: func(v pcommon.Value) { _ = v.SetEmptySlice().FromRaw([]any{"value", true}) },
expected: "[value true]",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
profiles := pprofile.NewProfiles()
dic := profiles.Dictionary()
dic.StringTable().Append("")
dic.StringTable().Append("key")
attribute := dic.AttributeTable().AppendEmpty()
attribute.SetKeyStrindex(1)
tt.setValue(attribute.Value())

sample := profiles.ResourceProfiles().AppendEmpty().ScopeProfiles().AppendEmpty().Profiles().AppendEmpty().Samples().AppendEmpty()
sample.Values().Append(100)
sample.AttributeIndices().Append(0)

output, err := NewTextProfilesMarshaler().MarshalProfiles(profiles)
require.NoError(t, err)
assert.Contains(t, string(output), "-> key: "+tt.expected)
})
}
}

func TestProfilesTextInvalidDictionaryIndex(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading