@@ -18,9 +18,10 @@ import (
18
18
// Statement holds a top level Statement for processing telemetry data. A Statement is a combination of a function
19
19
// invocation and the boolean expression to match telemetry for invoking the function.
20
20
type Statement [K any ] struct {
21
- function Expr [K ]
22
- condition BoolExpr [K ]
23
- origText string
21
+ function Expr [K ]
22
+ condition BoolExpr [K ]
23
+ origText string
24
+ telemetrySettings component.TelemetrySettings
24
25
}
25
26
26
27
// Execute is a function that will execute the statement's function if the statement's condition is met.
@@ -29,6 +30,11 @@ type Statement[K any] struct {
29
30
// In addition, the functions return value is always returned.
30
31
func (s * Statement [K ]) Execute (ctx context.Context , tCtx K ) (any , bool , error ) {
31
32
condition , err := s .condition .Eval (ctx , tCtx )
33
+ defer func () {
34
+ if s .telemetrySettings .Logger != nil {
35
+ s .telemetrySettings .Logger .Debug ("TransformContext after statement execution" , zap .String ("statement" , s .origText ), zap .Bool ("condition matched" , condition ), zap .Any ("TransformContext" , tCtx ))
36
+ }
37
+ }()
32
38
if err != nil {
33
39
return nil , false , err
34
40
}
@@ -150,9 +156,10 @@ func (p *Parser[K]) ParseStatement(statement string) (*Statement[K], error) {
150
156
return nil , err
151
157
}
152
158
return & Statement [K ]{
153
- function : function ,
154
- condition : expression ,
155
- origText : statement ,
159
+ function : function ,
160
+ condition : expression ,
161
+ origText : statement ,
162
+ telemetrySettings : p .telemetrySettings ,
156
163
}, nil
157
164
}
158
165
@@ -332,10 +339,9 @@ func NewStatementSequence[K any](statements []*Statement[K], telemetrySettings c
332
339
// When the ErrorMode of the StatementSequence is `ignore`, errors are logged and execution continues to the next statement.
333
340
// When the ErrorMode of the StatementSequence is `silent`, errors are not logged and execution continues to the next statement.
334
341
func (s * StatementSequence [K ]) Execute (ctx context.Context , tCtx K ) error {
335
- s .telemetrySettings .Logger .Debug ("initial TransformContext" , zap .Any ("TransformContext" , tCtx ))
342
+ s .telemetrySettings .Logger .Debug ("initial TransformContext before executing StatementSequence " , zap .Any ("TransformContext" , tCtx ))
336
343
for _ , statement := range s .statements {
337
- _ , condition , err := statement .Execute (ctx , tCtx )
338
- s .telemetrySettings .Logger .Debug ("TransformContext after statement execution" , zap .String ("statement" , statement .origText ), zap .Bool ("condition matched" , condition ), zap .Any ("TransformContext" , tCtx ))
344
+ _ , _ , err := statement .Execute (ctx , tCtx )
339
345
if err != nil {
340
346
if s .errorMode == PropagateError {
341
347
err = fmt .Errorf ("failed to execute statement: %v, %w" , statement .origText , err )
0 commit comments