Skip to content

Commit

Permalink
keep error traces
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger committed Dec 4, 2024
1 parent 51531f2 commit 3deda55
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package com.grafana.extensions.sampler;

import com.grafana.extensions.util.MovingAverage;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.trace.ReadableSpan;
import java.util.Collections;
Expand All @@ -17,6 +19,7 @@
import java.util.logging.Logger;

public class DynamicSampler {
private static final AttributeKey<String> EXCEPTION = AttributeKey.stringKey("exception.type");
private final Set<String> sampledTraces = new ConcurrentSkipListSet<>();
public static final Logger logger = Logger.getLogger(DynamicSampler.class.getName());
private final int windowSize;
Expand Down Expand Up @@ -74,6 +77,15 @@ public Set<String> getSampledTraces() {
}

boolean shouldSample(ReadableSpan span) {
return isSlow(span) || hasError(span);
}

private boolean hasError(ReadableSpan span) {
return span.toSpanData().getStatus().getStatusCode() == StatusCode.ERROR
|| span.getAttributes().get(EXCEPTION) != null;
}

private boolean isSlow(ReadableSpan span) {
String spanName = span.getName();
logger.log(
Level.INFO,
Expand Down

0 comments on commit 3deda55

Please sign in to comment.