65public final class GlowrootSlowThresholdMiddleware
implements Middleware {
67 private final Map<String, Long> thresholdByNormalizedPath;
68 private final long defaultThresholdMs;
70 private GlowrootSlowThresholdMiddleware(
final Map<String, Long> thresholds,
final long defaultThresholdMs) {
71 this.thresholdByNormalizedPath = Map.copyOf(thresholds);
72 this.defaultThresholdMs = defaultThresholdMs;
83 final var normalized = PathNormalizer.normalize(exchange.path());
84 final var threshold = thresholdByNormalizedPath.getOrDefault(normalized, defaultThresholdMs);
87 Glowroot.setTransactionSlowThreshold(threshold, TimeUnit.MILLISECONDS);
88 }
catch (
final Throwable ignore) {
92 return next.
handle(exchange);
98 public static final class Builder {
100 private final Map<String, Long> thresholds =
new HashMap<>();
101 private long defaultThresholdMs = 2_000L;
112 public Builder threshold(
final String normalizedPath,
final long thresholdMs) {
113 thresholds.put(normalizedPath, thresholdMs);
121 public Builder defaultThreshold(
final long thresholdMs) {
122 this.defaultThresholdMs = thresholdMs;
126 public GlowrootSlowThresholdMiddleware build() {
127 return new GlowrootSlowThresholdMiddleware(thresholds, defaultThresholdMs);