Skip to content

Commit 829b010

Browse files
authored
[pkg/ottl] remove support from accessing top-level objects (#36872)
1 parent 7efaa99 commit 829b010

File tree

12 files changed

+36
-183
lines changed

12 files changed

+36
-183
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: pkg/ottl
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: removed the ability to reference entire parent objects.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [36872]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
Statements like `set(cache["resource"], resource)` in non-resource contexts will no longer work.
20+
21+
# If your change doesn't affect end users or the exported elements of any package,
22+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
23+
# Optional: The change log or logs in which this entry should be included.
24+
# e.g. '[user]' or '[user, api]'
25+
# Include 'user' if the change is relevant to end users.
26+
# Include 'api' if there is a change to a library API.
27+
# Default: '[user]'
28+
change_logs: []

pkg/ottl/contexts/internal/metric.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var MetricSymbolTable = map[ottl.EnumSymbol]ottl.Enum{
2929

3030
func MetricPathGetSetter[K MetricContext](path ottl.Path[K]) (ottl.GetSetter[K], error) {
3131
if path == nil {
32-
return accessMetric[K](), nil
32+
return nil, FormatDefaultErrorMessage("metric", "metric", "Metric", MetricRef)
3333
}
3434
switch path.Name() {
3535
case "name":
@@ -51,20 +51,6 @@ func MetricPathGetSetter[K MetricContext](path ottl.Path[K]) (ottl.GetSetter[K],
5151
}
5252
}
5353

54-
func accessMetric[K MetricContext]() ottl.StandardGetSetter[K] {
55-
return ottl.StandardGetSetter[K]{
56-
Getter: func(_ context.Context, tCtx K) (any, error) {
57-
return tCtx.GetMetric(), nil
58-
},
59-
Setter: func(_ context.Context, tCtx K, val any) error {
60-
if newMetric, ok := val.(pmetric.Metric); ok {
61-
newMetric.CopyTo(tCtx.GetMetric())
62-
}
63-
return nil
64-
},
65-
}
66-
}
67-
6854
func accessName[K MetricContext]() ottl.StandardGetSetter[K] {
6955
return ottl.StandardGetSetter[K]{
7056
Getter: func(_ context.Context, tCtx K) (any, error) {

pkg/ottl/contexts/internal/resource.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type ResourceContext interface {
1818

1919
func ResourcePathGetSetter[K ResourceContext](path ottl.Path[K]) (ottl.GetSetter[K], error) {
2020
if path == nil {
21-
return accessResource[K](), nil
21+
return nil, FormatDefaultErrorMessage("resource", "resource", "Resource", ResourceContextRef)
2222
}
2323
switch path.Name() {
2424
case "attributes":
@@ -35,20 +35,6 @@ func ResourcePathGetSetter[K ResourceContext](path ottl.Path[K]) (ottl.GetSetter
3535
}
3636
}
3737

38-
func accessResource[K ResourceContext]() ottl.StandardGetSetter[K] {
39-
return ottl.StandardGetSetter[K]{
40-
Getter: func(_ context.Context, tCtx K) (any, error) {
41-
return tCtx.GetResource(), nil
42-
},
43-
Setter: func(_ context.Context, tCtx K, val any) error {
44-
if newRes, ok := val.(pcommon.Resource); ok {
45-
newRes.CopyTo(tCtx.GetResource())
46-
}
47-
return nil
48-
},
49-
}
50-
}
51-
5238
func accessResourceAttributes[K ResourceContext]() ottl.StandardGetSetter[K] {
5339
return ottl.StandardGetSetter[K]{
5440
Getter: func(_ context.Context, tCtx K) (any, error) {

pkg/ottl/contexts/internal/resource_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,6 @@ func TestResourcePathGetSetter(t *testing.T) {
2828
newVal any
2929
modified func(resource pcommon.Resource)
3030
}{
31-
{
32-
name: "resource",
33-
path: nil,
34-
orig: refResource,
35-
newVal: pcommon.NewResource(),
36-
modified: func(resource pcommon.Resource) {
37-
pcommon.NewResource().CopyTo(resource)
38-
},
39-
},
4031
{
4132
name: "resource schema_url",
4233
path: &TestPath[*resourceContext]{

pkg/ottl/contexts/internal/scope.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type InstrumentationScopeContext interface {
1818

1919
func ScopePathGetSetter[K InstrumentationScopeContext](path ottl.Path[K]) (ottl.GetSetter[K], error) {
2020
if path == nil {
21-
return accessInstrumentationScope[K](), nil
21+
return nil, FormatDefaultErrorMessage("instrumentation_scope", "instrumentation_scope", "Instrumentation Scope", InstrumentationScopeRef)
2222
}
2323
switch path.Name() {
2424
case "name":
@@ -40,20 +40,6 @@ func ScopePathGetSetter[K InstrumentationScopeContext](path ottl.Path[K]) (ottl.
4040
}
4141
}
4242

43-
func accessInstrumentationScope[K InstrumentationScopeContext]() ottl.StandardGetSetter[K] {
44-
return ottl.StandardGetSetter[K]{
45-
Getter: func(_ context.Context, tCtx K) (any, error) {
46-
return tCtx.GetInstrumentationScope(), nil
47-
},
48-
Setter: func(_ context.Context, tCtx K, val any) error {
49-
if newIl, ok := val.(pcommon.InstrumentationScope); ok {
50-
newIl.CopyTo(tCtx.GetInstrumentationScope())
51-
}
52-
return nil
53-
},
54-
}
55-
}
56-
5743
func accessInstrumentationScopeAttributes[K InstrumentationScopeContext]() ottl.StandardGetSetter[K] {
5844
return ottl.StandardGetSetter[K]{
5945
Getter: func(_ context.Context, tCtx K) (any, error) {

pkg/ottl/contexts/internal/scope_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@ func TestScopePathGetSetter(t *testing.T) {
2727
newVal any
2828
modified func(is pcommon.InstrumentationScope)
2929
}{
30-
{
31-
name: "instrumentation_scope",
32-
path: nil,
33-
orig: refIS,
34-
newVal: pcommon.NewInstrumentationScope(),
35-
modified: func(is pcommon.InstrumentationScope) {
36-
pcommon.NewInstrumentationScope().CopyTo(is)
37-
},
38-
},
3930
{
4031
name: "instrumentation_scope name",
4132
path: &TestPath[*instrumentationScopeContext]{

pkg/ottl/contexts/internal/span.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var SpanSymbolTable = map[ottl.EnumSymbol]ottl.Enum{
3939

4040
func SpanPathGetSetter[K SpanContext](path ottl.Path[K]) (ottl.GetSetter[K], error) {
4141
if path == nil {
42-
return accessSpan[K](), nil
42+
return nil, FormatDefaultErrorMessage("span", "span", SpanContextName, SpanRef)
4343
}
4444
switch path.Name() {
4545
case "trace_id":
@@ -132,20 +132,6 @@ func SpanPathGetSetter[K SpanContext](path ottl.Path[K]) (ottl.GetSetter[K], err
132132
}
133133
}
134134

135-
func accessSpan[K SpanContext]() ottl.StandardGetSetter[K] {
136-
return ottl.StandardGetSetter[K]{
137-
Getter: func(_ context.Context, tCtx K) (any, error) {
138-
return tCtx.GetSpan(), nil
139-
},
140-
Setter: func(_ context.Context, tCtx K, val any) error {
141-
if newSpan, ok := val.(ptrace.Span); ok {
142-
newSpan.CopyTo(tCtx.GetSpan())
143-
}
144-
return nil
145-
},
146-
}
147-
}
148-
149135
func accessTraceID[K SpanContext]() ottl.StandardGetSetter[K] {
150136
return ottl.StandardGetSetter[K]{
151137
Getter: func(_ context.Context, tCtx K) (any, error) {

pkg/ottl/contexts/ottldatapoint/datapoint_test.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,8 +1923,6 @@ func createAttributeTelemetry(attributes pcommon.Map) {
19231923
}
19241924

19251925
func Test_newPathGetSetter_Metric(t *testing.T) {
1926-
refMetric := createMetricTelemetry()
1927-
19281926
newMetric := pmetric.NewMetric()
19291927
newMetric.SetName("new name")
19301928

@@ -1935,17 +1933,6 @@ func Test_newPathGetSetter_Metric(t *testing.T) {
19351933
newVal any
19361934
modified func(metric pmetric.Metric)
19371935
}{
1938-
{
1939-
name: "metric",
1940-
path: &internal.TestPath[TransformContext]{
1941-
N: "metric",
1942-
},
1943-
orig: refMetric,
1944-
newVal: newMetric,
1945-
modified: func(metric pmetric.Metric) {
1946-
newMetric.CopyTo(metric)
1947-
},
1948-
},
19491936
{
19501937
name: "metric name",
19511938
path: &internal.TestPath[TransformContext]{

pkg/ottl/contexts/ottllog/log_test.go

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var (
2727
)
2828

2929
func Test_newPathGetSetter(t *testing.T) {
30-
refLog, refIS, refResource := createTelemetry("string")
30+
refLog, _, _ := createTelemetry("string")
3131

3232
newAttrs := pcommon.NewMap()
3333
newAttrs.PutStr("hello", "world")
@@ -596,28 +596,6 @@ func Test_newPathGetSetter(t *testing.T) {
596596
log.SetDroppedAttributesCount(20)
597597
},
598598
},
599-
{
600-
name: "instrumentation_scope",
601-
path: &internal.TestPath[TransformContext]{
602-
N: "instrumentation_scope",
603-
},
604-
orig: refIS,
605-
newVal: pcommon.NewInstrumentationScope(),
606-
modified: func(_ plog.LogRecord, il pcommon.InstrumentationScope, _ pcommon.Resource, _ pcommon.Map) {
607-
pcommon.NewInstrumentationScope().CopyTo(il)
608-
},
609-
},
610-
{
611-
name: "resource",
612-
path: &internal.TestPath[TransformContext]{
613-
N: "resource",
614-
},
615-
orig: refResource,
616-
newVal: pcommon.NewResource(),
617-
modified: func(_ plog.LogRecord, _ pcommon.InstrumentationScope, resource pcommon.Resource, _ pcommon.Map) {
618-
pcommon.NewResource().CopyTo(resource)
619-
},
620-
},
621599
}
622600
for _, tt := range tests {
623601
t.Run(tt.name, func(t *testing.T) {

pkg/ottl/contexts/ottlscope/scope_test.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
func Test_newPathGetSetter(t *testing.T) {
20-
refIS, refResource := createTelemetry()
20+
refIS, _ := createTelemetry()
2121

2222
newAttrs := pcommon.NewMap()
2323
newAttrs.PutStr("hello", "world")
@@ -382,17 +382,6 @@ func Test_newPathGetSetter(t *testing.T) {
382382
is.SetVersion("next")
383383
},
384384
},
385-
{
386-
name: "resource",
387-
path: &internal.TestPath[TransformContext]{
388-
N: "resource",
389-
},
390-
orig: refResource,
391-
newVal: pcommon.NewResource(),
392-
modified: func(_ pcommon.InstrumentationScope, resource pcommon.Resource, _ pcommon.Map) {
393-
pcommon.NewResource().CopyTo(resource)
394-
},
395-
},
396385
}
397386
for _, tt := range tests {
398387
t.Run(tt.name, func(t *testing.T) {

pkg/ottl/contexts/ottlspan/span_test.go

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var (
2626
)
2727

2828
func Test_newPathGetSetter(t *testing.T) {
29-
refSpan, refIS, refResource := createTelemetry()
29+
refSpan, _, _ := createTelemetry()
3030

3131
newAttrs := pcommon.NewMap()
3232
newAttrs.PutStr("hello", "world")
@@ -649,28 +649,6 @@ func Test_newPathGetSetter(t *testing.T) {
649649
span.Status().SetMessage("bad span")
650650
},
651651
},
652-
{
653-
name: "instrumentation_scope",
654-
path: &internal.TestPath[TransformContext]{
655-
N: "instrumentation_scope",
656-
},
657-
orig: refIS,
658-
newVal: pcommon.NewInstrumentationScope(),
659-
modified: func(_ ptrace.Span, il pcommon.InstrumentationScope, _ pcommon.Resource, _ pcommon.Map) {
660-
pcommon.NewInstrumentationScope().CopyTo(il)
661-
},
662-
},
663-
{
664-
name: "resource",
665-
path: &internal.TestPath[TransformContext]{
666-
N: "resource",
667-
},
668-
orig: refResource,
669-
newVal: pcommon.NewResource(),
670-
modified: func(_ ptrace.Span, _ pcommon.InstrumentationScope, resource pcommon.Resource, _ pcommon.Map) {
671-
pcommon.NewResource().CopyTo(resource)
672-
},
673-
},
674652
}
675653
for _, tt := range tests {
676654
t.Run(tt.name, func(t *testing.T) {

pkg/ottl/contexts/ottlspanevent/span_events_test.go

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
var spanID2 = [8]byte{8, 7, 6, 5, 4, 3, 2, 1}
2121

2222
func Test_newPathGetSetter(t *testing.T) {
23-
refSpanEvent, refSpan, refIS, refResource := createTelemetry()
23+
refSpanEvent, _, _, _ := createTelemetry()
2424

2525
newAttrs := pcommon.NewMap()
2626
newAttrs.PutStr("hello", "world")
@@ -405,39 +405,6 @@ func Test_newPathGetSetter(t *testing.T) {
405405
spanEvent.SetDroppedAttributesCount(20)
406406
},
407407
},
408-
{
409-
name: "instrumentation_scope",
410-
path: &internal.TestPath[TransformContext]{
411-
N: "instrumentation_scope",
412-
},
413-
orig: refIS,
414-
newVal: pcommon.NewInstrumentationScope(),
415-
modified: func(_ ptrace.SpanEvent, _ ptrace.Span, il pcommon.InstrumentationScope, _ pcommon.Resource, _ pcommon.Map) {
416-
pcommon.NewInstrumentationScope().CopyTo(il)
417-
},
418-
},
419-
{
420-
name: "resource",
421-
path: &internal.TestPath[TransformContext]{
422-
N: "resource",
423-
},
424-
orig: refResource,
425-
newVal: pcommon.NewResource(),
426-
modified: func(_ ptrace.SpanEvent, _ ptrace.Span, _ pcommon.InstrumentationScope, resource pcommon.Resource, _ pcommon.Map) {
427-
pcommon.NewResource().CopyTo(resource)
428-
},
429-
},
430-
{
431-
name: "span",
432-
path: &internal.TestPath[TransformContext]{
433-
N: "span",
434-
},
435-
orig: refSpan,
436-
newVal: ptrace.NewSpan(),
437-
modified: func(_ ptrace.SpanEvent, span ptrace.Span, _ pcommon.InstrumentationScope, _ pcommon.Resource, _ pcommon.Map) {
438-
ptrace.NewSpan().CopyTo(span)
439-
},
440-
},
441408
}
442409
for _, tt := range tests {
443410
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)