From 891efac7482a4b10381a811967c97b042d097734 Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Fri, 27 Oct 2023 09:59:03 +0000 Subject: [PATCH] chore: log warning if both tracesSampleRate and tracesSampler are set (#1701) * Log warning if both tracesSampleRate and tracesSampler are set * Update CHANGELOG * Update log * Update CHANGELOG --- CHANGELOG.md | 4 ++++ dart/lib/src/sentry_traces_sampler.dart | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5d88dea03..d6466d82fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Enhancements + +- Log warning if both tracesSampleRate and tracesSampler are set ([#1701](https://github.com/getsentry/sentry-dart/pull/1701)) + ### Features - Initial (alpha) support for profiling on iOS and macOS ([#1611](https://github.com/getsentry/sentry-dart/pull/1611)) diff --git a/dart/lib/src/sentry_traces_sampler.dart b/dart/lib/src/sentry_traces_sampler.dart index 1b49e2931b..b1668084c9 100644 --- a/dart/lib/src/sentry_traces_sampler.dart +++ b/dart/lib/src/sentry_traces_sampler.dart @@ -14,7 +14,12 @@ class SentryTracesSampler { SentryTracesSampler( this._options, { Random? random, - }) : _random = random ?? Random(); + }) : _random = random ?? Random() { + if (_options.tracesSampler != null && _options.tracesSampleRate != null) { + _options.logger(SentryLevel.warning, + 'Both tracesSampler and traceSampleRate are set. tracesSampler will take precedence and fallback to traceSampleRate if it returns null.'); + } + } SentryTracesSamplingDecision sample(SentrySamplingContext samplingContext) { final samplingDecision =