Skip to content
Merged
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
11 changes: 9 additions & 2 deletions pkg/ottl/contexts/internal/ctxprofile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package ctxprofile // import "github.com/open-telemetry/opentelemetry-collector-
import (
"context"
"encoding/hex"
"errors"
"time"

"go.opentelemetry.io/collector/pdata/pcommon"
Expand Down Expand Up @@ -333,8 +334,11 @@ func accessProfileID[K ProfileContext]() ottl.StandardGetSetter[K] {
return tCtx.GetProfile().ProfileID(), nil
},
Setter: func(_ context.Context, tCtx K, val any) error {
if i, ok := val.(pprofile.ProfileID); ok {
tCtx.GetProfile().SetProfileID(i)
if id, ok := val.(pprofile.ProfileID); ok {
if id.IsEmpty() {
return errors.New("profile ids must not be empty")
}
tCtx.GetProfile().SetProfileID(id)
}
return nil
},
Expand All @@ -353,6 +357,9 @@ func accessStringProfileID[K ProfileContext]() ottl.StandardGetSetter[K] {
if err != nil {
return err
}
if id.IsEmpty() {
return errors.New("profile ids must not be empty")
}
tCtx.GetProfile().SetProfileID(id)
}
return nil
Expand Down
14 changes: 14 additions & 0 deletions pkg/ottl/contexts/internal/ctxprofile/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package ctxprofile // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxprofile"
import (
"context"
"encoding/hex"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -104,10 +105,23 @@ func TestPathGetSetter(t *testing.T) {
path: "profile_id",
val: createProfileID(),
},
{
path: "profile_id",
val: pprofile.NewProfileIDEmpty(),
setFails: true,
},
{
path: "profile_id string",
val: createProfileID().String(),
},
{
path: "profile_id string",
val: func() string {
id := pprofile.NewProfileIDEmpty()
return hex.EncodeToString(id[:])
}(),
setFails: true,
},
{
path: "attribute_indices",
val: []int64{567},
Expand Down
Loading