Skip to content

Commit 4921b34

Browse files
committed
[pkg/testdata] Fix type of Attribute.Value
1 parent f8e9fde commit 4921b34

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: pkg/pdatatest
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Change type of attribute values from string to any.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: []
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [api]

pkg/pdatatest/pprofiletest/types.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
package pprofiletest // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pprofiletest"
55
import (
6+
"fmt"
7+
68
"go.opentelemetry.io/collector/pdata/pcommon"
79
"go.opentelemetry.io/collector/pdata/pprofile"
810
)
@@ -30,7 +32,10 @@ func (rp ResourceProfile) Transform(pp pprofile.Profiles) pprofile.ResourceProfi
3032
sp.Transform(prp)
3133
}
3234
for _, a := range rp.Resource.Attributes {
33-
prp.Resource().Attributes().PutStr(a.Key, a.Value)
35+
if prp.Resource().Attributes().PutEmpty(a.Key).FromRaw(a.Value) != nil {
36+
panic(fmt.Sprintf("unsupported resource attribute value: {%s: %v (type %T)}",
37+
a.Key, a.Value, a.Value))
38+
}
3439
}
3540
return prp
3641
}
@@ -66,7 +71,10 @@ type Scope struct {
6671
func (sc Scope) Transform(psp pprofile.ScopeProfiles) pcommon.InstrumentationScope {
6772
psc := psp.Scope()
6873
for _, a := range sc.Attributes {
69-
psc.Attributes().PutStr(a.Key, a.Value)
74+
if psc.Attributes().PutEmpty(a.Key).FromRaw(a.Value) != nil {
75+
panic(fmt.Sprintf("unsupported scope attribute value: {%s: %v (type %T)}",
76+
a.Key, a.Value, a.Value))
77+
}
7078
}
7179
psc.SetName(sc.Name)
7280
psc.SetVersion(sc.Version)
@@ -274,13 +282,16 @@ func (m *Mapping) Transform(pp pprofile.Profile) {
274282

275283
type Attribute struct {
276284
Key string
277-
Value string
285+
Value any
278286
}
279287

280288
func (a *Attribute) Transform(pp pprofile.Profile) int32 {
281289
pa := pp.AttributeTable().AppendEmpty()
282290
pa.SetKey(a.Key)
283-
pa.Value().SetStr(a.Value)
291+
if pa.Value().FromRaw(a.Value) != nil {
292+
panic(fmt.Sprintf("unsupported attribute value: {%s: %v (type %T)}",
293+
a.Key, a.Value, a.Value))
294+
}
284295
return int32(pp.AttributeTable().Len() - 1)
285296
}
286297

0 commit comments

Comments
 (0)