Skip to content

Commit

Permalink
[pkg/ottl] remove support from accessing top-level objects
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerHelmuth committed Dec 17, 2024
1 parent a70fa09 commit 6d24583
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 60 deletions.
16 changes: 1 addition & 15 deletions pkg/ottl/contexts/internal/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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) {
Expand Down
16 changes: 1 addition & 15 deletions pkg/ottl/contexts/internal/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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) {
Expand Down
16 changes: 1 addition & 15 deletions pkg/ottl/contexts/internal/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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) {
Expand Down
16 changes: 1 addition & 15 deletions pkg/ottl/contexts/internal/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6d24583

Please sign in to comment.