Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pkg/ottl] Add schema_url field to contexts #31444

Merged
merged 47 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
172a11f
[feat]: added breaking changes to newTransformContext func of log.go,…
kernelpanic77 Feb 27, 2024
8b70eef
[fix]: Added separate functions to access schema_url using Scope/Reso…
kernelpanic77 Feb 29, 2024
ff353a7
[feat]: Updated Implementation using SchemaURLItem Interface for ottl…
kernelpanic77 Mar 7, 2024
02457c7
[FIX]: Fixed SchemaURLItem interface to match the function call in Sc…
kernelpanic77 Mar 19, 2024
615c0cc
[FIX]: Fixed resource_test.go to match the ResourceContext interface
kernelpanic77 Mar 19, 2024
00eb90e
Merge branch 'main' into schemaurl-ottl-context
kernelpanic77 Mar 20, 2024
8b3735d
Merge branch 'open-telemetry:main' into schemaurl-ottl-context
kernelpanic77 Apr 12, 2024
af6427e
[feat]: completed implementation for spans and traces
kernelpanic77 Apr 13, 2024
8898a50
Update schemaurl-ottl-context.yaml
kernelpanic77 Apr 17, 2024
5d079ef
Merge branch 'open-telemetry:main' into schemaurl-ottl-context
kernelpanic77 Apr 17, 2024
f6a3b49
[fix]: separated changelogs for api breaking changes and user enhance…
kernelpanic77 Apr 22, 2024
53ce5c6
Merge branch 'schemaurl-ottl-context' of github.com:kernelpanic77/ope…
kernelpanic77 May 1, 2024
b41f52f
[feat]: add small changes to verify requirements for test_suite for s…
kernelpanic77 May 7, 2024
76ab825
[feat]: added breaking change to NewTransformContext function for ott…
kernelpanic77 May 15, 2024
6184491
[fix]: Completed Implementation TransformContext interface
kernelpanic77 May 15, 2024
a756781
[feat]: Completed the resource_test pkg.contexts.internal
kernelpanic77 May 15, 2024
5644f90
[fix]: added license to the schema.go for ottl.contexts.internal
kernelpanic77 May 16, 2024
2bb11bd
[feat]: Completed all required changes for PR
kernelpanic77 May 16, 2024
ab2d805
Merge branch 'main' into schemaurl-ottl-context
kernelpanic77 May 16, 2024
f778e6c
[feat]: Completed implementation for ottlscope
kernelpanic77 May 17, 2024
23851b8
Update pkg/ottl/contexts/internal/schema.go
evan-bradley May 17, 2024
914d2c0
Merge branch 'main' into schemaurl-ottl-context
kernelpanic77 May 20, 2024
ae7d24f
[fix]: Moved SchemaURL to ottlcommon package to expose the struct to …
kernelpanic77 May 22, 2024
a934a2b
[fix]: passed correct smetrics, rmetrics for ottldatapoint functions,…
kernelpanic77 May 31, 2024
647bd68
[feat]: added tests to transformprocessor package to set schema_url
kernelpanic77 Jun 2, 2024
ef9d3e5
Merge branch 'main' into schemaurl-ottl-context
kernelpanic77 Jun 2, 2024
ae2917b
Merge branch 'main' into schemaurl-ottl-context
kernelpanic77 Jun 3, 2024
e0192b8
Update pkg/ottl/contexts/ottlcommon/schema.go
evan-bradley Jun 3, 2024
94939e6
[fix]: Fixed linting issues inside transform processor
kernelpanic77 Jun 4, 2024
c70aac5
Merge branch 'main' into schemaurl-ottl-context
kernelpanic77 Jun 4, 2024
c97ec24
[fix]: linting errors removed from ottl/contexts
kernelpanic77 Jun 4, 2024
e509c1e
Merge branch 'main' into schemaurl-ottl-context
kernelpanic77 Jun 4, 2024
d38168c
[fix]: Adding linting rule in golang to prevent lint on interface by …
kernelpanic77 Jun 11, 2024
1c56ae4
Merge branch 'main' into schemaurl-ottl-context
kernelpanic77 Jun 11, 2024
7dcfa93
Removed ottlcommon package, did required changes for referencing sche…
kernelpanic77 Jun 12, 2024
71eb05a
Update go.sum
kernelpanic77 Jun 12, 2024
1a6a79c
Merge branch 'main' into schemaurl-ottl-context
kernelpanic77 Jun 12, 2024
b4a9273
Merge branch 'main' into schemaurl-ottl-context
kernelpanic77 Jun 12, 2024
f17772e
Merge branch 'main' into schemaurl-ottl-context
TylerHelmuth Jun 12, 2024
d1140fb
Updated test files to fix errors in unit tests
kernelpanic77 Jun 19, 2024
9a9115e
Merge branch 'main' into schemaurl-ottl-context
kernelpanic77 Jun 19, 2024
ace0b74
Updated test files to fix errors in processort/routingprocessor
kernelpanic77 Jun 19, 2024
2ca7e7e
Merge branch 'main' into schemaurl-ottl-context
kernelpanic77 Jun 20, 2024
79bfd39
Merge branch 'main' into schemaurl-ottl-context
kernelpanic77 Jun 21, 2024
e9f05b9
Update pkg/ottl/contexts/internal/schema.go
evan-bradley Jun 21, 2024
5f7ea93
Fix lint
evan-bradley Jun 21, 2024
638d61f
Run gofmt
evan-bradley Jun 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/schemaurl-ottl-context-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'breaking'

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: 'pkg/ottl'

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Changed ScopeContext, InstrumentationResourceContext, TransformContext interfaces to make SchemaURL accessible in resources and scopes on all signals"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [30229]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
27 changes: 27 additions & 0 deletions .chloggen/schemaurl-ottl-context-user.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'enhancement'

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: 'pkg/ottl'

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Add a `schema_url` field to access the SchemaURL in resources and scopes on all signals"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [30229]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
18 changes: 9 additions & 9 deletions connector/countconnector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ func (c *count) ConsumeTraces(ctx context.Context, td ptrace.Traces) error {

for k := 0; k < scopeSpan.Spans().Len(); k++ {
span := scopeSpan.Spans().At(k)
sCtx := ottlspan.NewTransformContext(span, scopeSpan.Scope(), resourceSpan.Resource())
sCtx := ottlspan.NewTransformContext(span, scopeSpan.Scope(), resourceSpan.Resource(), scopeSpan, resourceSpan)
multiError = errors.Join(multiError, spansCounter.update(ctx, span.Attributes(), sCtx))

for l := 0; l < span.Events().Len(); l++ {
event := span.Events().At(l)
eCtx := ottlspanevent.NewTransformContext(event, span, scopeSpan.Scope(), resourceSpan.Resource())
eCtx := ottlspanevent.NewTransformContext(event, span, scopeSpan.Scope(), resourceSpan.Resource(), scopeSpan, resourceSpan)
multiError = errors.Join(multiError, spanEventsCounter.update(ctx, event.Attributes(), eCtx))
}
}
Expand Down Expand Up @@ -101,39 +101,39 @@ func (c *count) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error {

for k := 0; k < scopeMetrics.Metrics().Len(); k++ {
metric := scopeMetrics.Metrics().At(k)
mCtx := ottlmetric.NewTransformContext(metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource())
mCtx := ottlmetric.NewTransformContext(metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric)
multiError = errors.Join(multiError, metricsCounter.update(ctx, pcommon.NewMap(), mCtx))

//exhaustive:enforce
switch metric.Type() {
case pmetric.MetricTypeGauge:
dps := metric.Gauge().DataPoints()
for i := 0; i < dps.Len(); i++ {
dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource())
dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric)
multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx))
}
case pmetric.MetricTypeSum:
dps := metric.Sum().DataPoints()
for i := 0; i < dps.Len(); i++ {
dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource())
dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric)
multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx))
}
case pmetric.MetricTypeSummary:
dps := metric.Summary().DataPoints()
for i := 0; i < dps.Len(); i++ {
dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource())
dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric)
multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx))
}
case pmetric.MetricTypeHistogram:
dps := metric.Histogram().DataPoints()
for i := 0; i < dps.Len(); i++ {
dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource())
dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric)
multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx))
}
case pmetric.MetricTypeExponentialHistogram:
dps := metric.ExponentialHistogram().DataPoints()
for i := 0; i < dps.Len(); i++ {
dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource())
dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric)
multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx))
}
case pmetric.MetricTypeEmpty:
Expand Down Expand Up @@ -176,7 +176,7 @@ func (c *count) ConsumeLogs(ctx context.Context, ld plog.Logs) error {
for k := 0; k < scopeLogs.LogRecords().Len(); k++ {
logRecord := scopeLogs.LogRecords().At(k)

lCtx := ottllog.NewTransformContext(logRecord, scopeLogs.Scope(), resourceLog.Resource())
lCtx := ottllog.NewTransformContext(logRecord, scopeLogs.Scope(), resourceLog.Resource(), scopeLogs, resourceLog)
multiError = errors.Join(multiError, counter.update(ctx, logRecord.Attributes(), lCtx))
}
}
Expand Down
2 changes: 1 addition & 1 deletion connector/routingconnector/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *logsConnector) ConsumeLogs(ctx context.Context, ld plog.Logs) error {

for i := 0; i < ld.ResourceLogs().Len(); i++ {
rlogs := ld.ResourceLogs().At(i)
rtx := ottlresource.NewTransformContext(rlogs.Resource())
rtx := ottlresource.NewTransformContext(rlogs.Resource(), rlogs)

noRoutesMatch := true
for _, route := range c.router.routeSlice {
Expand Down
2 changes: 1 addition & 1 deletion connector/routingconnector/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *metricsConnector) ConsumeMetrics(ctx context.Context, md pmetric.Metric

for i := 0; i < md.ResourceMetrics().Len(); i++ {
rmetrics := md.ResourceMetrics().At(i)
rtx := ottlresource.NewTransformContext(rmetrics.Resource())
rtx := ottlresource.NewTransformContext(rmetrics.Resource(), rmetrics)

noRoutesMatch := true
for _, route := range c.router.routeSlice {
Expand Down
2 changes: 1 addition & 1 deletion connector/routingconnector/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c *tracesConnector) ConsumeTraces(ctx context.Context, t ptrace.Traces) er
var errs error
for i := 0; i < t.ResourceSpans().Len(); i++ {
rspans := t.ResourceSpans().At(i)
rtx := ottlresource.NewTransformContext(rspans.Resource())
rtx := ottlresource.NewTransformContext(rspans.Resource(), rspans)

noRoutesMatch := true
for _, route := range c.router.routeSlice {
Expand Down
2 changes: 1 addition & 1 deletion exporter/honeycombmarkerexporter/logs_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (e *honeycombLogsExporter) exportMarkers(ctx context.Context, ld plog.Logs)
logs := slogs.LogRecords()
for k := 0; k < logs.Len(); k++ {
logRecord := logs.At(k)
tCtx := ottllog.NewTransformContext(logRecord, slogs.Scope(), rlogs.Resource())
tCtx := ottllog.NewTransformContext(logRecord, slogs.Scope(), rlogs.Resource(), slogs, rlogs)
for _, m := range e.markers {
match, err := m.logBoolExpr.Eval(ctx, tCtx)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions internal/filter/filterlog/filterlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ func TestLogRecord_Matching_False(t *testing.T) {
assert.NoError(t, err)
require.NotNil(t, expr)

val, err := expr.Eval(context.Background(), ottllog.NewTransformContext(lr, pcommon.NewInstrumentationScope(), pcommon.NewResource()))
val, err := expr.Eval(context.Background(), ottllog.NewTransformContext(lr, pcommon.NewInstrumentationScope(), pcommon.NewResource(), plog.NewScopeLogs(), plog.NewResourceLogs()))
require.NoError(t, err)
assert.False(t, val)

val, err = expr.Eval(context.Background(), ottllog.NewTransformContext(lrm, pcommon.NewInstrumentationScope(), pcommon.NewResource()))
val, err = expr.Eval(context.Background(), ottllog.NewTransformContext(lrm, pcommon.NewInstrumentationScope(), pcommon.NewResource(), plog.NewScopeLogs(), plog.NewResourceLogs()))
require.NoError(t, err)
assert.False(t, val)
})
Expand Down Expand Up @@ -228,12 +228,12 @@ func TestLogRecord_Matching_True(t *testing.T) {
require.NotNil(t, expr)

assert.NotNil(t, lr)
val, err := expr.Eval(context.Background(), ottllog.NewTransformContext(lr, pcommon.NewInstrumentationScope(), pcommon.NewResource()))
val, err := expr.Eval(context.Background(), ottllog.NewTransformContext(lr, pcommon.NewInstrumentationScope(), pcommon.NewResource(), plog.NewScopeLogs(), plog.NewResourceLogs()))
require.NoError(t, err)
assert.True(t, val)

assert.NotNil(t, lrm)
val, err = expr.Eval(context.Background(), ottllog.NewTransformContext(lrm, pcommon.NewInstrumentationScope(), pcommon.NewResource()))
val, err = expr.Eval(context.Background(), ottllog.NewTransformContext(lrm, pcommon.NewInstrumentationScope(), pcommon.NewResource(), plog.NewScopeLogs(), plog.NewResourceLogs()))
require.NoError(t, err)
assert.True(t, val)
})
Expand Down Expand Up @@ -1304,7 +1304,7 @@ func Test_NewSkipExpr_With_Bridge(t *testing.T) {

scope := pcommon.NewInstrumentationScope()

tCtx := ottllog.NewTransformContext(log, scope, resource)
tCtx := ottllog.NewTransformContext(log, scope, resource, plog.NewScopeLogs(), plog.NewResourceLogs())

boolExpr, err := NewSkipExpr(tt.condition)
require.NoError(t, err)
Expand Down Expand Up @@ -1378,7 +1378,7 @@ func BenchmarkFilterlog_NewSkipExpr(b *testing.B) {

scope := pcommon.NewInstrumentationScope()

tCtx := ottllog.NewTransformContext(log, scope, resource)
tCtx := ottllog.NewTransformContext(log, scope, resource, plog.NewScopeLogs(), plog.NewResourceLogs())

b.Run(tt.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
Expand Down
4 changes: 2 additions & 2 deletions internal/filter/filtermetric/filtermetric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestMatcherMatches(t *testing.T) {
assert.NotNil(t, matcher)
assert.NoError(t, err)

matches, err := matcher.Eval(context.Background(), ottlmetric.NewTransformContext(test.metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource()))
matches, err := matcher.Eval(context.Background(), ottlmetric.NewTransformContext(test.metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()))
assert.NoError(t, err)
assert.Equal(t, test.shouldMatch, matches)
})
Expand Down Expand Up @@ -188,7 +188,7 @@ func Test_NewSkipExpr_With_Bridge(t *testing.T) {

scope := pcommon.NewInstrumentationScope()

tCtx := ottlmetric.NewTransformContext(metric, pmetric.NewMetricSlice(), scope, resource)
tCtx := ottlmetric.NewTransformContext(metric, pmetric.NewMetricSlice(), scope, resource, pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics())

boolExpr, err := NewSkipExpr(tt.include, tt.exclude)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions internal/filter/filterottl/functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func Test_HasAttrKeyOnDatapoint(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
exprFunc, err := hasAttributeKeyOnDatapoint(tt.key)
assert.NoError(t, err)
result, err := exprFunc(context.Background(), ottlmetric.NewTransformContext(tt.input(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource()))
result, err := exprFunc(context.Background(), ottlmetric.NewTransformContext(tt.input(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()))
assert.NoError(t, err)
assert.Equal(t, tt.expected, result)
})
Expand Down Expand Up @@ -351,7 +351,7 @@ func Test_HasAttrOnDatapoint(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
exprFunc, err := hasAttributeOnDatapoint(tt.key, tt.expectedVal)
assert.NoError(t, err)
result, err := exprFunc(context.Background(), ottlmetric.NewTransformContext(tt.input(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource()))
result, err := exprFunc(context.Background(), ottlmetric.NewTransformContext(tt.input(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()))
assert.NoError(t, err)
assert.Equal(t, tt.expected, result)
})
Expand Down
10 changes: 5 additions & 5 deletions internal/filter/filterspan/filterspan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestSpan_Matching_False(t *testing.T) {
require.NoError(t, err)
assert.NotNil(t, expr)

val, err := expr.Eval(context.Background(), ottlspan.NewTransformContext(span, library, resource))
val, err := expr.Eval(context.Background(), ottlspan.NewTransformContext(span, library, resource, ptrace.NewScopeSpans(), ptrace.NewResourceSpans()))
require.NoError(t, err)
assert.False(t, val)
})
Expand All @@ -197,7 +197,7 @@ func TestSpan_MissingServiceName(t *testing.T) {
assert.NotNil(t, mp)

emptySpan := ptrace.NewSpan()
val, err := mp.Eval(context.Background(), ottlspan.NewTransformContext(emptySpan, pcommon.NewInstrumentationScope(), pcommon.NewResource()))
val, err := mp.Eval(context.Background(), ottlspan.NewTransformContext(emptySpan, pcommon.NewInstrumentationScope(), pcommon.NewResource(), ptrace.NewScopeSpans(), ptrace.NewResourceSpans()))
require.NoError(t, err)
assert.False(t, val)
}
Expand Down Expand Up @@ -288,7 +288,7 @@ func TestSpan_Matching_True(t *testing.T) {
require.NoError(t, err)
assert.NotNil(t, mp)

val, err := mp.Eval(context.Background(), ottlspan.NewTransformContext(span, library, resource))
val, err := mp.Eval(context.Background(), ottlspan.NewTransformContext(span, library, resource, ptrace.NewScopeSpans(), ptrace.NewResourceSpans()))
require.NoError(t, err)
assert.True(t, val)
})
Expand Down Expand Up @@ -1211,7 +1211,7 @@ func Test_NewSkipExpr_With_Bridge(t *testing.T) {
scope.SetName("scope")
scope.SetVersion("0.1.0")

tCtx := ottlspan.NewTransformContext(span, scope, resource)
tCtx := ottlspan.NewTransformContext(span, scope, resource, ptrace.NewScopeSpans(), ptrace.NewResourceSpans())

boolExpr, err := NewSkipExpr(tt.condition)
require.NoError(t, err)
Expand Down Expand Up @@ -1279,7 +1279,7 @@ func BenchmarkFilterspan_NewSkipExpr(b *testing.B) {

scope := pcommon.NewInstrumentationScope()

tCtx := ottlspan.NewTransformContext(span, scope, resource)
tCtx := ottlspan.NewTransformContext(span, scope, resource, ptrace.NewScopeSpans(), ptrace.NewResourceSpans())

b.Run(tt.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
Expand Down
17 changes: 17 additions & 0 deletions pkg/ottl/contexts/internal/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

type ResourceContext interface {
GetResource() pcommon.Resource
GetResourceSchemaURLItem() SchemaURLItem
}

func ResourcePathGetSetter[K ResourceContext](path ottl.Path[K]) (ottl.GetSetter[K], error) {
Expand All @@ -27,6 +28,8 @@ func ResourcePathGetSetter[K ResourceContext](path ottl.Path[K]) (ottl.GetSetter
return accessResourceAttributesKey[K](path.Keys()), nil
case "dropped_attributes_count":
return accessResourceDroppedAttributesCount[K](), nil
case "schema_url":
return accessResourceSchemaURLItem[K](), nil
default:
return nil, FormatDefaultErrorMessage(path.Name(), path.String(), "Resource", ResourceContextRef)
}
Expand Down Expand Up @@ -84,3 +87,17 @@ func accessResourceDroppedAttributesCount[K ResourceContext]() ottl.StandardGetS
},
}
}

func accessResourceSchemaURLItem[K ResourceContext]() ottl.StandardGetSetter[K] {
kernelpanic77 marked this conversation as resolved.
Show resolved Hide resolved
return ottl.StandardGetSetter[K]{
Getter: func(_ context.Context, tCtx K) (any, error) {
return tCtx.GetResourceSchemaURLItem().SchemaUrl(), nil
},
Setter: func(_ context.Context, tCtx K, val any) error {
if schemaURL, ok := val.(string); ok {
tCtx.GetResourceSchemaURLItem().SetSchemaUrl(schemaURL)
}
return nil
},
}
}
39 changes: 37 additions & 2 deletions pkg/ottl/contexts/internal/resource_test.go
evan-bradley marked this conversation as resolved.
Show resolved Hide resolved
evan-bradley marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
func TestResourcePathGetSetter(t *testing.T) {
refResource := createResource()

refResourceContext := newResourceContext(refResource)
newAttrs := pcommon.NewMap()
newAttrs.PutStr("hello", "world")

Expand All @@ -36,6 +37,17 @@ func TestResourcePathGetSetter(t *testing.T) {
pcommon.NewResource().CopyTo(resource)
},
},
{
name: "resource schema_url",
path: &TestPath[*resourceContext]{
N: "schema_url",
},
orig: refResourceContext.GetResourceSchemaURLItem().SchemaUrl(),
newVal: "new_schema_url",
modified: func(_ pcommon.Resource) {
refResourceContext.GetResourceSchemaURLItem().SetSchemaUrl("new_schema_url")
},
},
{
name: "attributes",
path: &TestPath[*resourceContext]{
Expand Down Expand Up @@ -370,14 +382,37 @@ func createResource() pcommon.Resource {
return resource
}

type TestResourceSchemaURLItem struct {
schemaURL string
}

func (t *TestResourceSchemaURLItem) SchemaUrl() string {
return t.schemaURL
}

func (t *TestResourceSchemaURLItem) SetSchemaUrl(v string) {
t.schemaURL = v
}
evan-bradley marked this conversation as resolved.
Show resolved Hide resolved

func createResourceSchemaURLItem() SchemaURLItem {
return &TestResourceSchemaURLItem{
schemaURL: "schema_url",
}
}

type resourceContext struct {
resource pcommon.Resource
resource pcommon.Resource
schemaURLItem SchemaURLItem
}

func (r *resourceContext) GetResource() pcommon.Resource {
return r.resource
}

func (r *resourceContext) GetResourceSchemaURLItem() SchemaURLItem {
return r.schemaURLItem
}

func newResourceContext(resource pcommon.Resource) *resourceContext {
return &resourceContext{resource: resource}
return &resourceContext{resource: resource, schemaURLItem: createResourceSchemaURLItem()}
}
Loading
Loading