diff --git a/pkg/ottl/contexts/internal/ids.go b/pkg/ottl/contexts/internal/ctxutil/ids.go similarity index 87% rename from pkg/ottl/contexts/internal/ids.go rename to pkg/ottl/contexts/internal/ctxutil/ids.go index 2eb12c96ce23..243b8b0bac67 100644 --- a/pkg/ottl/contexts/internal/ids.go +++ b/pkg/ottl/contexts/internal/ctxutil/ids.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" +package ctxutil // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" import ( "encoding/hex" diff --git a/pkg/ottl/contexts/internal/ids_test.go b/pkg/ottl/contexts/internal/ctxutil/ids_test.go similarity index 84% rename from pkg/ottl/contexts/internal/ids_test.go rename to pkg/ottl/contexts/internal/ctxutil/ids_test.go index 42370dbdf90d..ab9a545eb990 100644 --- a/pkg/ottl/contexts/internal/ids_test.go +++ b/pkg/ottl/contexts/internal/ctxutil/ids_test.go @@ -1,12 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal +package ctxutil_test import ( "testing" "github.com/stretchr/testify/assert" + + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" ) func TestParseSpanIDError(t *testing.T) { @@ -28,7 +30,7 @@ func TestParseSpanIDError(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - _, err := ParseSpanID(tt.input) + _, err := ctxutil.ParseSpanID(tt.input) assert.EqualError(t, err, tt.wantErr) }) } @@ -53,7 +55,7 @@ func TestParseTraceIDError(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - _, err := ParseTraceID(tt.input) + _, err := ctxutil.ParseTraceID(tt.input) assert.EqualError(t, err, tt.wantErr) }) } diff --git a/pkg/ottl/contexts/internal/map.go b/pkg/ottl/contexts/internal/ctxutil/map.go similarity index 90% rename from pkg/ottl/contexts/internal/map.go rename to pkg/ottl/contexts/internal/ctxutil/map.go index 9965d6dc5c86..c16628ee165e 100644 --- a/pkg/ottl/contexts/internal/map.go +++ b/pkg/ottl/contexts/internal/ctxutil/map.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" +package ctxutil // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" import ( "context" @@ -58,7 +58,7 @@ func SetMapValue[K any](ctx context.Context, tCtx K, m pcommon.Map, keys []ottl. if !ok { currentValue = m.PutEmpty(*s) } - return setIndexableValue[K](ctx, tCtx, currentValue, val, keys[1:]) + return SetIndexableValue[K](ctx, tCtx, currentValue, val, keys[1:]) } func FetchValueFromExpression[K any, T int64 | string](ctx context.Context, tCtx K, key ottl.Key[K]) (*T, error) { diff --git a/pkg/ottl/contexts/internal/map_test.go b/pkg/ottl/contexts/internal/ctxutil/map_test.go similarity index 90% rename from pkg/ottl/contexts/internal/map_test.go rename to pkg/ottl/contexts/internal/ctxutil/map_test.go index 3789d6fa17de..15cb34d30a04 100644 --- a/pkg/ottl/contexts/internal/map_test.go +++ b/pkg/ottl/contexts/internal/ctxutil/map_test.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal +package ctxutil_test import ( "context" @@ -12,6 +12,7 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/pathtest" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottltest" ) @@ -121,7 +122,7 @@ func Test_GetMapValue_Invalid(t *testing.T) { s := m.PutEmptySlice("slice") s.AppendEmpty() - _, err := GetMapValue[any](context.Background(), nil, m, tt.keys) + _, err := ctxutil.GetMapValue[any](context.Background(), nil, m, tt.keys) assert.Equal(t, tt.err.Error(), err.Error()) }) } @@ -138,13 +139,13 @@ func Test_GetMapValue_MissingKey(t *testing.T) { S: ottltest.Strp("unknown key"), }, } - result, err := GetMapValue[any](context.Background(), nil, m, keys) + result, err := ctxutil.GetMapValue[any](context.Background(), nil, m, keys) assert.NoError(t, err) assert.Nil(t, result) } func Test_GetMapValue_NilKey(t *testing.T) { - _, err := GetMapValue[any](context.Background(), nil, pcommon.NewMap(), nil) + _, err := ctxutil.GetMapValue[any](context.Background(), nil, pcommon.NewMap(), nil) assert.Error(t, err) } @@ -253,7 +254,7 @@ func Test_SetMapValue_Invalid(t *testing.T) { s := m.PutEmptySlice("slice") s.AppendEmpty() - err := SetMapValue[any](context.Background(), nil, m, tt.keys, "value") + err := ctxutil.SetMapValue[any](context.Background(), nil, m, tt.keys, "value") assert.Equal(t, tt.err.Error(), err.Error()) }) } @@ -273,7 +274,7 @@ func Test_SetMapValue_AddingNewSubMap(t *testing.T) { S: ottltest.Strp("foo"), }, } - err := SetMapValue[any](context.Background(), nil, m, keys, "bar") + err := ctxutil.SetMapValue[any](context.Background(), nil, m, keys, "bar") assert.NoError(t, err) expected := pcommon.NewMap() @@ -297,7 +298,7 @@ func Test_SetMapValue_EmptyMap(t *testing.T) { S: ottltest.Strp("foo"), }, } - err := SetMapValue[any](context.Background(), nil, m, keys, "bar") + err := ctxutil.SetMapValue[any](context.Background(), nil, m, keys, "bar") assert.NoError(t, err) expected := pcommon.NewMap() @@ -307,6 +308,6 @@ func Test_SetMapValue_EmptyMap(t *testing.T) { } func Test_SetMapValue_NilKey(t *testing.T) { - err := SetMapValue[any](context.Background(), nil, pcommon.NewMap(), nil, "bar") + err := ctxutil.SetMapValue[any](context.Background(), nil, pcommon.NewMap(), nil, "bar") assert.Error(t, err) } diff --git a/pkg/ottl/contexts/internal/slice.go b/pkg/ottl/contexts/internal/ctxutil/slice.go similarity index 88% rename from pkg/ottl/contexts/internal/slice.go rename to pkg/ottl/contexts/internal/ctxutil/slice.go index 9004d08ae836..9337f9bd46bd 100644 --- a/pkg/ottl/contexts/internal/slice.go +++ b/pkg/ottl/contexts/internal/ctxutil/slice.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" +package ctxutil // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" import ( "context" @@ -61,5 +61,5 @@ func SetSliceValue[K any](ctx context.Context, tCtx K, s pcommon.Slice, keys []o return fmt.Errorf("index %d out of bounds", idx) } - return setIndexableValue[K](ctx, tCtx, s.At(idx), val, keys[1:]) + return SetIndexableValue[K](ctx, tCtx, s.At(idx), val, keys[1:]) } diff --git a/pkg/ottl/contexts/internal/slice_test.go b/pkg/ottl/contexts/internal/ctxutil/slice_test.go similarity index 88% rename from pkg/ottl/contexts/internal/slice_test.go rename to pkg/ottl/contexts/internal/ctxutil/slice_test.go index 828140b53f25..9a02a4dfa874 100644 --- a/pkg/ottl/contexts/internal/slice_test.go +++ b/pkg/ottl/contexts/internal/ctxutil/slice_test.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal +package ctxutil_test import ( "context" @@ -12,6 +12,7 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/pathtest" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottltest" ) @@ -81,14 +82,14 @@ func Test_GetSliceValue_Invalid(t *testing.T) { s := pcommon.NewSlice() s.AppendEmpty().SetStr("val") - _, err := GetSliceValue[any](context.Background(), nil, s, tt.keys) + _, err := ctxutil.GetSliceValue[any](context.Background(), nil, s, tt.keys) assert.Equal(t, tt.err.Error(), err.Error()) }) } } func Test_GetSliceValue_NilKey(t *testing.T) { - _, err := GetSliceValue[any](context.Background(), nil, pcommon.NewSlice(), nil) + _, err := ctxutil.GetSliceValue[any](context.Background(), nil, pcommon.NewSlice(), nil) assert.Error(t, err) } @@ -157,13 +158,13 @@ func Test_SetSliceValue_Invalid(t *testing.T) { s := pcommon.NewSlice() s.AppendEmpty().SetStr("val") - err := SetSliceValue[any](context.Background(), nil, s, tt.keys, "value") + err := ctxutil.SetSliceValue[any](context.Background(), nil, s, tt.keys, "value") assert.Equal(t, tt.err.Error(), err.Error()) }) } } func Test_SetSliceValue_NilKey(t *testing.T) { - err := SetSliceValue[any](context.Background(), nil, pcommon.NewSlice(), nil, "value") + err := ctxutil.SetSliceValue[any](context.Background(), nil, pcommon.NewSlice(), nil, "value") assert.Error(t, err) } diff --git a/pkg/ottl/contexts/internal/value.go b/pkg/ottl/contexts/internal/ctxutil/value.go similarity index 96% rename from pkg/ottl/contexts/internal/value.go rename to pkg/ottl/contexts/internal/ctxutil/value.go index 34136fe89caf..bc1da05c62dc 100644 --- a/pkg/ottl/contexts/internal/value.go +++ b/pkg/ottl/contexts/internal/ctxutil/value.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" +package ctxutil // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" import ( "context" @@ -112,7 +112,7 @@ func getIndexableValue[K any](ctx context.Context, tCtx K, value pcommon.Value, return ottlcommon.GetValue(val), nil } -func setIndexableValue[K any](ctx context.Context, tCtx K, currentValue pcommon.Value, val any, keys []ottl.Key[K]) error { +func SetIndexableValue[K any](ctx context.Context, tCtx K, currentValue pcommon.Value, val any, keys []ottl.Key[K]) error { var newValue pcommon.Value switch val.(type) { case []string, []bool, []int64, []float64, [][]byte, []any: diff --git a/pkg/ottl/contexts/internal/value_test.go b/pkg/ottl/contexts/internal/ctxutil/value_test.go similarity index 69% rename from pkg/ottl/contexts/internal/value_test.go rename to pkg/ottl/contexts/internal/ctxutil/value_test.go index b874d8ebcbdc..46a4e0ee3cf0 100644 --- a/pkg/ottl/contexts/internal/value_test.go +++ b/pkg/ottl/contexts/internal/ctxutil/value_test.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" +package ctxutil_test import ( "context" @@ -11,6 +11,7 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/pathtest" ) @@ -18,6 +19,6 @@ func Test_SetIndexableValue_InvalidValue(t *testing.T) { keys := []ottl.Key[any]{ &pathtest.Key[any]{}, } - err := setIndexableValue[any](context.Background(), nil, pcommon.NewValueStr("str"), nil, keys) + err := ctxutil.SetIndexableValue[any](context.Background(), nil, pcommon.NewValueStr("str"), nil, keys) assert.Error(t, err) } diff --git a/pkg/ottl/contexts/internal/resource.go b/pkg/ottl/contexts/internal/resource.go index 4e9cf9793974..b79d8f4b903a 100644 --- a/pkg/ottl/contexts/internal/resource.go +++ b/pkg/ottl/contexts/internal/resource.go @@ -12,6 +12,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxcache" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxerror" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxresource" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" ) type ResourceContext interface { @@ -57,10 +58,10 @@ func accessResourceAttributes[K ResourceContext]() ottl.StandardGetSetter[K] { func accessResourceAttributesKey[K ResourceContext](keys []ottl.Key[K]) ottl.StandardGetSetter[K] { return ottl.StandardGetSetter[K]{ Getter: func(ctx context.Context, tCtx K) (any, error) { - return GetMapValue[K](ctx, tCtx, tCtx.GetResource().Attributes(), keys) + return ctxutil.GetMapValue[K](ctx, tCtx, tCtx.GetResource().Attributes(), keys) }, Setter: func(ctx context.Context, tCtx K, val any) error { - return SetMapValue[K](ctx, tCtx, tCtx.GetResource().Attributes(), keys, val) + return ctxutil.SetMapValue[K](ctx, tCtx, tCtx.GetResource().Attributes(), keys, val) }, } } diff --git a/pkg/ottl/contexts/internal/scope.go b/pkg/ottl/contexts/internal/scope.go index 0995e67da0ab..e7417c851729 100644 --- a/pkg/ottl/contexts/internal/scope.go +++ b/pkg/ottl/contexts/internal/scope.go @@ -12,6 +12,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxcache" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxerror" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxscope" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" ) type InstrumentationScopeContext interface { @@ -62,10 +63,10 @@ func accessInstrumentationScopeAttributes[K InstrumentationScopeContext]() ottl. func accessInstrumentationScopeAttributesKey[K InstrumentationScopeContext](keys []ottl.Key[K]) ottl.StandardGetSetter[K] { return ottl.StandardGetSetter[K]{ Getter: func(ctx context.Context, tCtx K) (any, error) { - return GetMapValue[K](ctx, tCtx, tCtx.GetInstrumentationScope().Attributes(), keys) + return ctxutil.GetMapValue[K](ctx, tCtx, tCtx.GetInstrumentationScope().Attributes(), keys) }, Setter: func(ctx context.Context, tCtx K, val any) error { - return SetMapValue[K](ctx, tCtx, tCtx.GetInstrumentationScope().Attributes(), keys, val) + return ctxutil.SetMapValue[K](ctx, tCtx, tCtx.GetInstrumentationScope().Attributes(), keys, val) }, } } diff --git a/pkg/ottl/contexts/internal/span.go b/pkg/ottl/contexts/internal/span.go index b25fcf25385a..ad2e1d4144e6 100644 --- a/pkg/ottl/contexts/internal/span.go +++ b/pkg/ottl/contexts/internal/span.go @@ -18,6 +18,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxcache" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxerror" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxspan" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" ) type SpanContext interface { @@ -143,7 +144,7 @@ func accessStringTraceID[K SpanContext]() ottl.StandardGetSetter[K] { }, Setter: func(_ context.Context, tCtx K, val any) error { if str, ok := val.(string); ok { - id, err := ParseTraceID(str) + id, err := ctxutil.ParseTraceID(str) if err != nil { return err } @@ -176,7 +177,7 @@ func accessStringSpanID[K SpanContext]() ottl.StandardGetSetter[K] { }, Setter: func(_ context.Context, tCtx K, val any) error { if str, ok := val.(string); ok { - id, err := ParseSpanID(str) + id, err := ctxutil.ParseSpanID(str) if err != nil { return err } @@ -261,7 +262,7 @@ func accessStringParentSpanID[K SpanContext]() ottl.StandardGetSetter[K] { }, Setter: func(_ context.Context, tCtx K, val any) error { if str, ok := val.(string); ok { - id, err := ParseSpanID(str) + id, err := ctxutil.ParseSpanID(str) if err != nil { return err } @@ -435,10 +436,10 @@ func accessAttributes[K SpanContext]() ottl.StandardGetSetter[K] { func accessAttributesKey[K SpanContext](keys []ottl.Key[K]) ottl.StandardGetSetter[K] { return ottl.StandardGetSetter[K]{ Getter: func(ctx context.Context, tCtx K) (any, error) { - return GetMapValue[K](ctx, tCtx, tCtx.GetSpan().Attributes(), keys) + return ctxutil.GetMapValue[K](ctx, tCtx, tCtx.GetSpan().Attributes(), keys) }, Setter: func(ctx context.Context, tCtx K, val any) error { - return SetMapValue[K](ctx, tCtx, tCtx.GetSpan().Attributes(), keys, val) + return ctxutil.SetMapValue[K](ctx, tCtx, tCtx.GetSpan().Attributes(), keys, val) }, } } diff --git a/pkg/ottl/contexts/ottldatapoint/datapoint.go b/pkg/ottl/contexts/ottldatapoint/datapoint.go index 8cee3e125a25..17817811659b 100644 --- a/pkg/ottl/contexts/ottldatapoint/datapoint.go +++ b/pkg/ottl/contexts/ottldatapoint/datapoint.go @@ -21,6 +21,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxmetric" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxresource" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxscope" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging" ) @@ -327,10 +328,10 @@ func accessCache() ottl.StandardGetSetter[TransformContext] { func accessCacheKey(key []ottl.Key[TransformContext]) ottl.StandardGetSetter[TransformContext] { return ottl.StandardGetSetter[TransformContext]{ Getter: func(ctx context.Context, tCtx TransformContext) (any, error) { - return internal.GetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key) + return ctxutil.GetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key) }, Setter: func(ctx context.Context, tCtx TransformContext, val any) error { - return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key, val) + return ctxutil.SetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key, val) }, } } @@ -379,26 +380,26 @@ func accessAttributesKey(key []ottl.Key[TransformContext]) ottl.StandardGetSette Getter: func(ctx context.Context, tCtx TransformContext) (any, error) { switch tCtx.GetDataPoint().(type) { case pmetric.NumberDataPoint: - return internal.GetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.NumberDataPoint).Attributes(), key) + return ctxutil.GetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.NumberDataPoint).Attributes(), key) case pmetric.HistogramDataPoint: - return internal.GetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.HistogramDataPoint).Attributes(), key) + return ctxutil.GetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.HistogramDataPoint).Attributes(), key) case pmetric.ExponentialHistogramDataPoint: - return internal.GetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.ExponentialHistogramDataPoint).Attributes(), key) + return ctxutil.GetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.ExponentialHistogramDataPoint).Attributes(), key) case pmetric.SummaryDataPoint: - return internal.GetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.SummaryDataPoint).Attributes(), key) + return ctxutil.GetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.SummaryDataPoint).Attributes(), key) } return nil, nil }, Setter: func(ctx context.Context, tCtx TransformContext, val any) error { switch tCtx.GetDataPoint().(type) { case pmetric.NumberDataPoint: - return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.NumberDataPoint).Attributes(), key, val) + return ctxutil.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.NumberDataPoint).Attributes(), key, val) case pmetric.HistogramDataPoint: - return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.HistogramDataPoint).Attributes(), key, val) + return ctxutil.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.HistogramDataPoint).Attributes(), key, val) case pmetric.ExponentialHistogramDataPoint: - return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.ExponentialHistogramDataPoint).Attributes(), key, val) + return ctxutil.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.ExponentialHistogramDataPoint).Attributes(), key, val) case pmetric.SummaryDataPoint: - return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.SummaryDataPoint).Attributes(), key, val) + return ctxutil.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.SummaryDataPoint).Attributes(), key, val) } return nil }, diff --git a/pkg/ottl/contexts/ottllog/log.go b/pkg/ottl/contexts/ottllog/log.go index af043b742cf3..f4cf18dfbe50 100644 --- a/pkg/ottl/contexts/ottllog/log.go +++ b/pkg/ottl/contexts/ottllog/log.go @@ -21,6 +21,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxlog" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxresource" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxscope" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging" common "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/internal/ottlcommon" ) @@ -307,10 +308,10 @@ func accessCache() ottl.StandardGetSetter[TransformContext] { func accessCacheKey(key []ottl.Key[TransformContext]) ottl.StandardGetSetter[TransformContext] { return ottl.StandardGetSetter[TransformContext]{ Getter: func(ctx context.Context, tCtx TransformContext) (any, error) { - return internal.GetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key) + return ctxutil.GetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key) }, Setter: func(ctx context.Context, tCtx TransformContext, val any) error { - return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key, val) + return ctxutil.SetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key, val) }, } } @@ -405,7 +406,7 @@ func accessBody() ottl.StandardGetSetter[TransformContext] { return common.GetValue(tCtx.GetLogRecord().Body()), nil }, Setter: func(_ context.Context, tCtx TransformContext, val any) error { - return internal.SetValue(tCtx.GetLogRecord().Body(), val) + return ctxutil.SetValue(tCtx.GetLogRecord().Body(), val) }, } } @@ -416,9 +417,9 @@ func accessBodyKey(key []ottl.Key[TransformContext]) ottl.StandardGetSetter[Tran body := tCtx.GetLogRecord().Body() switch body.Type() { case pcommon.ValueTypeMap: - return internal.GetMapValue[TransformContext](ctx, tCtx, tCtx.GetLogRecord().Body().Map(), key) + return ctxutil.GetMapValue[TransformContext](ctx, tCtx, tCtx.GetLogRecord().Body().Map(), key) case pcommon.ValueTypeSlice: - return internal.GetSliceValue[TransformContext](ctx, tCtx, tCtx.GetLogRecord().Body().Slice(), key) + return ctxutil.GetSliceValue[TransformContext](ctx, tCtx, tCtx.GetLogRecord().Body().Slice(), key) default: return nil, fmt.Errorf("log bodies of type %s cannot be indexed", body.Type().String()) } @@ -427,9 +428,9 @@ func accessBodyKey(key []ottl.Key[TransformContext]) ottl.StandardGetSetter[Tran body := tCtx.GetLogRecord().Body() switch body.Type() { case pcommon.ValueTypeMap: - return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetLogRecord().Body().Map(), key, val) + return ctxutil.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetLogRecord().Body().Map(), key, val) case pcommon.ValueTypeSlice: - return internal.SetSliceValue[TransformContext](ctx, tCtx, tCtx.GetLogRecord().Body().Slice(), key, val) + return ctxutil.SetSliceValue[TransformContext](ctx, tCtx, tCtx.GetLogRecord().Body().Slice(), key, val) default: return fmt.Errorf("log bodies of type %s cannot be indexed", body.Type().String()) } @@ -468,10 +469,10 @@ func accessAttributes() ottl.StandardGetSetter[TransformContext] { func accessAttributesKey(key []ottl.Key[TransformContext]) ottl.StandardGetSetter[TransformContext] { return ottl.StandardGetSetter[TransformContext]{ Getter: func(ctx context.Context, tCtx TransformContext) (any, error) { - return internal.GetMapValue[TransformContext](ctx, tCtx, tCtx.GetLogRecord().Attributes(), key) + return ctxutil.GetMapValue[TransformContext](ctx, tCtx, tCtx.GetLogRecord().Attributes(), key) }, Setter: func(ctx context.Context, tCtx TransformContext, val any) error { - return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetLogRecord().Attributes(), key, val) + return ctxutil.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetLogRecord().Attributes(), key, val) }, } } @@ -526,7 +527,7 @@ func accessStringTraceID() ottl.StandardGetSetter[TransformContext] { }, Setter: func(_ context.Context, tCtx TransformContext, val any) error { if str, ok := val.(string); ok { - id, err := internal.ParseTraceID(str) + id, err := ctxutil.ParseTraceID(str) if err != nil { return err } @@ -559,7 +560,7 @@ func accessStringSpanID() ottl.StandardGetSetter[TransformContext] { }, Setter: func(_ context.Context, tCtx TransformContext, val any) error { if str, ok := val.(string); ok { - id, err := internal.ParseSpanID(str) + id, err := ctxutil.ParseSpanID(str) if err != nil { return err } diff --git a/pkg/ottl/contexts/ottlmetric/metrics.go b/pkg/ottl/contexts/ottlmetric/metrics.go index dfe9cb1e5876..ac59814108e7 100644 --- a/pkg/ottl/contexts/ottlmetric/metrics.go +++ b/pkg/ottl/contexts/ottlmetric/metrics.go @@ -17,6 +17,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxmetric" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxresource" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxscope" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" ) // Experimental: *NOTE* this constant is subject to change or removal in the future. @@ -229,10 +230,10 @@ func accessCache() ottl.StandardGetSetter[TransformContext] { func accessCacheKey(key []ottl.Key[TransformContext]) ottl.StandardGetSetter[TransformContext] { return ottl.StandardGetSetter[TransformContext]{ Getter: func(ctx context.Context, tCtx TransformContext) (any, error) { - return internal.GetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key) + return ctxutil.GetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key) }, Setter: func(ctx context.Context, tCtx TransformContext, val any) error { - return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key, val) + return ctxutil.SetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key, val) }, } } diff --git a/pkg/ottl/contexts/ottlresource/resource.go b/pkg/ottl/contexts/ottlresource/resource.go index 95ba45fb449e..662d36b33635 100644 --- a/pkg/ottl/contexts/ottlresource/resource.go +++ b/pkg/ottl/contexts/ottlresource/resource.go @@ -16,6 +16,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxerror" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxresource" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging" ) @@ -180,10 +181,10 @@ func accessCache() ottl.StandardGetSetter[TransformContext] { func accessCacheKey(key []ottl.Key[TransformContext]) ottl.StandardGetSetter[TransformContext] { return ottl.StandardGetSetter[TransformContext]{ Getter: func(ctx context.Context, tCtx TransformContext) (any, error) { - return internal.GetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key) + return ctxutil.GetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key) }, Setter: func(ctx context.Context, tCtx TransformContext, val any) error { - return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key, val) + return ctxutil.SetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key, val) }, } } diff --git a/pkg/ottl/contexts/ottlscope/scope.go b/pkg/ottl/contexts/ottlscope/scope.go index 6835e106966d..1e173d8914f6 100644 --- a/pkg/ottl/contexts/ottlscope/scope.go +++ b/pkg/ottl/contexts/ottlscope/scope.go @@ -17,6 +17,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxerror" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxresource" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxscope" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging" ) @@ -214,10 +215,10 @@ func accessCache() ottl.StandardGetSetter[TransformContext] { func accessCacheKey(key []ottl.Key[TransformContext]) ottl.StandardGetSetter[TransformContext] { return ottl.StandardGetSetter[TransformContext]{ Getter: func(ctx context.Context, tCtx TransformContext) (any, error) { - return internal.GetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key) + return ctxutil.GetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key) }, Setter: func(ctx context.Context, tCtx TransformContext, val any) error { - return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key, val) + return ctxutil.SetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key, val) }, } } diff --git a/pkg/ottl/contexts/ottlspan/span.go b/pkg/ottl/contexts/ottlspan/span.go index d6e233cf7002..5dacec43c584 100644 --- a/pkg/ottl/contexts/ottlspan/span.go +++ b/pkg/ottl/contexts/ottlspan/span.go @@ -19,6 +19,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxresource" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxscope" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxspan" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging" ) @@ -234,10 +235,10 @@ func accessCache() ottl.StandardGetSetter[TransformContext] { func accessCacheKey(key []ottl.Key[TransformContext]) ottl.StandardGetSetter[TransformContext] { return ottl.StandardGetSetter[TransformContext]{ Getter: func(ctx context.Context, tCtx TransformContext) (any, error) { - return internal.GetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key) + return ctxutil.GetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key) }, Setter: func(ctx context.Context, tCtx TransformContext, val any) error { - return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key, val) + return ctxutil.SetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key, val) }, } } diff --git a/pkg/ottl/contexts/ottlspanevent/span_events.go b/pkg/ottl/contexts/ottlspanevent/span_events.go index 61e1a664df6a..94b10bf3088a 100644 --- a/pkg/ottl/contexts/ottlspanevent/span_events.go +++ b/pkg/ottl/contexts/ottlspanevent/span_events.go @@ -21,6 +21,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxscope" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxspan" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxspanevent" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging" ) @@ -286,10 +287,10 @@ func accessCache() ottl.StandardGetSetter[TransformContext] { func accessCacheKey(key []ottl.Key[TransformContext]) ottl.StandardGetSetter[TransformContext] { return ottl.StandardGetSetter[TransformContext]{ Getter: func(ctx context.Context, tCtx TransformContext) (any, error) { - return internal.GetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key) + return ctxutil.GetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key) }, Setter: func(ctx context.Context, tCtx TransformContext, val any) error { - return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key, val) + return ctxutil.SetMapValue[TransformContext](ctx, tCtx, tCtx.getCache(), key, val) }, } } @@ -353,10 +354,10 @@ func accessSpanEventAttributes() ottl.StandardGetSetter[TransformContext] { func accessSpanEventAttributesKey(key []ottl.Key[TransformContext]) ottl.StandardGetSetter[TransformContext] { return ottl.StandardGetSetter[TransformContext]{ Getter: func(ctx context.Context, tCtx TransformContext) (any, error) { - return internal.GetMapValue[TransformContext](ctx, tCtx, tCtx.GetSpanEvent().Attributes(), key) + return ctxutil.GetMapValue[TransformContext](ctx, tCtx, tCtx.GetSpanEvent().Attributes(), key) }, Setter: func(ctx context.Context, tCtx TransformContext, val any) error { - return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetSpanEvent().Attributes(), key, val) + return ctxutil.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetSpanEvent().Attributes(), key, val) }, } }