shouldSampleEvent function

double? shouldSampleEvent(
  1. String eventName,
  2. EventSamplingConfig config
)

Determine if an event should be sampled based on its sample rate. Returns the sample rate if sampled, null if not configured, 0 if dropped.

Implementation

double? shouldSampleEvent(String eventName, EventSamplingConfig config) {
  final eventConfig = config[eventName];
  if (eventConfig == null) return null;

  final rate = eventConfig.sampleRate;
  if (rate < 0 || rate > 1 || rate.isNaN) return null;
  if (rate >= 1) return null;
  if (rate <= 0) return 0;

  final random = Random();
  return random.nextDouble() < rate ? rate : 0;
}