Skip to content

Commit

Permalink
fix: no need to send span when window is not null, change key for error
Browse files Browse the repository at this point in the history
  • Loading branch information
Syerikjan Khusayan committed Dec 4, 2024
1 parent 3deda55 commit 71db1bc
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.logging.Logger;

public class DynamicSampler {
private static final AttributeKey<String> EXCEPTION = AttributeKey.stringKey("exception.type");
private static final AttributeKey<String> EXCEPTION = AttributeKey.stringKey("error.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 @@ -95,7 +95,9 @@ private boolean isSlow(ReadableSpan span) {
MovingAverage currMovingAvg =
movingAvgs.computeIfAbsent(spanName, ma -> new MovingAverage(windowSize));
currMovingAvg.add(duration);
if (currMovingAvg.getCount() >= windowSize) {
if (currMovingAvg.getCount() < windowSize) {
return false;
}
double avg = currMovingAvg.calcAverage();
logger.log(
Level.INFO,
Expand All @@ -105,7 +107,6 @@ private boolean isSlow(ReadableSpan span) {
if (duration < avg * threshold) {
return false;
}
}
logger.log(
Level.INFO,
"sending span part of Trace: {0} - {1}",
Expand Down

0 comments on commit 71db1bc

Please sign in to comment.