@@ -12,17 +12,19 @@ import (
1212	"sync" 
1313	"time" 
1414
15- 	"go.opencensus.io/stats" 
1615	"go.opentelemetry.io/collector/component" 
1716	"go.opentelemetry.io/collector/consumer" 
1817	"go.opentelemetry.io/collector/exporter" 
1918	"go.opentelemetry.io/collector/pdata/pcommon" 
2019	"go.opentelemetry.io/collector/pdata/pmetric" 
2120	"go.opentelemetry.io/collector/pdata/ptrace" 
2221	"go.opentelemetry.io/collector/processor" 
22+ 	"go.opentelemetry.io/collector/processor/processorhelper" 
2323	semconv "go.opentelemetry.io/collector/semconv/v1.13.0" 
24+ 	"go.opentelemetry.io/otel/metric" 
2425	"go.uber.org/zap" 
2526
27+ 	"github.com/open-telemetry/opentelemetry-collector-contrib/processor/servicegraphprocessor/internal/metadata" 
2628	"github.com/open-telemetry/opentelemetry-collector-contrib/processor/servicegraphprocessor/internal/store" 
2729)
2830
@@ -76,10 +78,14 @@ type serviceGraphProcessor struct {
7678	metricMutex  sync.RWMutex 
7779	keyToMetric  map [string ]metricSeries 
7880
81+ 	statDroppedSpans  metric.Int64Counter 
82+ 	statTotalEdges    metric.Int64Counter 
83+ 	statExpiredEdges  metric.Int64Counter 
84+ 
7985	shutdownCh  chan  any 
8086}
8187
82- func  newProcessor (logger   * zap. Logger , config  component.Config ) * serviceGraphProcessor  {
88+ func  newProcessor (set  component. TelemetrySettings , config  component.Config ) * serviceGraphProcessor  {
8389	pConfig  :=  config .(* Config )
8490
8591	bounds  :=  defaultLatencyHistogramBuckets 
@@ -102,9 +108,28 @@ func newProcessor(logger *zap.Logger, config component.Config) *serviceGraphProc
102108		pConfig .VirtualNodePeerAttributes  =  defaultPeerAttributes 
103109	}
104110
111+ 	scopeName  :=  "processor/servicegraphprocessor" 
112+ 	meter  :=  set .MeterProvider .Meter (scopeName )
113+ 
114+ 	droppedSpan , _  :=  meter .Int64Counter (
115+ 		processorhelper .BuildCustomMetricName (metadata .Type , "dropped_spans" ),
116+ 		metric .WithDescription ("Number of spans dropped when trying to add edges" ),
117+ 		metric .WithUnit ("1" ),
118+ 	)
119+ 	totalEdges , _  :=  meter .Int64Counter (
120+ 		processorhelper .BuildCustomMetricName (metadata .Type , "total_edges" ),
121+ 		metric .WithDescription ("Total number of unique edges" ),
122+ 		metric .WithUnit ("1" ),
123+ 	)
124+ 	expiredEdges , _  :=  meter .Int64Counter (
125+ 		processorhelper .BuildCustomMetricName (metadata .Type , "expired_edges" ),
126+ 		metric .WithDescription ("Number of edges that expired before finding its matching span" ),
127+ 		metric .WithUnit ("1" ),
128+ 	)
129+ 
105130	return  & serviceGraphProcessor {
106131		config :                               pConfig ,
107- 		logger :                               logger ,
132+ 		logger :                               set . Logger ,
108133		startTime :                            time .Now (),
109134		reqTotal :                             make (map [string ]int64 ),
110135		reqFailedTotal :                       make (map [string ]int64 ),
@@ -117,6 +142,9 @@ func newProcessor(logger *zap.Logger, config component.Config) *serviceGraphProc
117142		reqDurationBounds :                    bounds ,
118143		keyToMetric :                          make (map [string ]metricSeries ),
119144		shutdownCh :                           make (chan  any ),
145+ 		statDroppedSpans :                     droppedSpan ,
146+ 		statTotalEdges :                       totalEdges ,
147+ 		statExpiredEdges :                     expiredEdges ,
120148	}
121149}
122150
@@ -299,7 +327,7 @@ func (p *serviceGraphProcessor) aggregateMetrics(ctx context.Context, td ptrace.
299327
300328				if  errors .Is (err , store .ErrTooManyItems ) {
301329					totalDroppedSpans ++ 
302- 					stats . Record (ctx , statDroppedSpans . M ( 1 ) )
330+ 					p . statDroppedSpans . Add (ctx , 1 )
303331					continue 
304332				}
305333
@@ -309,7 +337,7 @@ func (p *serviceGraphProcessor) aggregateMetrics(ctx context.Context, td ptrace.
309337				}
310338
311339				if  isNew  {
312- 					stats . Record (ctx , statTotalEdges . M ( 1 ) )
340+ 					p . statTotalEdges . Add (ctx , 1 )
313341				}
314342			}
315343		}
@@ -354,7 +382,7 @@ func (p *serviceGraphProcessor) onExpire(e *store.Edge) {
354382		zap .Stringer ("trace_id" , e .TraceID ),
355383	)
356384
357- 	stats . Record (context .Background (), statExpiredEdges . M ( 1 ) )
385+ 	p . statExpiredEdges . Add (context .Background (), 1 )
358386
359387	if  virtualNodeFeatureGate .IsEnabled () {
360388		e .ConnectionType  =  store .VirtualNode 
0 commit comments