@@ -10,18 +10,9 @@ import (
10
10
11
11
"github.com/alecthomas/participle/v2"
12
12
"go.opentelemetry.io/collector/component"
13
- "go.opentelemetry.io/otel/attribute"
14
- "go.opentelemetry.io/otel/codes"
15
- "go.opentelemetry.io/otel/trace"
16
- "go.opentelemetry.io/otel/trace/noop"
17
13
"go.uber.org/zap"
18
14
)
19
15
20
- const (
21
- logAttributeTraceID = "trace_id"
22
- logAttributeSpanID = "span_id"
23
- )
24
-
25
16
// Statement holds a top level Statement for processing telemetry data. A Statement is a combination of a function
26
17
// invocation and the boolean expression to match telemetry for invoking the function.
27
18
type Statement [K any ] struct {
@@ -240,7 +231,6 @@ type StatementSequence[K any] struct {
240
231
statements []* Statement [K ]
241
232
errorMode ErrorMode
242
233
telemetrySettings component.TelemetrySettings
243
- tracer trace.Tracer
244
234
}
245
235
246
236
type StatementSequenceOption [K any ] func (* StatementSequence [K ])
@@ -260,10 +250,6 @@ func NewStatementSequence[K any](statements []*Statement[K], telemetrySettings c
260
250
statements : statements ,
261
251
errorMode : PropagateError ,
262
252
telemetrySettings : telemetrySettings ,
263
- tracer : & noop.Tracer {},
264
- }
265
- if telemetrySettings .TracerProvider != nil {
266
- s .tracer = telemetrySettings .TracerProvider .Tracer ("ottl" )
267
253
}
268
254
for _ , op := range options {
269
255
op (& s )
@@ -276,62 +262,20 @@ func NewStatementSequence[K any](statements []*Statement[K], telemetrySettings c
276
262
// When the ErrorMode of the StatementSequence is `ignore`, errors are logged and execution continues to the next statement.
277
263
// When the ErrorMode of the StatementSequence is `silent`, errors are not logged and execution continues to the next statement.
278
264
func (s * StatementSequence [K ]) Execute (ctx context.Context , tCtx K ) error {
279
- ctx , sequenceSpan := s .tracer .Start (ctx , "ottl/StatementSequenceExecution" )
280
- defer sequenceSpan .End ()
281
- s .telemetrySettings .Logger .Debug (
282
- "initial TransformContext" ,
283
- zap .Any ("TransformContext" , tCtx ),
284
- zap .String (logAttributeTraceID , sequenceSpan .SpanContext ().TraceID ().String ()),
285
- zap .String (logAttributeSpanID , sequenceSpan .SpanContext ().SpanID ().String ()),
286
- )
265
+ s .telemetrySettings .Logger .Debug ("initial TransformContext" , zap .Any ("TransformContext" , tCtx ))
287
266
for _ , statement := range s .statements {
288
- statementCtx , statementSpan := s .tracer .Start (ctx , "ottl/StatementExecution" )
289
- statementSpan .SetAttributes (
290
- attribute.KeyValue {
291
- Key : "statement" ,
292
- Value : attribute .StringValue (statement .origText ),
293
- },
294
- )
295
- _ , condition , err := statement .Execute (statementCtx , tCtx )
296
- statementSpan .SetAttributes (
297
- attribute.KeyValue {
298
- Key : "condition.matched" ,
299
- Value : attribute .BoolValue (condition ),
300
- },
301
- )
302
- s .telemetrySettings .Logger .Debug (
303
- "TransformContext after statement execution" ,
304
- zap .String ("statement" , statement .origText ),
305
- zap .Bool ("condition matched" , condition ),
306
- zap .Any ("TransformContext" , tCtx ),
307
- zap .String (logAttributeTraceID , statementSpan .SpanContext ().TraceID ().String ()),
308
- zap .String (logAttributeSpanID , statementSpan .SpanContext ().SpanID ().String ()),
309
- )
267
+ _ , condition , err := statement .Execute (ctx , tCtx )
268
+ s .telemetrySettings .Logger .Debug ("TransformContext after statement execution" , zap .String ("statement" , statement .origText ), zap .Bool ("condition matched" , condition ), zap .Any ("TransformContext" , tCtx ))
310
269
if err != nil {
311
- statementSpan .RecordError (err )
312
- errMsg := fmt .Sprintf ("failed to execute statement '%s': %v" , statement .origText , err )
313
- statementSpan .SetStatus (codes .Error , errMsg )
314
270
if s .errorMode == PropagateError {
315
- sequenceSpan .SetStatus (codes .Error , errMsg )
316
- statementSpan .End ()
317
271
err = fmt .Errorf ("failed to execute statement: %v, %w" , statement .origText , err )
318
272
return err
319
273
}
320
274
if s .errorMode == IgnoreError {
321
- s .telemetrySettings .Logger .Warn (
322
- "failed to execute statement" ,
323
- zap .Error (err ),
324
- zap .String ("statement" , statement .origText ),
325
- zap .String (logAttributeTraceID , statementSpan .SpanContext ().TraceID ().String ()),
326
- zap .String (logAttributeSpanID , statementSpan .SpanContext ().SpanID ().String ()),
327
- )
275
+ s .telemetrySettings .Logger .Warn ("failed to execute statement" , zap .Error (err ), zap .String ("statement" , statement .origText ))
328
276
}
329
- } else {
330
- statementSpan .SetStatus (codes .Ok , "statement executed successfully" )
331
277
}
332
- statementSpan .End ()
333
278
}
334
- sequenceSpan .SetStatus (codes .Ok , "statement sequence executed successfully" )
335
279
return nil
336
280
}
337
281
0 commit comments