@@ -29,7 +29,7 @@ type signalToMetrics struct {
2929 collectorInstanceInfo model.CollectorInstanceInfo
3030 logger * zap.Logger
3131
32- spanMetricDefs []model.MetricDef [ottlspan.TransformContext ]
32+ spanMetricDefs []model.MetricDef [* ottlspan.TransformContext ]
3333 dpMetricDefs []model.MetricDef [ottldatapoint.TransformContext ]
3434 logMetricDefs []model.MetricDef [ottllog.TransformContext ]
3535 profileMetricDefs []model.MetricDef [ottlprofile.TransformContext ]
@@ -49,7 +49,7 @@ func (sm *signalToMetrics) ConsumeTraces(ctx context.Context, td ptrace.Traces)
4949
5050 processedMetrics := pmetric .NewMetrics ()
5151 processedMetrics .ResourceMetrics ().EnsureCapacity (td .ResourceSpans ().Len ())
52- aggregator := aggregator.NewAggregator [ottlspan.TransformContext ](processedMetrics )
52+ aggregator := aggregator.NewAggregator [* ottlspan.TransformContext ](processedMetrics )
5353
5454 for i := 0 ; i < td .ResourceSpans ().Len (); i ++ {
5555 resourceSpan := td .ResourceSpans ().At (i )
@@ -67,22 +67,26 @@ func (sm *signalToMetrics) ConsumeTraces(ctx context.Context, td ptrace.Traces)
6767
6868 // The transform context is created from original attributes so that the
6969 // OTTL expressions are also applied on the original attributes.
70- tCtx := ottlspan .NewTransformContext (span , scopeSpan .Scope (), resourceSpan .Resource (), scopeSpan , resourceSpan )
70+ tCtx := ottlspan .BorrowContext (span , scopeSpan .Scope (), resourceSpan .Resource (), scopeSpan , resourceSpan )
7171 if md .Conditions != nil {
7272 match , err := md .Conditions .Eval (ctx , tCtx )
7373 if err != nil {
74+ ottlspan .ReturnContext (tCtx )
7475 return fmt .Errorf ("failed to evaluate conditions: %w" , err )
7576 }
7677 if ! match {
78+ ottlspan .ReturnContext (tCtx )
7779 sm .logger .Debug ("condition not matched, skipping" , zap .String ("name" , md .Key .Name ))
7880 continue
7981 }
8082 }
8183
8284 filteredResAttrs := md .FilterResourceAttributes (resourceAttrs , sm .collectorInstanceInfo )
8385 if err := aggregator .Aggregate (ctx , tCtx , md , filteredResAttrs , filteredSpanAttrs , 1 ); err != nil {
86+ ottlspan .ReturnContext (tCtx )
8487 return err
8588 }
89+ ottlspan .ReturnContext (tCtx )
8690 }
8791 }
8892 }
0 commit comments