Skip to content

Commit

Permalink
added span size gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
mamunto committed Nov 20, 2024
1 parent d57d5ab commit 4522a0b
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]")
Expand All @@ -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 {
Expand Down

0 comments on commit 4522a0b

Please sign in to comment.