SentryLoggerProvider class final
A logger provider that integrates with Sentry for error reporting and crash analytics.
This provider creates a SentryObserver that sends logs to Sentry and handles exceptions by reporting them to Sentry.
Example usage:
// Basic usage with default settings
final provider = SentryLoggerProvider(
dsn: 'https://key@sentry.io/project',
);
// Events for warning+, breadcrumbs for debug+
final provider = SentryLoggerProvider(
dsn: 'https://key@sentry.io/project',
filter: const MinLevelFilter(FlexLogLevel.warning),
breadcrumbFilter: const MinLevelFilter(FlexLogLevel.debug),
);
// With scope enrichment based on your own error types
final provider = SentryLoggerProvider(
dsn: 'https://key@sentry.io/project',
onEnrichScope: (scope, log) {
final error = log.error;
if (error is MyAppError) {
scope
..setTag('error.code', error.code)
..fingerprint = [error.code];
}
},
);
// With custom Sentry configuration
final provider = SentryLoggerProvider(
dsn: 'https://key@sentry.io/project',
optionsConfiguration: (options) {
options.environment = 'production';
options.release = '1.0.0';
options.sampleRate = 0.8;
options.tracesSampleRate = 0.2;
options.debug = true;
options.captureFailedRequests = true;
options.attachScreenshot = true;
options.enableAutoPerformanceTracing = true;
},
);
Constructors
- SentryLoggerProvider({required String dsn, LogFilter filter = const MinLevelFilter(FlexLogLevel.error), LogFilter breadcrumbFilter = const MinLevelFilter(FlexLogLevel.info), SentryScopeEnricher? onEnrichScope, void optionsConfiguration(SentryFlutterOptions options)?, String? providerId})
- Creates a Sentry logger provider with the specified settings.
Properties
-
Filter to determine which logs are recorded as Sentry breadcrumbs.
final
- dsn → String
-
DSN (Data Source Name) for Sentry configuration.
final
- filter → LogFilter
-
Filter to determine which logs create Sentry events (issues).
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- onEnrichScope → SentryScopeEnricher?
-
Optional callback to enrich the Sentry
Scopebefore a log is captured.final - optionsConfiguration → void Function(SentryFlutterOptions options)?
-
Optional callback to configure
SentryFlutterOptions.final - providerId → String
-
Unique id for this provider (used for deduplication and lookup).
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createObserver(
) → FlexObserver? - Creates the observer for log messages.
-
dispose(
) → Future< void> - Disposes any resources used by the provider.
-
initialize(
) → Future< void> - Initializes the provider.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited