SamplingTransport class

A Transport decorator that probabilistically samples log events before forwarding them to an inner Transport.

Pass sampleRate between 0.0 (drop all) and 1.0 (forward all). Optionally restrict sampling to specific levels; events at unlisted levels are always forwarded.

Example — forward only 10 % of debug/trace logs to Sentry:

SentryTransport()
  .withSampling(
    sampleRate: 0.1,
    levels: [LogLevel.trace, LogLevel.debug],
  );
Inheritance
Available extensions

Constructors

SamplingTransport(Transport inner, {required double sampleRate, List<LogLevel> levels = const [], Random? random, LogLevel level = LogLevel.trace, Map<String, dynamic> config = const {}})
Creates a SamplingTransport.

Properties

config Map<String, dynamic>
Arbitrary key/value options passed to the transport at construction time.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
inner Transport
The inner transport that receives sampled events.
final
level LogLevel
Minimum severity level this transport will handle.
finalinherited
levels List<LogLevel>
Levels subject to sampling. Events at other levels are always forwarded. When empty, all levels are sampled.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sampleRate double
Fraction of matching events to forward. Must be between 0.0 and 1.0.
final

Methods

emitLog(LogEvent event) Future<void>
Performs the actual delivery of event to the transport's destination.
override
log(LogEvent event) Future<void>
Delivers event to the destination if event.level >= this.level.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
withBuffer({int maxSize = 100, Duration? flushInterval}) BufferedTransport

Available on Transport, provided by the BufferedTransportExtension extension

Wraps this transport in a BufferedTransport.
withSampling({required double sampleRate, List<LogLevel> levels = const [], Random? random}) SamplingTransport

Available on Transport, provided by the SamplingTransportExtension extension

Wraps this transport in a SamplingTransport.

Operators

operator ==(Object other) bool
The equality operator.
inherited