From abac513f9d603790280b7cf7b0de9028e7b7d1f2 Mon Sep 17 00:00:00 2001 From: Dimosthenis Pagakis Date: Thu, 5 Dec 2024 15:00:32 +0100 Subject: [PATCH] feat: add a low default sample ratio (#28) * feat: add a low default sample ratio * refactor: diff sample rate per env --- src/main/kotlin/com/monta/otel/extension/Customizer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/monta/otel/extension/Customizer.java b/src/main/kotlin/com/monta/otel/extension/Customizer.java index 27453d3..745ef9b 100644 --- a/src/main/kotlin/com/monta/otel/extension/Customizer.java +++ b/src/main/kotlin/com/monta/otel/extension/Customizer.java @@ -10,6 +10,7 @@ import io.opentelemetry.semconv.ServiceAttributes; import io.opentelemetry.semconv.UrlAttributes; +import java.util.Objects; import java.util.UUID; /** @@ -60,7 +61,8 @@ private static Sampler getSampler() { return Sampler.alwaysOff(); } } else { - return Sampler.alwaysOn(); + double rate = Objects.equals(System.getenv("STAGE"), "production") ? 0.1 : 1.0; + return Sampler.traceIdRatioBased(rate); } } }