Skip to content

Commit 04eb2a4

Browse files
rockdabootDylan-M
authored andcommitted
[chore][pkg/pdatatest] Fix Attribute.Transform() by using pprofile.PutAttribute() (open-telemetry#41205)
#### Description After the recent changes in pprofile, `Attribute.Transform()` needs to make use of `pprofile.PutAttribute()` instead of directly manipulating data structures. This change is split out of open-telemetry#39974.
1 parent 32e01aa commit 04eb2a4

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

pkg/pdatatest/pprofiletest/types.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (p *Profile) Transform(dic pprofile.ProfilesDictionary, psp pprofile.ScopeP
132132
pp.SetOriginalPayloadFormat(p.OriginalPayloadFormat)
133133
pp.OriginalPayload().FromRaw(p.OriginalPayload)
134134
for _, at := range p.Attributes {
135-
pp.AttributeIndices().Append(at.Transform(dic))
135+
at.Transform(dic, pp)
136136
}
137137
for _, au := range p.AttributeUnits {
138138
au.Transform(dic)
@@ -218,13 +218,13 @@ func (sa *Sample) Transform(dic pprofile.ProfilesDictionary, pp pprofile.Profile
218218
pl.SetFunctionIndex(l.Function.Transform(dic))
219219
}
220220
for _, at := range loc.Attributes {
221-
ploc.AttributeIndices().Append(at.Transform(dic))
221+
at.Transform(dic, ploc)
222222
}
223223
}
224224
psa.SetLocationsLength(int32(pp.LocationIndices().Len()) - psa.LocationsStartIndex())
225225
psa.Value().FromRaw(sa.Value)
226226
for _, at := range sa.Attributes {
227-
psa.AttributeIndices().Append(at.Transform(dic))
227+
at.Transform(dic, psa)
228228
}
229229
//nolint:revive,staticcheck
230230
if sa.Link != nil {
@@ -272,7 +272,7 @@ func (m *Mapping) Transform(dic pprofile.ProfilesDictionary) {
272272
pm.SetFileOffset(m.FileOffset)
273273
pm.SetFilenameStrindex(addString(dic, m.Filename))
274274
for _, at := range m.Attributes {
275-
pm.AttributeIndices().Append(at.Transform(dic))
275+
at.Transform(dic, pm)
276276
}
277277
pm.SetHasFunctions(m.HasFunctions)
278278
pm.SetHasFilenames(m.HasFileNames)
@@ -285,14 +285,20 @@ type Attribute struct {
285285
Value any
286286
}
287287

288-
func (a *Attribute) Transform(dic pprofile.ProfilesDictionary) int32 {
289-
pa := dic.AttributeTable().AppendEmpty()
290-
pa.SetKey(a.Key)
291-
if pa.Value().FromRaw(a.Value) != nil {
288+
type attributable interface {
289+
AttributeIndices() pcommon.Int32Slice
290+
}
291+
292+
func (a *Attribute) Transform(dic pprofile.ProfilesDictionary, record attributable) {
293+
v := pcommon.NewValueEmpty()
294+
if err := v.FromRaw(a.Value); err != nil {
292295
panic(fmt.Sprintf("unsupported attribute value: {%s: %v (type %T)}",
293296
a.Key, a.Value, a.Value))
294297
}
295-
return int32(dic.AttributeTable().Len() - 1)
298+
if err := pprofile.PutAttribute(dic.AttributeTable(), record, a.Key, v); err != nil {
299+
panic(fmt.Sprintf("failed to put attribute: {%s: %v (type %T)}: %v",
300+
a.Key, a.Value, a.Value, err))
301+
}
296302
}
297303

298304
type AttributeUnit struct {

0 commit comments

Comments
 (0)