Skip to content

Commit

Permalink
feature: added support for traceIdRatioBased
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianEstrada committed Jul 20, 2023
1 parent 8703cb3 commit 1d65faa
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main/kotlin/com/monta/otel/extension/Customizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,28 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) {
autoConfiguration.addTracerProviderCustomizer((sdkTracerProviderBuilder, configProperties) ->
sdkTracerProviderBuilder.setSampler(
Sampler.parentBased(
RuleBasedRoutingSampler.builder(SpanKind.SERVER, Sampler.alwaysOn())
RuleBasedRoutingSampler.builder(SpanKind.SERVER, getSampler())
.drop(SemanticAttributes.HTTP_TARGET, "/health*")
.drop(SemanticAttributes.HTTP_TARGET, "/prometheus*")
.build()
)
)
);
}

private static Sampler getSampler() {

String otelTracesSamplerArg = System.getenv("OTEL_TRACES_SAMPLER_ARG");

if (otelTracesSamplerArg != null) {
try {
double ratio = Double.parseDouble(otelTracesSamplerArg);
return Sampler.traceIdRatioBased(ratio);
} catch (Exception exception) {
return Sampler.alwaysOff();
}
} else {
return Sampler.alwaysOn();
}
}
}

0 comments on commit 1d65faa

Please sign in to comment.