Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instrumentation to the BatchSpansProcessor to count the number of dropped spans #889

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
package io.opentelemetry.sdk.trace.export;

import com.google.common.util.concurrent.MoreExecutors;
import io.opentelemetry.OpenTelemetry;
import io.opentelemetry.internal.Utils;
import io.opentelemetry.metrics.LongCounter;
import io.opentelemetry.metrics.LongCounter.BoundLongCounter;
import io.opentelemetry.metrics.Meter;
import io.opentelemetry.sdk.trace.ReadableSpan;
import io.opentelemetry.sdk.trace.SpanProcessor;
import io.opentelemetry.sdk.trace.data.SpanData;
Expand Down Expand Up @@ -233,6 +237,23 @@ private static Thread newThread(Runnable runnable) {
// concurrency.
private static final class Worker implements Runnable {

static {
Meter meter = OpenTelemetry.getMeterRegistry().get("io.opentelemetry.sdk.trace");
LongCounter droppedSpansCounter =
meter
.longCounterBuilder("droppedSpans")
.setMonotonic(true)
.setUnit("1")
.setDescription(
"The number of spans dropped by the BatchSpansProcessor due to high throughput.")
.build();
droppedSpans =
droppedSpansCounter.bind(
meter.createLabelSet("spanProcessorType", BatchSpansProcessor.class.getSimpleName()));
}

private static final BoundLongCounter droppedSpans;

private final ExecutorService executorService =
Executors.newSingleThreadExecutor(
new ThreadFactory() {
Expand Down Expand Up @@ -272,7 +293,7 @@ private Worker(
private void addSpan(ReadableSpan span) {
synchronized (monitor) {
if (spansList.size() == maxQueueSize) {
// TODO: Record a counter for dropped spans.
droppedSpans.add(1);
return;
}
// TODO: Record a gauge for referenced spans.
Expand Down