Skip to content

Commit

Permalink
fix: don't send span when windows is not full
Browse files Browse the repository at this point in the history
  • Loading branch information
Syerikjan Khusayan committed Dec 4, 2024
1 parent 51531f2 commit 7f10ba8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,25 @@ boolean shouldSample(ReadableSpan span) {
String spanName = span.getName();
logger.log(
Level.INFO,
"spanName {0} - windowSize {1}: {2}",
new Object[] {span.getName(), windowSize, span.getAttributes()});
"spanName {0} - windowSize {1}: {2} - {3}",
new Object[] {
span.getName(), windowSize, span.getAttributes(), span.toSpanData().getStatus()
});
long duration = span.getLatencyNanos();
MovingAverage currMovingAvg =
movingAvgs.computeIfAbsent(spanName, ma -> new MovingAverage(windowSize));
currMovingAvg.add(duration);
if (currMovingAvg.getCount() >= windowSize) {
double avg = currMovingAvg.calcAverage();
logger.log(
Level.INFO,
"avg {0} * threshold {1} = {2}, duration {3}",
new Object[] {avg, threshold, avg * threshold, duration});
// discard
if (duration < avg * threshold) {
return false;
}
if (currMovingAvg.getCount() < windowSize) {
return false;
}
double avg = currMovingAvg.calcAverage();
logger.log(
Level.INFO,
"avg {0} * threshold {1} = {2}, duration {3}",
new Object[] {avg, threshold, avg * threshold, duration});
// discard
if (duration < avg * threshold) {
return false;
}
logger.log(
Level.INFO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ void notSampled() {
String serverTiming = ServerTimingHeaderCustomizer.toHeaderValue(Context.current());
serverTimingHeaderReader.consume(
new StringHttpCommonAttributesGetter(serverTiming), "request", "response");
System.out.println(serverTiming);
assertThat(DynamicSampler.getInstance().getSampledTraces()).doesNotContain(traceId);
});
}
Expand Down

0 comments on commit 7f10ba8

Please sign in to comment.