diff --git a/docs/platforms/dart/integrations/dio.mdx b/docs/platforms/dart/integrations/dio.mdx index a6ecebed271cd..bffc64a9db73b 100644 --- a/docs/platforms/dart/integrations/dio.mdx +++ b/docs/platforms/dart/integrations/dio.mdx @@ -58,18 +58,10 @@ final response = await dio.get('https://wrong-url.dev/'); This is an opt-out feature. The following example shows how to disable it: -```dart -import 'package:sentry/sentry.dart'; - -Future main() async { - await Sentry.init( - (options) { - options.dsn = '___PUBLIC_DSN___'; - options.captureFailedRequests = false; - }, - appRunner: initApp, // Init your App. - ); -} +```dart {2} +await Sentry.init((options) { + options.captureFailedRequests = false; +}); ``` ## Tracing for HTTP Requests diff --git a/docs/platforms/flutter/session-replay/index.mdx b/docs/platforms/flutter/session-replay/index.mdx index a6a08488060ec..e90b37f4c9115 100644 --- a/docs/platforms/flutter/session-replay/index.mdx +++ b/docs/platforms/flutter/session-replay/index.mdx @@ -32,14 +32,11 @@ dependencies: To set up the integration, add the following to your Sentry initialization: ```dart -await SentryFlutter.init( - (options) { - ... - options.experimental.replay.sessionSampleRate = 1.0; - options.experimental.replay.onErrorSampleRate = 1.0; - }, - appRunner: () => runApp(MyApp()), -); +await SentryFlutter.init((options) { + ... + options.experimental.replay.sessionSampleRate = 1.0; + options.experimental.replay.onErrorSampleRate = 1.0; +}); ``` ## Verify diff --git a/platform-includes/configuration/allow-urls/dart.mdx b/platform-includes/configuration/allow-urls/dart.mdx index 62d3d51c1eb82..f920476b3a816 100644 --- a/platform-includes/configuration/allow-urls/dart.mdx +++ b/platform-includes/configuration/allow-urls/dart.mdx @@ -1,13 +1,5 @@ -```dart -import 'package:sentry/sentry.dart'; - -Future main() async { - await Sentry.init( - (options) { - options.dsn = '___PUBLIC_DSN___'; - options.allowUrls = ["^https://sentry.com.*\$", "my-custom-domain"]; - }, - appRunner: initApp, // Init your App. - ); -} +```dart {2} +await Sentry.init((options) { + options.allowUrls = ["^https://sentry.com.*\$", "my-custom-domain"]; +}); ``` diff --git a/platform-includes/configuration/allow-urls/flutter.mdx b/platform-includes/configuration/allow-urls/flutter.mdx new file mode 100644 index 0000000000000..5fbc3635079da --- /dev/null +++ b/platform-includes/configuration/allow-urls/flutter.mdx @@ -0,0 +1,5 @@ +```dart {2} +await SentryFlutter.init((options) { + options.allowUrls = ["^https://sentry.com.*\$", "my-custom-domain"]; +}); +``` diff --git a/platform-includes/configuration/before-breadcrumb-hint/dart.mdx b/platform-includes/configuration/before-breadcrumb-hint/dart.mdx index 32ef5e78584f0..a25fa09f6a203 100644 --- a/platform-includes/configuration/before-breadcrumb-hint/dart.mdx +++ b/platform-includes/configuration/before-breadcrumb-hint/dart.mdx @@ -1,11 +1,7 @@ -```dart -import 'package:sentry/sentry.dart'; - -Breadcrumb? beforeBreadcrumb(Breadcrumb? breadcrumb, Hint hint) { - return hint is MyHint ? null : crumb; -} - -Future main() async { - await Sentry.init((options) => options.beforeBreadcrumb = beforeBreadcrumb); -} +```dart {3} +await Sentry.init((options) { + options.beforeBreadcrumb = (breadcrumb, hint) { + return hint is MyHint ? null : crumb; + }; +}); ``` diff --git a/platform-includes/configuration/before-breadcrumb-hint/flutter.mdx b/platform-includes/configuration/before-breadcrumb-hint/flutter.mdx new file mode 100644 index 0000000000000..75b7e191823cc --- /dev/null +++ b/platform-includes/configuration/before-breadcrumb-hint/flutter.mdx @@ -0,0 +1,7 @@ +```dart {3} +await SentryFlutter.init((options) { + options.beforeBreadcrumb = (breadcrumb, hint) { + return hint is MyHint ? null : crumb; + }; +}); +``` diff --git a/platform-includes/configuration/before-send-fingerprint/dart.mdx b/platform-includes/configuration/before-send-fingerprint/dart.mdx index 426cd8c042480..4f62cfb37fa97 100644 --- a/platform-includes/configuration/before-send-fingerprint/dart.mdx +++ b/platform-includes/configuration/before-send-fingerprint/dart.mdx @@ -1,14 +1,10 @@ -```dart -import 'package:sentry/sentry.dart'; - -FutureOr beforeSend(SentryEvent event, Hint hint) async { - if (event.throwable is DatabaseException) { - event = event.copyWith(fingerprint: ['database-connection-error']); - } - return event; -} - -Future main() async { - await Sentry.init((options) => options.beforeSend = beforeSend); -} +```dart {3-6} +await Sentry.init((options) { + options.beforeSend = (event, hint) { + if (event.throwable is DatabaseException) { + event = event.copyWith(fingerprint: ['database-connection-error']); + } + return event; + }; +}); ``` diff --git a/platform-includes/configuration/before-send-fingerprint/flutter.mdx b/platform-includes/configuration/before-send-fingerprint/flutter.mdx new file mode 100644 index 0000000000000..459286e11c4fa --- /dev/null +++ b/platform-includes/configuration/before-send-fingerprint/flutter.mdx @@ -0,0 +1,10 @@ +```dart {3-6} +await SentryFlutter.init((options) { + options.beforeSend = (event, hint) { + if (event.throwable is DatabaseException) { + event = event.copyWith(fingerprint: ['database-connection-error']); + } + return event; + }; +}); +``` diff --git a/platform-includes/configuration/before-send-hint/dart.mdx b/platform-includes/configuration/before-send-hint/dart.mdx index 0f17d38c06042..0cc46ecccd47e 100644 --- a/platform-includes/configuration/before-send-hint/dart.mdx +++ b/platform-includes/configuration/before-send-hint/dart.mdx @@ -1,11 +1,7 @@ -```dart -import 'package:sentry/sentry.dart'; - -FutureOr beforeSend(SentryEvent event, Hint hint) async { - return hint is MyHint ? null : event; -} - -Future main() async { - await Sentry.init((options) => options.beforeSend = beforeSend); -} +```dart {3} +await Sentry.init((options) { + options.beforeSend = (event, hint) { + return hint is MyHint ? null : event; + }; +}); ``` diff --git a/platform-includes/configuration/before-send-hint/flutter.mdx b/platform-includes/configuration/before-send-hint/flutter.mdx new file mode 100644 index 0000000000000..42d9d971aef2f --- /dev/null +++ b/platform-includes/configuration/before-send-hint/flutter.mdx @@ -0,0 +1,7 @@ +```dart {3} +await SentryFlutter.init((options) { + options.beforeSend = (event, hint) { + return hint is MyHint ? null : event; + }; +}); +``` diff --git a/platform-includes/configuration/before-send/dart.mdx b/platform-includes/configuration/before-send/dart.mdx index 470996be3120a..1f7a266b6deb7 100644 --- a/platform-includes/configuration/before-send/dart.mdx +++ b/platform-includes/configuration/before-send/dart.mdx @@ -1,13 +1,7 @@ -```dart -import 'package:sentry/sentry.dart'; - -FutureOr beforeSend(SentryEvent event, Hint hint) async { - // Modify the event here: - event = event.copyWith(serverName: null); // Don't send server names. - return event; -} - -Future main() async { - await Sentry.init((options) => options.beforeSend = beforeSend); -} +```dart {3} +await Sentry.init((options) { + options.beforeSend = (event, hint) { + return event.copyWith(serverName: null); // Don't send server names. + }; +}); ``` diff --git a/platform-includes/configuration/before-send/flutter.mdx b/platform-includes/configuration/before-send/flutter.mdx new file mode 100644 index 0000000000000..6616d2266d57a --- /dev/null +++ b/platform-includes/configuration/before-send/flutter.mdx @@ -0,0 +1,7 @@ +```dart {3} +await SentryFlutter.init((options) { + options.beforeSend = (event, hint) { + return event.copyWith(serverName: null); // Don't send server names. + }; +}); +``` diff --git a/platform-includes/configuration/deny-urls/dart.mdx b/platform-includes/configuration/deny-urls/dart.mdx index a8cfae64755b8..b582d5e32faca 100644 --- a/platform-includes/configuration/deny-urls/dart.mdx +++ b/platform-includes/configuration/deny-urls/dart.mdx @@ -1,13 +1,5 @@ -```dart -import 'package:sentry/sentry.dart'; - -Future main() async { - await Sentry.init( - (options) { - options.dsn = '___PUBLIC_DSN___'; - options.denyUrls = ["^.*ends-with-this\$", "denied-url"]; - }, - appRunner: initApp, // Init your App. - ); -} +```dart {2} +await Sentry.init((options) { + options.denyUrls = ["^.*ends-with-this\$", "denied-url"]; +}); ``` diff --git a/platform-includes/configuration/deny-urls/flutter.mdx b/platform-includes/configuration/deny-urls/flutter.mdx new file mode 100644 index 0000000000000..004a10e3042fc --- /dev/null +++ b/platform-includes/configuration/deny-urls/flutter.mdx @@ -0,0 +1,5 @@ +```dart {2} +await SentryFlutter.init((options) { + options.denyUrls = ["^.*ends-with-this\$", "denied-url"]; +}); +``` diff --git a/platform-includes/configuration/ignore-errors/dart.mdx b/platform-includes/configuration/ignore-errors/dart.mdx index 1196b49e59d78..3afc5a2c9078d 100644 --- a/platform-includes/configuration/ignore-errors/dart.mdx +++ b/platform-includes/configuration/ignore-errors/dart.mdx @@ -1,10 +1,5 @@ -```dart - await SentryFlutter.init( - (options) { - options.dsn = '___PUBLIC_DSN___'; - options.ignoreErrors = ["my-error", "^error-.*\$"]; - ... - }, - appRunner: () => runApp(MyApp()), - ); +```dart {2} +await Sentry.init((options) { + options.ignoreErrors = ["my-error", "^error-.*\$"]; +}); ``` diff --git a/platform-includes/configuration/ignore-transactions/dart.mdx b/platform-includes/configuration/ignore-transactions/dart.mdx index 607847272da60..c9367418ce72f 100644 --- a/platform-includes/configuration/ignore-transactions/dart.mdx +++ b/platform-includes/configuration/ignore-transactions/dart.mdx @@ -1,10 +1,5 @@ -```dart - await SentryFlutter.init( - (options) { - options.dsn = '___PUBLIC_DSN___'; - options.ignoreTransactions = ["my-transaction", "^transaction-.*\$" ]; - ... - }, - appRunner: () => runApp(MyApp()), - ); +```dart {2} +await Sentry.init((options) { + options.ignoreTransactions = ["my-transaction", "^transaction-.*\$" ]; +}); ``` diff --git a/platform-includes/configuration/sample-rate/dart.mdx b/platform-includes/configuration/sample-rate/dart.mdx index 20dc2bf4c504d..d0500e27fd4c3 100644 --- a/platform-includes/configuration/sample-rate/dart.mdx +++ b/platform-includes/configuration/sample-rate/dart.mdx @@ -1,8 +1,6 @@ -```dart -import 'package:sentry/sentry.dart'; - -Future main() async { +```dart {3} +await Sentry.init((options) { // Capture only 25% of events - await Sentry.init((options) => options.sampleRate = 0.25); -} + options.sampleRate = 0.25; +}); ``` diff --git a/platform-includes/configuration/sample-rate/flutter.mdx b/platform-includes/configuration/sample-rate/flutter.mdx new file mode 100644 index 0000000000000..7317c6b805dff --- /dev/null +++ b/platform-includes/configuration/sample-rate/flutter.mdx @@ -0,0 +1,6 @@ +```dart {3} +await SentryFlutter.init((options) { + // Capture only 25% of events + options.sampleRate = 0.25; +}); +``` diff --git a/platform-includes/enriching-events/attach-viewhierarchy/flutter.mdx b/platform-includes/enriching-events/attach-viewhierarchy/flutter.mdx index 260f182eb14bb..1ea2715d4cc05 100644 --- a/platform-includes/enriching-events/attach-viewhierarchy/flutter.mdx +++ b/platform-includes/enriching-events/attach-viewhierarchy/flutter.mdx @@ -1,14 +1,5 @@ -```dart -import 'package:flutter/widgets.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; - -Future main() async { - await SentryFlutter.init( - (options) { - options.dsn = '___PUBLIC_DSN___'; - options.attachViewHierarchy = true; - }, - appRunner: () => runApp(MyApp()), - ); -} +```dart {2} +await SentryFlutter.init((options) { + options.attachViewHierarchy = true; +}); ``` diff --git a/platform-includes/enriching-events/attachment-upload/dart.mdx b/platform-includes/enriching-events/attachment-upload/dart.mdx index 52f3d266831ed..34db2789ad9a3 100644 --- a/platform-includes/enriching-events/attachment-upload/dart.mdx +++ b/platform-includes/enriching-events/attachment-upload/dart.mdx @@ -4,6 +4,6 @@ import 'package:sentry/sentry.dart'; final attachment = SentryAttachment.fromByteData(bytedata); Sentry.configureScope((scope) { - scope.addAttachment(attachment); + scope.addAttachment(attachment); }); ``` diff --git a/platform-includes/enriching-events/breadcrumbs/before-breadcrumb/dart.mdx b/platform-includes/enriching-events/breadcrumbs/before-breadcrumb/dart.mdx index ae7ea313ce458..334731506d698 100644 --- a/platform-includes/enriching-events/breadcrumbs/before-breadcrumb/dart.mdx +++ b/platform-includes/enriching-events/breadcrumbs/before-breadcrumb/dart.mdx @@ -1,11 +1,7 @@ -```dart -import 'package:sentry/sentry.dart'; - -Breadcrumb? beforeBreadcrumb(Breadcrumb? breadcrumb, Hint hint) { - return 'a.spammy.Logger' == breadcrumb.category ? null : breadcrumb; -} - -Future main() async { - await Sentry.init((options) => options.beforeBreadcrumb = beforeBreadcrumb); -} +```dart {3} +await Sentry.init((options) { + options.beforeBreadcrumb = (breadcrumb, hint) { + return 'a.spammy.Logger' == breadcrumb.category ? null : breadcrumb; + }; +}); ``` diff --git a/platform-includes/enriching-events/breadcrumbs/before-breadcrumb/flutter.mdx b/platform-includes/enriching-events/breadcrumbs/before-breadcrumb/flutter.mdx new file mode 100644 index 0000000000000..adefceb4e8d55 --- /dev/null +++ b/platform-includes/enriching-events/breadcrumbs/before-breadcrumb/flutter.mdx @@ -0,0 +1,7 @@ +```dart {3} +await SentryFlutter.init((options) { + options.beforeBreadcrumb = (breadcrumb, hint) { + return 'a.spammy.Logger' == breadcrumb.category ? null : breadcrumb; + }; +}); +``` diff --git a/platform-includes/performance/configure-sample-rate/dart.mdx b/platform-includes/performance/configure-sample-rate/dart.mdx index 583bd9daacddf..6d3ee56846578 100644 --- a/platform-includes/performance/configure-sample-rate/dart.mdx +++ b/platform-includes/performance/configure-sample-rate/dart.mdx @@ -1,9 +1,5 @@ ```dart {diff} -import 'package:sentry/sentry.dart'; - -Sentry.init((options) => { - options.dsn = '___PUBLIC_DSN___'; - +Sentry.init((options) { + // To set a uniform sample rate + options.tracesSampleRate = 1.0; @@ -12,6 +8,6 @@ Sentry.init((options) => { + options.tracesSampler = (samplingContext) { + // return a number between 0 and 1 or null (to fallback + // to configured value) - }; ++ }; }); ``` diff --git a/platform-includes/performance/configure-sample-rate/flutter.mdx b/platform-includes/performance/configure-sample-rate/flutter.mdx index 3d8eb55278897..cc02a630cb122 100644 --- a/platform-includes/performance/configure-sample-rate/flutter.mdx +++ b/platform-includes/performance/configure-sample-rate/flutter.mdx @@ -1,21 +1,13 @@ ```dart {diff} -import 'package:flutter/widgets.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; +SentryFlutter.init((options) { ++ // To set a uniform sample rate ++ options.tracesSampleRate = 1.0; -SentryFlutter.init( - (options) => { - options.dsn = '___PUBLIC_DSN___'; - -+ // To set a uniform sample rate -+ options.tracesSampleRate = 1.0; - -+ // OR if you prefer, determine traces sample rate -+ // based on the sampling context -+ options.tracesSampler = (samplingContext) { -+ // return a number between 0 and 1 or null (to fallback -+ // to configured value) -+ }; - }, - appRunner: () => runApp(MyApp()), -); ++ // OR if you prefer, determine traces sample rate ++ // based on the sampling context ++ options.tracesSampler = (samplingContext) { ++ // return a number between 0 and 1 or null (to fallback ++ // to configured value) ++ }; +}); ``` diff --git a/platform-includes/performance/traces-sample-rate/dart.mdx b/platform-includes/performance/traces-sample-rate/dart.mdx index 92ed280abf06c..503edbc1206bc 100644 --- a/platform-includes/performance/traces-sample-rate/dart.mdx +++ b/platform-includes/performance/traces-sample-rate/dart.mdx @@ -1,7 +1,5 @@ -```dart -import 'package:sentry/sentry.dart'; - -Sentry.init((options) => { - options.tracesSampleRate = 0.2, - }); +```dart {2} +await Sentry.init((options) { + options.tracesSampleRate = 0.2; +}); ``` diff --git a/platform-includes/performance/traces-sample-rate/flutter.mdx b/platform-includes/performance/traces-sample-rate/flutter.mdx index 1fbd43f4cecac..0f6262fbdfe5e 100644 --- a/platform-includes/performance/traces-sample-rate/flutter.mdx +++ b/platform-includes/performance/traces-sample-rate/flutter.mdx @@ -1,11 +1,5 @@ -```dart -import 'package:flutter/widgets.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; - -SentryFlutter.init( - (options) => { - options.tracesSampleRate = 0.2; - }, - appRunner: () => runApp(MyApp()), -); +```dart {2} +await SentryFlutter.init((options) => { + options.tracesSampleRate = 0.2; +}); ``` diff --git a/platform-includes/performance/traces-sampler-as-filter/dart.mdx b/platform-includes/performance/traces-sampler-as-filter/dart.mdx index 44e05e56c2178..0421a61701387 100644 --- a/platform-includes/performance/traces-sampler-as-filter/dart.mdx +++ b/platform-includes/performance/traces-sampler-as-filter/dart.mdx @@ -1,26 +1,24 @@ ```dart -import 'package:sentry/sentry.dart'; +await Sentry.init((options) { + // Determine traces sample rate based on the sampling context + options.tracesSampler = (samplingContext) { + final ctx = samplingContext.customSamplingContext; + // If this is the continuation of a trace, just use that decision (rate controlled by the caller). + final parentSampled = + samplingContext.transactionContext.parentSampled; + if (parentSampled != null) { + return parentSampled ? 1.0 : 0.0; + } -Sentry.init((options) => { - // Determine traces sample rate based on the sampling context - options.tracesSampler = (samplingContext) { - final ctx = samplingContext.customSamplingContext; - // If this is the continuation of a trace, just use that decision (rate controlled by the caller). - final parentSampled = - samplingContext.transactionContext.parentSampled; - if (parentSampled != null) { - return parentSampled ? 1.0 : 0.0; - } - - if (/* make a decision based on `samplingContext` */) { - // Drop this transaction, by setting its sample rate to 0% - return 0.0; - } else if (/* ... */) { - // Override sample rate for other cases (replaces `options.TracesSampleRate`) - return 0.1; - } - // Can return `null` to fallback to the rate configured by `options.tracesSampleRate` - return null; - }, - }); + if (/* make a decision based on `samplingContext` */) { + // Drop this transaction, by setting its sample rate to 0% + return 0.0; + } else if (/* ... */) { + // Override sample rate for other cases (replaces `options.TracesSampleRate`) + return 0.1; + } + // Can return `null` to fallback to the rate configured by `options.tracesSampleRate` + return null; + }; +}); ``` diff --git a/platform-includes/performance/traces-sampler-as-filter/flutter.mdx b/platform-includes/performance/traces-sampler-as-filter/flutter.mdx index 7c1725c061932..2695322cfe723 100644 --- a/platform-includes/performance/traces-sampler-as-filter/flutter.mdx +++ b/platform-includes/performance/traces-sampler-as-filter/flutter.mdx @@ -1,30 +1,24 @@ ```dart -import 'package:flutter/widgets.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; +await SentryFlutter.init((options) { + // Determine traces sample rate based on the sampling context + options.tracesSampler = (samplingContext) { + final ctx = samplingContext.customSamplingContext; + // If this is the continuation of a trace, just use that decision (rate controlled by the caller). + final parentSampled = + samplingContext.transactionContext.parentSampled; + if (parentSampled != null) { + return parentSampled ? 1.0 : 0.0; + } -SentryFlutter.init( - (options) => { - // Determine traces sample rate based on the sampling context - options.tracesSampler = (samplingContext) { - final ctx = samplingContext.customSamplingContext; - // If this is the continuation of a trace, just use that decision (rate controlled by the caller). - final parentSampled = - samplingContext.transactionContext.parentSampled; - if (parentSampled != null) { - return parentSampled ? 1.0 : 0.0; - } - - if (/* make a decision based on `samplingContext` */) { - // Drop this transaction, by setting its sample rate to 0% - return 0.0; - } else if (/* ... */) { - // Override sample rate for other cases (replaces `options.TracesSampleRate`) - return 0.1; - } - // Can return `null` to fallback to the rate configured by `options.tracesSampleRate` - return null; - }, - }, - appRunner: () => runApp(MyApp()), -); + if (/* make a decision based on `samplingContext` */) { + // Drop this transaction, by setting its sample rate to 0% + return 0.0; + } else if (/* ... */) { + // Override sample rate for other cases (replaces `options.TracesSampleRate`) + return 0.1; + } + // Can return `null` to fallback to the rate configured by `options.tracesSampleRate` + return null; + }; +}); ``` diff --git a/platform-includes/performance/traces-sampler-as-sampler/dart.mdx b/platform-includes/performance/traces-sampler-as-sampler/dart.mdx index de0b003c30b0b..0cee6321597ec 100644 --- a/platform-includes/performance/traces-sampler-as-sampler/dart.mdx +++ b/platform-includes/performance/traces-sampler-as-sampler/dart.mdx @@ -1,30 +1,28 @@ ```dart -import 'package:sentry/sentry.dart'; +await Sentry.init((options) { + // Determine traces sample rate based on the sampling context + options.tracesSampler = (samplingContext) { + final ctx = samplingContext.customSamplingContext; + // If this is the continuation of a trace, just use that decision (rate controlled by the caller). + final parentSampled = + samplingContext.transactionContext.parentSampled; + if (parentSampled != null) { + return parentSampled ? 1.0 : 0.0; + } -Sentry.init((options) => { - // Determine traces sample rate based on the sampling context - options.tracesSampler = (samplingContext) { - final ctx = samplingContext.customSamplingContext; - // If this is the continuation of a trace, just use that decision (rate controlled by the caller). - final parentSampled = - samplingContext.transactionContext.parentSampled; - if (parentSampled != null) { - return parentSampled ? 1.0 : 0.0; - } - - if ('/payment' == ctx['url']) { - // These are important - take a big sample - return 0.5; - } else if ('/search' == ctx['url']) { - // Search is less important and happen much more frequently - only take 1% - return 0.01; - } else if ('/health' == ctx['url']) { - // The health check endpoint is just noise - drop all transactions - return 0.0; - } else { - // Default sample rate - return 0.1; - } - }, - }); + if ('/payment' == ctx['url']) { + // These are important - take a big sample + return 0.5; + } else if ('/search' == ctx['url']) { + // Search is less important and happen much more frequently - only take 1% + return 0.01; + } else if ('/health' == ctx['url']) { + // The health check endpoint is just noise - drop all transactions + return 0.0; + } else { + // Default sample rate + return 0.1; + } + }; +}); ``` diff --git a/platform-includes/performance/traces-sampler-as-sampler/flutter.mdx b/platform-includes/performance/traces-sampler-as-sampler/flutter.mdx index 6699fee7aac41..3473d23fc10af 100644 --- a/platform-includes/performance/traces-sampler-as-sampler/flutter.mdx +++ b/platform-includes/performance/traces-sampler-as-sampler/flutter.mdx @@ -1,34 +1,28 @@ ```dart -import 'package:flutter/widgets.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; +await SentryFlutter.init((options) { + // Determine traces sample rate based on the sampling context + options.tracesSampler = (samplingContext) { + final ctx = samplingContext.customSamplingContext; + // If this is the continuation of a trace, just use that decision (rate controlled by the caller). + final parentSampled = + samplingContext.transactionContext.parentSampled; + if (parentSampled != null) { + return parentSampled ? 1.0 : 0.0; + } -SentryFlutter.init( - (options) => { - // Determine traces sample rate based on the sampling context - options.tracesSampler = (samplingContext) { - final ctx = samplingContext.customSamplingContext; - // If this is the continuation of a trace, just use that decision (rate controlled by the caller). - final parentSampled = - samplingContext.transactionContext.parentSampled; - if (parentSampled != null) { - return parentSampled ? 1.0 : 0.0; - } - - if ('/payment' == ctx['url']) { - // These are important - take a big sample - return 0.5; - } else if ('/search' == ctx['url']) { - // Search is less important and happen much more frequently - only take 1% - return 0.01; - } else if ('/health' == ctx['url']) { - // The health check endpoint is just noise - drop all transactions - return 0.0; - } else { - // Default sample rate - return 0.1; - } - }, - }, - appRunner: () => runApp(MyApp()), -); + if ('/payment' == ctx['url']) { + // These are important - take a big sample + return 0.5; + } else if ('/search' == ctx['url']) { + // Search is less important and happen much more frequently - only take 1% + return 0.01; + } else if ('/health' == ctx['url']) { + // The health check endpoint is just noise - drop all transactions + return 0.0; + } else { + // Default sample rate + return 0.1; + } + }; +}); ``` diff --git a/platform-includes/set-environment/dart.mdx b/platform-includes/set-environment/dart.mdx index 9f965d8f01909..1588ccdf83ed5 100644 --- a/platform-includes/set-environment/dart.mdx +++ b/platform-includes/set-environment/dart.mdx @@ -1,7 +1,5 @@ -```dart -import 'package:sentry/sentry.dart'; - -Future main() async { - await Sentry.init((options) => options.environment = 'staging'); -} +```dart {2} +await Sentry.init((options) { + options.environment = 'staging'; +}); ``` diff --git a/platform-includes/set-environment/flutter.mdx b/platform-includes/set-environment/flutter.mdx index 3e5de8bd58c40..84c93fb454e5a 100644 --- a/platform-includes/set-environment/flutter.mdx +++ b/platform-includes/set-environment/flutter.mdx @@ -1,14 +1,7 @@ -```dart -import 'package:flutter/widgets.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; - -Future main() async { - await SentryFlutter.init( - (options) => options.environment = 'staging', - appRunner: () => runApp(MyApp()), - ); - - // or define SENTRY_ENVIRONMENT via Dart environment variable (--dart-define) -} +```dart {2} +await SentryFlutter.init((options) { + options.environment = 'staging'; +}); +// or define SENTRY_ENVIRONMENT via Dart environment variable (--dart-define) ``` diff --git a/platform-includes/set-fingerprint/basic/dart.mdx b/platform-includes/set-fingerprint/basic/dart.mdx index 426cd8c042480..4f62cfb37fa97 100644 --- a/platform-includes/set-fingerprint/basic/dart.mdx +++ b/platform-includes/set-fingerprint/basic/dart.mdx @@ -1,14 +1,10 @@ -```dart -import 'package:sentry/sentry.dart'; - -FutureOr beforeSend(SentryEvent event, Hint hint) async { - if (event.throwable is DatabaseException) { - event = event.copyWith(fingerprint: ['database-connection-error']); - } - return event; -} - -Future main() async { - await Sentry.init((options) => options.beforeSend = beforeSend); -} +```dart {3-6} +await Sentry.init((options) { + options.beforeSend = (event, hint) { + if (event.throwable is DatabaseException) { + event = event.copyWith(fingerprint: ['database-connection-error']); + } + return event; + }; +}); ``` diff --git a/platform-includes/set-fingerprint/basic/flutter.mdx b/platform-includes/set-fingerprint/basic/flutter.mdx new file mode 100644 index 0000000000000..459286e11c4fa --- /dev/null +++ b/platform-includes/set-fingerprint/basic/flutter.mdx @@ -0,0 +1,10 @@ +```dart {3-6} +await SentryFlutter.init((options) { + options.beforeSend = (event, hint) { + if (event.throwable is DatabaseException) { + event = event.copyWith(fingerprint: ['database-connection-error']); + } + return event; + }; +}); +``` diff --git a/platform-includes/set-fingerprint/database-connection/dart.mdx b/platform-includes/set-fingerprint/database-connection/dart.mdx index 426cd8c042480..4f62cfb37fa97 100644 --- a/platform-includes/set-fingerprint/database-connection/dart.mdx +++ b/platform-includes/set-fingerprint/database-connection/dart.mdx @@ -1,14 +1,10 @@ -```dart -import 'package:sentry/sentry.dart'; - -FutureOr beforeSend(SentryEvent event, Hint hint) async { - if (event.throwable is DatabaseException) { - event = event.copyWith(fingerprint: ['database-connection-error']); - } - return event; -} - -Future main() async { - await Sentry.init((options) => options.beforeSend = beforeSend); -} +```dart {3-6} +await Sentry.init((options) { + options.beforeSend = (event, hint) { + if (event.throwable is DatabaseException) { + event = event.copyWith(fingerprint: ['database-connection-error']); + } + return event; + }; +}); ``` diff --git a/platform-includes/set-fingerprint/database-connection/flutter.mdx b/platform-includes/set-fingerprint/database-connection/flutter.mdx new file mode 100644 index 0000000000000..459286e11c4fa --- /dev/null +++ b/platform-includes/set-fingerprint/database-connection/flutter.mdx @@ -0,0 +1,10 @@ +```dart {3-6} +await SentryFlutter.init((options) { + options.beforeSend = (event, hint) { + if (event.throwable is DatabaseException) { + event = event.copyWith(fingerprint: ['database-connection-error']); + } + return event; + }; +}); +``` diff --git a/platform-includes/set-fingerprint/rpc/dart.mdx b/platform-includes/set-fingerprint/rpc/dart.mdx index affec0eb261f3..c6ee6506e1f50 100644 --- a/platform-includes/set-fingerprint/rpc/dart.mdx +++ b/platform-includes/set-fingerprint/rpc/dart.mdx @@ -1,6 +1,4 @@ ```dart -import 'package:sentry/sentry.dart'; - class MyRpcException implements Exception { final String function; final int httpStatusCode; @@ -8,19 +6,17 @@ class MyRpcException implements Exception { MyRpcException(this.function, this.httpStatusCode); } -FutureOr beforeSend(SentryEvent event, Hint hint) async { - if (event.throwable is MyRpcException) { - final exception = event.throwable as MyRpcException; - event = event.copyWith(fingerprint: [ - '{{ default }}', - exception.function, - exception.httpStatusCode.toString(), - ]); - } - return event; -} - -Future main() async { - await Sentry.init((options) => options.beforeSend = beforeSend); -} +await Sentry.init((options) { + options.beforeSend = (event, hint) { + if (event.throwable is MyRpcException) { + final exception = event.throwable as MyRpcException; + event = event.copyWith(fingerprint: [ + '{{ default }}', + exception.function, + exception.httpStatusCode.toString(), + ]); + } + return event; + }; +}); ``` diff --git a/platform-includes/set-fingerprint/rpc/flutter.mdx b/platform-includes/set-fingerprint/rpc/flutter.mdx new file mode 100644 index 0000000000000..8a57b424423f6 --- /dev/null +++ b/platform-includes/set-fingerprint/rpc/flutter.mdx @@ -0,0 +1,22 @@ +```dart +class MyRpcException implements Exception { + final String function; + final int httpStatusCode; + + MyRpcException(this.function, this.httpStatusCode); +} + +await SentryFlutter.init((options) { + options.beforeSend = (event, hint) { + if (event.throwable is MyRpcException) { + final exception = event.throwable as MyRpcException; + event = event.copyWith(fingerprint: [ + '{{ default }}', + exception.function, + exception.httpStatusCode.toString(), + ]); + } + return event; + }; +}); +``` diff --git a/platform-includes/set-release/dart.mdx b/platform-includes/set-release/dart.mdx index 8737cf7f9a37d..eb76ef34f4c65 100644 --- a/platform-includes/set-release/dart.mdx +++ b/platform-includes/set-release/dart.mdx @@ -1,7 +1,6 @@ -```dart -import 'package:sentry/sentry.dart'; - -Future main() async { - await Sentry.init((options) => options.release = 'my-project-name@2.3.12+12'); // packageName@versionName+buildNumber -} +```dart {3} +await Sentry.init((options) { + // packageName@versionName+buildNumber + options.release = 'my-project-name@2.3.12+12'; +}); ``` diff --git a/platform-includes/set-release/flutter.mdx b/platform-includes/set-release/flutter.mdx index 155b633bffc87..295a526725e09 100644 --- a/platform-includes/set-release/flutter.mdx +++ b/platform-includes/set-release/flutter.mdx @@ -1,15 +1,9 @@ ```dart -import 'package:flutter/widgets.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; +await SentryFlutter.init((options) { + options.release = 'my-project-name@2.3.12+12'; +}); -Future main() async { - await SentryFlutter.init( - (options) => options.release = 'my-project-name@2.3.12+12', - appRunner: () => runApp(MyApp()), - ); - - // or define SENTRY_RELEASE via Dart environment variable (--dart-define) if you are using Flutter Web. -} +// or define SENTRY_RELEASE via Dart environment variable (--dart-define) if you are using Flutter Web. ``` diff --git a/platform-includes/user-feedback/sdk-api-example/dart.mdx b/platform-includes/user-feedback/sdk-api-example/dart.mdx index 1dcee4d8d8d15..7a4c58c6f8271 100644 --- a/platform-includes/user-feedback/sdk-api-example/dart.mdx +++ b/platform-includes/user-feedback/sdk-api-example/dart.mdx @@ -1,11 +1,9 @@ ```dart -import 'package:sentry/sentry.dart'; - // Option 1: Retrieving SentryId from beforeSend SentryId sentryId = SentryId.empty(); await Sentry.init((options) { - options.beforeSend = (event, hint) async { + options.beforeSend = (event, hint) { sentryId = event.eventId; return event; }; diff --git a/platform-includes/user-feedback/sdk-api-example/flutter.mdx b/platform-includes/user-feedback/sdk-api-example/flutter.mdx new file mode 100644 index 0000000000000..a3ee42c324e9a --- /dev/null +++ b/platform-includes/user-feedback/sdk-api-example/flutter.mdx @@ -0,0 +1,26 @@ +```dart +// Option 1: Retrieving SentryId from beforeSend +SentryId sentryId = SentryId.empty(); + +await SentryFlutter.init((options) { + options.beforeSend = (event, hint) { + sentryId = event.eventId; + return event; + }; +}); + +// Option 2: Retrieving SentryId from the method capturing the event +SentryId sentryId = Sentry.captureMessage("My message"); + +// Option 3: Retrieving SentryId from the beforeSend callback +SentryId sentryId = Sentry.lastEventId; + +final userFeedback = SentryUserFeedback( + eventId: sentryId, + comments: 'Hello World!', + email: 'foo@bar.org', + name: 'John Doe', +); + +Sentry.captureUserFeedback(userFeedback); +```