File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
pkg/ottl/contexts/internal/ctxprofile Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package ctxprofile // import "github.com/open-telemetry/opentelemetry-collector-
6
6
import (
7
7
"context"
8
8
"encoding/hex"
9
+ "errors"
9
10
"time"
10
11
11
12
"go.opentelemetry.io/collector/pdata/pcommon"
@@ -333,8 +334,11 @@ func accessProfileID[K ProfileContext]() ottl.StandardGetSetter[K] {
333
334
return tCtx .GetProfile ().ProfileID (), nil
334
335
},
335
336
Setter : func (_ context.Context , tCtx K , val any ) error {
336
- if i , ok := val .(pprofile.ProfileID ); ok {
337
- tCtx .GetProfile ().SetProfileID (i )
337
+ if id , ok := val .(pprofile.ProfileID ); ok {
338
+ if id .IsEmpty () {
339
+ return errors .New ("profile ids must not be empty" )
340
+ }
341
+ tCtx .GetProfile ().SetProfileID (id )
338
342
}
339
343
return nil
340
344
},
@@ -353,6 +357,9 @@ func accessStringProfileID[K ProfileContext]() ottl.StandardGetSetter[K] {
353
357
if err != nil {
354
358
return err
355
359
}
360
+ if id .IsEmpty () {
361
+ return errors .New ("profile ids must not be empty" )
362
+ }
356
363
tCtx .GetProfile ().SetProfileID (id )
357
364
}
358
365
return nil
Original file line number Diff line number Diff line change 4
4
package ctxprofile // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxprofile"
5
5
import (
6
6
"context"
7
+ "encoding/hex"
7
8
"strings"
8
9
"testing"
9
10
"time"
@@ -104,10 +105,23 @@ func TestPathGetSetter(t *testing.T) {
104
105
path : "profile_id" ,
105
106
val : createProfileID (),
106
107
},
108
+ {
109
+ path : "profile_id" ,
110
+ val : pprofile .NewProfileIDEmpty (),
111
+ setFails : true ,
112
+ },
107
113
{
108
114
path : "profile_id string" ,
109
115
val : createProfileID ().String (),
110
116
},
117
+ {
118
+ path : "profile_id string" ,
119
+ val : func () string {
120
+ id := pprofile .NewProfileIDEmpty ()
121
+ return hex .EncodeToString (id [:])
122
+ }(),
123
+ setFails : true ,
124
+ },
111
125
{
112
126
path : "attribute_indices" ,
113
127
val : []int64 {567 },
You can’t perform that action at this time.
0 commit comments