diff --git a/pkg/ottl/contexts/internal/ctxprofile/profile.go b/pkg/ottl/contexts/internal/ctxprofile/profile.go index b4734d02b1026..eeaffede93bea 100644 --- a/pkg/ottl/contexts/internal/ctxprofile/profile.go +++ b/pkg/ottl/contexts/internal/ctxprofile/profile.go @@ -357,11 +357,11 @@ func getAttributeValue[K Context](tCtx K, key string) pcommon.Value { // Find the index of the attribute in the profile's attribute indices // and return the corresponding value from the attribute table. table := tCtx.GetProfilesDictionary().AttributeTable() - indices := tCtx.GetProfile().AttributeIndices().AsRaw() - for _, tableIndex := range indices { + for _, tableIndex := range tCtx.GetProfile().AttributeIndices().All() { attr := table.At(int(tableIndex)) if attr.Key() == key { + // Copy the value because OTTL expects to do inplace updates for the values. v := pcommon.NewValueEmpty() attr.Value().CopyTo(v) return v diff --git a/pkg/ottl/contexts/internal/ctxprofilesample/profilesample.go b/pkg/ottl/contexts/internal/ctxprofilesample/profilesample.go index b471504380c68..4f3cf7437da44 100644 --- a/pkg/ottl/contexts/internal/ctxprofilesample/profilesample.go +++ b/pkg/ottl/contexts/internal/ctxprofilesample/profilesample.go @@ -203,11 +203,11 @@ func getAttributeValue[K Context](tCtx K, key string) pcommon.Value { // Find the index of the attribute in the profile's attribute indices // and return the corresponding value from the attribute table. table := tCtx.GetProfilesDictionary().AttributeTable() - indices := tCtx.GetProfileSample().AttributeIndices().AsRaw() - for _, tableIndex := range indices { + for _, tableIndex := range tCtx.GetProfileSample().AttributeIndices().All() { attr := table.At(int(tableIndex)) if attr.Key() == key { + // Copy the value because OTTL expects to do inplace updates for the values. v := pcommon.NewValueEmpty() attr.Value().CopyTo(v) return v diff --git a/pkg/ottl/contexts/internal/logprofile/logging.go b/pkg/ottl/contexts/internal/logprofile/logging.go index 2b910c773e4f2..aac71645951c3 100644 --- a/pkg/ottl/contexts/internal/logprofile/logging.go +++ b/pkg/ottl/contexts/internal/logprofile/logging.go @@ -21,13 +21,11 @@ func getMapping(dict pprofile.ProfilesDictionary, idx int32) (mapping, error) { return newMapping(dict, mTable.At(int(idx))) } -func getLocations(dict pprofile.ProfilesDictionary, locIdxs []int32, - start, length int32, -) (locations, error) { - if start >= int32(len(locIdxs)) { +func getLocations(dict pprofile.ProfilesDictionary, locIdxs pcommon.Int32Slice, start, length int32) (locations, error) { + if start >= int32(locIdxs.Len()) { return locations{}, fmt.Errorf("location start index out of bounds: %d", start) } - if start+length > int32(len(locIdxs)) { + if start+length > int32(locIdxs.Len()) { return locations{}, fmt.Errorf("location end index out of bounds: %d", start+length) } @@ -35,7 +33,7 @@ func getLocations(dict pprofile.ProfilesDictionary, locIdxs []int32, var joinedErr error ls := make(locations, 0, length) for i := range length { - locIdx := locIdxs[start+i] + locIdx := locIdxs.At(int(start + i)) l, err := newLocation(dict, locTable.At(int(locIdx))) joinedErr = errors.Join(joinedErr, err) ls = append(ls, l) @@ -138,7 +136,7 @@ type ProfileSample struct { func (s ProfileSample) MarshalLogObject(encoder zapcore.ObjectEncoder) error { var joinedErr error - locs, err := getLocations(s.Dictionary, s.Profile.LocationIndices().AsRaw(), s.LocationsStartIndex(), s.LocationsLength()) + locs, err := getLocations(s.Dictionary, s.Profile.LocationIndices(), s.LocationsStartIndex(), s.LocationsLength()) joinedErr = errors.Join(joinedErr, err) joinedErr = errors.Join(joinedErr, encoder.AddArray("locations", locs))