diff --git a/pkg/ottl/contexts/internal/metric.go b/pkg/ottl/contexts/internal/metric.go index e2944a73df45..92dbee9b3374 100644 --- a/pkg/ottl/contexts/internal/metric.go +++ b/pkg/ottl/contexts/internal/metric.go @@ -29,7 +29,7 @@ var MetricSymbolTable = map[ottl.EnumSymbol]ottl.Enum{ func MetricPathGetSetter[K MetricContext](path ottl.Path[K]) (ottl.GetSetter[K], error) { if path == nil { - return accessMetric[K](), nil + return nil, FormatDefaultErrorMessage("metric", "metric", "Metric", MetricRef) } switch path.Name() { case "name": @@ -51,20 +51,6 @@ func MetricPathGetSetter[K MetricContext](path ottl.Path[K]) (ottl.GetSetter[K], } } -func accessMetric[K MetricContext]() ottl.StandardGetSetter[K] { - return ottl.StandardGetSetter[K]{ - Getter: func(_ context.Context, tCtx K) (any, error) { - return tCtx.GetMetric(), nil - }, - Setter: func(_ context.Context, tCtx K, val any) error { - if newMetric, ok := val.(pmetric.Metric); ok { - newMetric.CopyTo(tCtx.GetMetric()) - } - return nil - }, - } -} - func accessName[K MetricContext]() ottl.StandardGetSetter[K] { return ottl.StandardGetSetter[K]{ Getter: func(_ context.Context, tCtx K) (any, error) { diff --git a/pkg/ottl/contexts/internal/resource.go b/pkg/ottl/contexts/internal/resource.go index 2dfee7fce9f8..101bbf178244 100644 --- a/pkg/ottl/contexts/internal/resource.go +++ b/pkg/ottl/contexts/internal/resource.go @@ -18,7 +18,7 @@ type ResourceContext interface { func ResourcePathGetSetter[K ResourceContext](path ottl.Path[K]) (ottl.GetSetter[K], error) { if path == nil { - return accessResource[K](), nil + return nil, FormatDefaultErrorMessage("resource", "resource", "Resource", ResourceContextRef) } switch path.Name() { case "attributes": @@ -35,20 +35,6 @@ func ResourcePathGetSetter[K ResourceContext](path ottl.Path[K]) (ottl.GetSetter } } -func accessResource[K ResourceContext]() ottl.StandardGetSetter[K] { - return ottl.StandardGetSetter[K]{ - Getter: func(_ context.Context, tCtx K) (any, error) { - return tCtx.GetResource(), nil - }, - Setter: func(_ context.Context, tCtx K, val any) error { - if newRes, ok := val.(pcommon.Resource); ok { - newRes.CopyTo(tCtx.GetResource()) - } - return nil - }, - } -} - func accessResourceAttributes[K ResourceContext]() ottl.StandardGetSetter[K] { return ottl.StandardGetSetter[K]{ Getter: func(_ context.Context, tCtx K) (any, error) { diff --git a/pkg/ottl/contexts/internal/scope.go b/pkg/ottl/contexts/internal/scope.go index 6bc5d7352005..7a698ebc533f 100644 --- a/pkg/ottl/contexts/internal/scope.go +++ b/pkg/ottl/contexts/internal/scope.go @@ -18,7 +18,7 @@ type InstrumentationScopeContext interface { func ScopePathGetSetter[K InstrumentationScopeContext](path ottl.Path[K]) (ottl.GetSetter[K], error) { if path == nil { - return accessInstrumentationScope[K](), nil + return nil, FormatDefaultErrorMessage("instrumentation_scope", "instrumentation_scope", "Instrumentation Scope", InstrumentationScopeRef) } switch path.Name() { case "name": @@ -40,20 +40,6 @@ func ScopePathGetSetter[K InstrumentationScopeContext](path ottl.Path[K]) (ottl. } } -func accessInstrumentationScope[K InstrumentationScopeContext]() ottl.StandardGetSetter[K] { - return ottl.StandardGetSetter[K]{ - Getter: func(_ context.Context, tCtx K) (any, error) { - return tCtx.GetInstrumentationScope(), nil - }, - Setter: func(_ context.Context, tCtx K, val any) error { - if newIl, ok := val.(pcommon.InstrumentationScope); ok { - newIl.CopyTo(tCtx.GetInstrumentationScope()) - } - return nil - }, - } -} - func accessInstrumentationScopeAttributes[K InstrumentationScopeContext]() ottl.StandardGetSetter[K] { return ottl.StandardGetSetter[K]{ Getter: func(_ context.Context, tCtx K) (any, error) { diff --git a/pkg/ottl/contexts/internal/span.go b/pkg/ottl/contexts/internal/span.go index 607cb2e110f9..c1ebf5a9b109 100644 --- a/pkg/ottl/contexts/internal/span.go +++ b/pkg/ottl/contexts/internal/span.go @@ -39,7 +39,7 @@ var SpanSymbolTable = map[ottl.EnumSymbol]ottl.Enum{ func SpanPathGetSetter[K SpanContext](path ottl.Path[K]) (ottl.GetSetter[K], error) { if path == nil { - return accessSpan[K](), nil + return nil, FormatDefaultErrorMessage("span", "span", SpanContextName, SpanRef) } switch path.Name() { case "trace_id": @@ -132,20 +132,6 @@ func SpanPathGetSetter[K SpanContext](path ottl.Path[K]) (ottl.GetSetter[K], err } } -func accessSpan[K SpanContext]() ottl.StandardGetSetter[K] { - return ottl.StandardGetSetter[K]{ - Getter: func(_ context.Context, tCtx K) (any, error) { - return tCtx.GetSpan(), nil - }, - Setter: func(_ context.Context, tCtx K, val any) error { - if newSpan, ok := val.(ptrace.Span); ok { - newSpan.CopyTo(tCtx.GetSpan()) - } - return nil - }, - } -} - func accessTraceID[K SpanContext]() ottl.StandardGetSetter[K] { return ottl.StandardGetSetter[K]{ Getter: func(_ context.Context, tCtx K) (any, error) {