@@ -42,6 +42,8 @@ type OtelFormat struct {
4242 trapLog * OtelLogger
4343 logTee chan string
4444 metrics * OtelMetrics
45+ warnFull map [string ]bool
46+ registry go_metrics.Registry
4547}
4648
4749const (
@@ -68,7 +70,7 @@ func init() {
6870}
6971
7072type OtelMetrics struct {
71- ExportDrops go_metrics.Counter
73+ ExportDrops map [ string ] go_metrics.Meter
7274}
7375
7476/*
@@ -88,8 +90,10 @@ func NewFormat(ctx context.Context, log logger.Underlying, cfg *ktranslate.OtelF
8890 config : cfg ,
8991 inputs : map [string ]chan OtelData {},
9092 logTee : logTee ,
93+ warnFull : map [string ]bool {},
94+ registry : registry ,
9195 metrics : & OtelMetrics {
92- ExportDrops : go_metrics .GetOrRegisterCounter ( "otel_export_drops" , registry ) ,
96+ ExportDrops : map [ string ] go_metrics.Meter {} ,
9397 },
9498 }
9599
@@ -176,7 +180,7 @@ func NewFormat(ctx context.Context, log logger.Underlying, cfg *ktranslate.OtelF
176180 jf .trapLog = ol
177181
178182 otelm = otel .Meter ("ktranslate" )
179- jf .Infof ("Running exporting via %s to %s. Blocking : %v" , cfg .Protocol , cfg .Endpoint , cfg .NoBlockExport )
183+ jf .Infof ("Running exporting via %s to %s. NoBlockExport : %v" , cfg .Protocol , cfg .Endpoint , cfg .NoBlockExport )
180184
181185 return jf , nil
182186}
@@ -231,7 +235,25 @@ func (f *OtelFormat) To(msgs []*kt.JCHF, serBuf []byte) (*kt.Output, error) {
231235 select {
232236 case ch <- m :
233237 default :
234- f .metrics .ExportDrops .Inc (1 )
238+ if ! f .warnFull [m .Name ] {
239+ f .mux .RUnlock ()
240+ f .mux .Lock ()
241+ firstWarn := ! f .warnFull [m .Name ]
242+ if firstWarn {
243+ f .warnFull [m .Name ] = true
244+ f .metrics .ExportDrops [m .Name ] = go_metrics .GetOrRegisterMeter (fmt .Sprintf ("otel_export_drops^name=%s^force=true" , m .Name ), f .registry )
245+ }
246+ f .mux .Unlock ()
247+ f .mux .RLock ()
248+ if firstWarn {
249+ f .Warnf ("OTEL channel full, dropping sample for metric=%s" , m .Name )
250+ } else {
251+ f .Debugf ("OTEL channel full, dropping sample for metric=%s" , m .Name )
252+ }
253+ f .metrics .ExportDrops [m .Name ].Mark (1 )
254+ } else {
255+ f .Debugf ("OTEL channel full, dropping sample for metric=%s" , m .Name )
256+ }
235257 }
236258 } else {
237259 ch <- m
@@ -292,7 +314,25 @@ func (f *OtelFormat) Rollup(rolls []rollup.Rollup) (*kt.Output, error) {
292314 select {
293315 case ch <- m :
294316 default :
295- f .metrics .ExportDrops .Inc (1 )
317+ if ! f .warnFull [m .Name ] {
318+ f .mux .RUnlock ()
319+ f .mux .Lock ()
320+ firstWarn := ! f .warnFull [m .Name ]
321+ if firstWarn {
322+ f .warnFull [m .Name ] = true
323+ f .metrics .ExportDrops [m .Name ] = go_metrics .GetOrRegisterMeter (fmt .Sprintf ("otel_export_drops^name=%s^force=true" , m .Name ), f .registry )
324+ }
325+ f .mux .Unlock ()
326+ f .mux .RLock ()
327+ if firstWarn {
328+ f .Warnf ("OTEL channel full, dropping sample for metric=%s" , m .Name )
329+ } else {
330+ f .Debugf ("OTEL channel full, dropping sample for metric=%s" , m .Name )
331+ }
332+ f .metrics .ExportDrops [m .Name ].Mark (1 )
333+ } else {
334+ f .Debugf ("OTEL channel full, dropping sample for metric=%s" , m .Name )
335+ }
296336 }
297337 } else {
298338 ch <- m
0 commit comments