@@ -34,14 +34,17 @@ type ObsReport struct {
3434	tracer          trace.Tracer 
3535	logger          * zap.Logger 
3636
37- 	useOtelForMetrics         bool 
38- 	otelAttrs                 []attribute.KeyValue 
39- 	sentSpans                 metric.Int64Counter 
40- 	failedToSendSpans         metric.Int64Counter 
41- 	sentMetricPoints          metric.Int64Counter 
42- 	failedToSendMetricPoints  metric.Int64Counter 
43- 	sentLogRecords            metric.Int64Counter 
44- 	failedToSendLogRecords    metric.Int64Counter 
37+ 	useOtelForMetrics            bool 
38+ 	otelAttrs                    []attribute.KeyValue 
39+ 	sentSpans                    metric.Int64Counter 
40+ 	failedToSendSpans            metric.Int64Counter 
41+ 	failedToEnqueueSpans         metric.Int64Counter 
42+ 	sentMetricPoints             metric.Int64Counter 
43+ 	failedToSendMetricPoints     metric.Int64Counter 
44+ 	failedToEnqueueMetricPoints  metric.Int64Counter 
45+ 	sentLogRecords               metric.Int64Counter 
46+ 	failedToSendLogRecords       metric.Int64Counter 
47+ 	failedToEnqueueLogRecords    metric.Int64Counter 
4548}
4649
4750// ObsReportSettings are settings for creating an ObsReport. 
@@ -96,6 +99,12 @@ func (or *ObsReport) createOtelMetrics(cfg ObsReportSettings) error {
9699		metric .WithUnit ("1" ))
97100	errors  =  multierr .Append (errors , err )
98101
102+ 	or .failedToEnqueueSpans , err  =  meter .Int64Counter (
103+ 		obsmetrics .ExporterPrefix + obsmetrics .FailedToEnqueueSpansKey ,
104+ 		metric .WithDescription ("Number of spans failed to be added to the sending queue." ),
105+ 		metric .WithUnit ("1" ))
106+ 	errors  =  multierr .Append (errors , err )
107+ 
99108	or .sentMetricPoints , err  =  meter .Int64Counter (
100109		obsmetrics .ExporterPrefix + obsmetrics .SentMetricPointsKey ,
101110		metric .WithDescription ("Number of metric points successfully sent to destination." ),
@@ -108,6 +117,12 @@ func (or *ObsReport) createOtelMetrics(cfg ObsReportSettings) error {
108117		metric .WithUnit ("1" ))
109118	errors  =  multierr .Append (errors , err )
110119
120+ 	or .failedToEnqueueMetricPoints , err  =  meter .Int64Counter (
121+ 		obsmetrics .ExporterPrefix + obsmetrics .FailedToEnqueueMetricPointsKey ,
122+ 		metric .WithDescription ("Number of metric points failed to be added to the sending queue." ),
123+ 		metric .WithUnit ("1" ))
124+ 	errors  =  multierr .Append (errors , err )
125+ 
111126	or .sentLogRecords , err  =  meter .Int64Counter (
112127		obsmetrics .ExporterPrefix + obsmetrics .SentLogRecordsKey ,
113128		metric .WithDescription ("Number of log record successfully sent to destination." ),
@@ -120,6 +135,12 @@ func (or *ObsReport) createOtelMetrics(cfg ObsReportSettings) error {
120135		metric .WithUnit ("1" ))
121136	errors  =  multierr .Append (errors , err )
122137
138+ 	or .failedToEnqueueLogRecords , err  =  meter .Int64Counter (
139+ 		obsmetrics .ExporterPrefix + obsmetrics .FailedToEnqueueLogRecordsKey ,
140+ 		metric .WithDescription ("Number of log records failed to be added to the sending queue." ),
141+ 		metric .WithUnit ("1" ))
142+ 	errors  =  multierr .Append (errors , err )
143+ 
123144	return  errors 
124145}
125146
@@ -252,3 +273,43 @@ func toNumItems(numExportedItems int, err error) (int64, int64) {
252273	}
253274	return  int64 (numExportedItems ), 0 
254275}
276+ 
277+ func  (or  * ObsReport ) recordEnqueueFailure (ctx  context.Context , dataType  component.DataType , failed  int64 ) {
278+ 	if  or .useOtelForMetrics  {
279+ 		or .recordEnqueueFailureWithOtel (ctx , dataType , failed )
280+ 	} else  {
281+ 		or .recordEnqueueFailureWithOC (ctx , dataType , failed )
282+ 	}
283+ }
284+ 
285+ func  (or  * ObsReport ) recordEnqueueFailureWithOC (ctx  context.Context , dataType  component.DataType , failed  int64 ) {
286+ 	var  failedMeasure  * stats.Int64Measure 
287+ 	switch  dataType  {
288+ 	case  component .DataTypeTraces :
289+ 		failedMeasure  =  obsmetrics .ExporterFailedToSendSpans 
290+ 	case  component .DataTypeMetrics :
291+ 		failedMeasure  =  obsmetrics .ExporterFailedToSendMetricPoints 
292+ 	case  component .DataTypeLogs :
293+ 		failedMeasure  =  obsmetrics .ExporterFailedToSendLogRecords 
294+ 	}
295+ 	if  failed  >  0  {
296+ 		_  =  stats .RecordWithTags (
297+ 			ctx ,
298+ 			or .mutators ,
299+ 			failedMeasure .M (failed ))
300+ 	}
301+ }
302+ 
303+ func  (or  * ObsReport ) recordEnqueueFailureWithOtel (ctx  context.Context , dataType  component.DataType , failed  int64 ) {
304+ 	var  enqueueFailedMeasure  metric.Int64Counter 
305+ 	switch  dataType  {
306+ 	case  component .DataTypeTraces :
307+ 		enqueueFailedMeasure  =  or .failedToEnqueueSpans 
308+ 	case  component .DataTypeMetrics :
309+ 		enqueueFailedMeasure  =  or .failedToEnqueueMetricPoints 
310+ 	case  component .DataTypeLogs :
311+ 		enqueueFailedMeasure  =  or .failedToEnqueueLogRecords 
312+ 	}
313+ 
314+ 	enqueueFailedMeasure .Add (ctx , failed , metric .WithAttributes (or .otelAttrs ... ))
315+ }
0 commit comments