From bc0447d98b919348acdd04a055ce3e93af0e6516 Mon Sep 17 00:00:00 2001 From: Dan Jaglowski Date: Mon, 4 Nov 2024 21:09:09 -0500 Subject: [PATCH] [ottl] Demonstrate simpler context constructors --- pkg/ottl/contexts/ottldatapoint/datapoint.go | 5 +++++ pkg/ottl/contexts/ottllog/log.go | 5 +++++ pkg/ottl/contexts/ottlmetric/metrics.go | 5 +++++ pkg/ottl/contexts/ottlspan/span.go | 5 +++++ pkg/ottl/contexts/ottlspanevent/span_events.go | 5 +++++ 5 files changed, 25 insertions(+) diff --git a/pkg/ottl/contexts/ottldatapoint/datapoint.go b/pkg/ottl/contexts/ottldatapoint/datapoint.go index a8a6f2158045..0d967c618b23 100644 --- a/pkg/ottl/contexts/ottldatapoint/datapoint.go +++ b/pkg/ottl/contexts/ottldatapoint/datapoint.go @@ -60,6 +60,11 @@ func (tCtx TransformContext) MarshalLogObject(encoder zapcore.ObjectEncoder) err type Option func(*ottl.Parser[TransformContext]) +func NewTransformContextSimple(dataPoint any, metric pmetric.Metric, scopeMetrics pmetric.ScopeMetrics, resourceMetrics pmetric.ResourceMetrics) TransformContext { + return NewTransformContext(dataPoint, metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetrics.Resource(), scopeMetrics, resourceMetrics) +} + +// Deprecated: Use NewTransformContextSimple instead. func NewTransformContext(dataPoint any, metric pmetric.Metric, metrics pmetric.MetricSlice, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, scopeMetrics pmetric.ScopeMetrics, resourceMetrics pmetric.ResourceMetrics) TransformContext { return TransformContext{ dataPoint: dataPoint, diff --git a/pkg/ottl/contexts/ottllog/log.go b/pkg/ottl/contexts/ottllog/log.go index 5ae40916864e..b6987c7aadea 100644 --- a/pkg/ottl/contexts/ottllog/log.go +++ b/pkg/ottl/contexts/ottllog/log.go @@ -67,6 +67,11 @@ func (tCtx TransformContext) MarshalLogObject(encoder zapcore.ObjectEncoder) err type Option func(*ottl.Parser[TransformContext]) +func NewTransformContextSimple(logRecord plog.LogRecord, scopeLogs plog.ScopeLogs, resourceLogs plog.ResourceLogs) TransformContext { + return NewTransformContext(logRecord, scopeLogs.Scope(), resourceLogs.Resource(), scopeLogs, resourceLogs) +} + +// Deprecated: Use NewTransformContextSimple instead. func NewTransformContext(logRecord plog.LogRecord, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, scopeLogs plog.ScopeLogs, resourceLogs plog.ResourceLogs) TransformContext { return TransformContext{ logRecord: logRecord, diff --git a/pkg/ottl/contexts/ottlmetric/metrics.go b/pkg/ottl/contexts/ottlmetric/metrics.go index ce5ff174ee69..6aadbd455f5a 100644 --- a/pkg/ottl/contexts/ottlmetric/metrics.go +++ b/pkg/ottl/contexts/ottlmetric/metrics.go @@ -31,6 +31,11 @@ type TransformContext struct { type Option func(*ottl.Parser[TransformContext]) +func NewTransformContextSimple(metric pmetric.Metric, scopeMetrics pmetric.ScopeMetrics, resourceMetrics pmetric.ResourceMetrics) TransformContext { + return NewTransformContext(metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetrics.Resource(), scopeMetrics, resourceMetrics) +} + +// Deprecated: Use NewTransformContextSimple instead. func NewTransformContext(metric pmetric.Metric, metrics pmetric.MetricSlice, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, scopeMetrics pmetric.ScopeMetrics, resourceMetrics pmetric.ResourceMetrics) TransformContext { return TransformContext{ metric: metric, diff --git a/pkg/ottl/contexts/ottlspan/span.go b/pkg/ottl/contexts/ottlspan/span.go index 34fc2c944c1e..febb600abb62 100644 --- a/pkg/ottl/contexts/ottlspan/span.go +++ b/pkg/ottl/contexts/ottlspan/span.go @@ -41,6 +41,11 @@ func (tCtx TransformContext) MarshalLogObject(encoder zapcore.ObjectEncoder) err type Option func(*ottl.Parser[TransformContext]) +func NewTransformContextSimple(span ptrace.Span, scopeSpans ptrace.ScopeSpans, resourceSpans ptrace.ResourceSpans) TransformContext { + return NewTransformContext(span, scopeSpans.Scope(), resourceSpans.Resource(), scopeSpans, resourceSpans) +} + +// Deprecated: Use NewTransformContextSimple instead. func NewTransformContext(span ptrace.Span, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, scopeSpans ptrace.ScopeSpans, resourceSpans ptrace.ResourceSpans) TransformContext { return TransformContext{ span: span, diff --git a/pkg/ottl/contexts/ottlspanevent/span_events.go b/pkg/ottl/contexts/ottlspanevent/span_events.go index 8a4de90f15e9..1bdef6854be0 100644 --- a/pkg/ottl/contexts/ottlspanevent/span_events.go +++ b/pkg/ottl/contexts/ottlspanevent/span_events.go @@ -44,6 +44,11 @@ func (tCtx TransformContext) MarshalLogObject(encoder zapcore.ObjectEncoder) err type Option func(*ottl.Parser[TransformContext]) +func NewTransformContextSimple(spanEvent ptrace.SpanEvent, span ptrace.Span, scopeSpans ptrace.ScopeSpans, resourceSpans ptrace.ResourceSpans) TransformContext { + return NewTransformContext(spanEvent, span, scopeSpans.Scope(), resourceSpans.Resource(), scopeSpans, resourceSpans) +} + +// Deprecated: Use NewTransformContextSimple instead. func NewTransformContext(spanEvent ptrace.SpanEvent, span ptrace.Span, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, scopeSpans ptrace.ScopeSpans, resourceSpans ptrace.ResourceSpans) TransformContext { return TransformContext{ spanEvent: spanEvent,