diff --git a/Sources/OpenTelemetrySdk/Trace/SpanProcessors/BatchSpanProcessor.swift b/Sources/OpenTelemetrySdk/Trace/SpanProcessors/BatchSpanProcessor.swift index b87824db..37f07498 100644 --- a/Sources/OpenTelemetrySdk/Trace/SpanProcessors/BatchSpanProcessor.swift +++ b/Sources/OpenTelemetrySdk/Trace/SpanProcessors/BatchSpanProcessor.swift @@ -88,6 +88,7 @@ private class BatchWorker: Thread { private var processedSpansCounter: LongCounter private let droppedAttrs: [String: AttributeValue] private let exportedAttrs: [String: AttributeValue] + private let spanGaugeBuilder: LongGaugeBuilder init( spanExporter: SpanExporter, meterProvider: StableMeterProvider, @@ -123,6 +124,9 @@ private class BatchWorker: Thread { ) } + self.spanGaugeBuilder = meter.gaugeBuilder(name: "spanSize") + .ofLongs() + processedSpansCounter = meter.counterBuilder(name: "processedSpans") .setUnit("1") .setDescription("The number of spans processed by the BatchSpanProcessor. [dropped=true if they were dropped due to high throughput]") @@ -145,8 +149,19 @@ private class BatchWorker: Thread { processedSpansCounter.add(value: 1, attribute: droppedAttrs) return } - // TODO: Record a gauge for referenced spans. spanList.append(span) + + // Recording span size gauge + _ = self.spanGaugeBuilder + .buildWithCallback { [count = spanList.count] result in + result.record( + value: count, + attributes: [ + BatchSpanProcessor.SPAN_PROCESSOR_TYPE_LABEL: .string(BatchSpanProcessor.SPAN_PROCESSOR_TYPE_VALUE) + ] + ) + } + // Notify the worker thread that at half of the queue is available. It will take // time anyway for the thread to wake up. if spanList.count >= halfMaxQueueSize {