Skip to content

Commit

Permalink
docs(flutter): Use sentry flutter init in samples (#11858)
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase authored Nov 26, 2024
1 parent 4792cc9 commit 69bd829
Show file tree
Hide file tree
Showing 42 changed files with 351 additions and 365 deletions.
16 changes: 4 additions & 12 deletions docs/platforms/dart/integrations/dio.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,10 @@ final response = await dio.get<String>('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<void> 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
Expand Down
13 changes: 5 additions & 8 deletions docs/platforms/flutter/session-replay/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,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
Expand Down
16 changes: 4 additions & 12 deletions platform-includes/configuration/allow-urls/dart.mdx
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
```dart
import 'package:sentry/sentry.dart';
Future<void> 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"];
});
```
5 changes: 5 additions & 0 deletions platform-includes/configuration/allow-urls/flutter.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```dart {2}
await SentryFlutter.init((options) {
options.allowUrls = ["^https://sentry.com.*\$", "my-custom-domain"];
});
```
16 changes: 6 additions & 10 deletions platform-includes/configuration/before-breadcrumb-hint/dart.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
```dart
import 'package:sentry/sentry.dart';
Breadcrumb? beforeBreadcrumb(Breadcrumb? breadcrumb, Hint hint) {
return hint is MyHint ? null : crumb;
}
Future<void> 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;
};
});
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```dart {3}
await SentryFlutter.init((options) {
options.beforeBreadcrumb = (breadcrumb, hint) {
return hint is MyHint ? null : crumb;
};
});
```
22 changes: 9 additions & 13 deletions platform-includes/configuration/before-send-fingerprint/dart.mdx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
```dart
import 'package:sentry/sentry.dart';
FutureOr<SentryEvent?> beforeSend(SentryEvent event, Hint hint) async {
if (event.throwable is DatabaseException) {
event = event.copyWith(fingerprint: ['database-connection-error']);
}
return event;
}
Future<void> 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;
};
});
```
Original file line number Diff line number Diff line change
@@ -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;
};
});
```
16 changes: 6 additions & 10 deletions platform-includes/configuration/before-send-hint/dart.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
```dart
import 'package:sentry/sentry.dart';
FutureOr<SentryEvent?> beforeSend(SentryEvent event, Hint hint) async {
return hint is MyHint ? null : event;
}
Future<void> 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;
};
});
```
7 changes: 7 additions & 0 deletions platform-includes/configuration/before-send-hint/flutter.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```dart {3}
await SentryFlutter.init((options) {
options.beforeSend = (event, hint) {
return hint is MyHint ? null : event;
};
});
```
18 changes: 6 additions & 12 deletions platform-includes/configuration/before-send/dart.mdx
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
```dart
import 'package:sentry/sentry.dart';
FutureOr<SentryEvent?> beforeSend(SentryEvent event, Hint hint) async {
// Modify the event here:
event = event.copyWith(serverName: null); // Don't send server names.
return event;
}
Future<void> 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.
};
});
```
7 changes: 7 additions & 0 deletions platform-includes/configuration/before-send/flutter.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```dart {3}
await SentryFlutter.init((options) {
options.beforeSend = (event, hint) {
return event.copyWith(serverName: null); // Don't send server names.
};
});
```
16 changes: 4 additions & 12 deletions platform-includes/configuration/deny-urls/dart.mdx
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
```dart
import 'package:sentry/sentry.dart';
Future<void> 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"];
});
```
5 changes: 5 additions & 0 deletions platform-includes/configuration/deny-urls/flutter.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```dart {2}
await SentryFlutter.init((options) {
options.denyUrls = ["^.*ends-with-this\$", "denied-url"];
});
```
13 changes: 4 additions & 9 deletions platform-includes/configuration/ignore-errors/dart.mdx
Original file line number Diff line number Diff line change
@@ -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-.*\$"];
});
```
13 changes: 4 additions & 9 deletions platform-includes/configuration/ignore-transactions/dart.mdx
Original file line number Diff line number Diff line change
@@ -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-.*\$" ];
});
```
10 changes: 4 additions & 6 deletions platform-includes/configuration/sample-rate/dart.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
```dart
import 'package:sentry/sentry.dart';
Future<void> 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;
});
```
6 changes: 6 additions & 0 deletions platform-includes/configuration/sample-rate/flutter.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```dart {3}
await SentryFlutter.init((options) {
// Capture only 25% of events
options.sampleRate = 0.25;
});
```
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
```dart
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> 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;
});
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import 'package:sentry/sentry.dart';
final attachment = SentryAttachment.fromByteData(bytedata);
Sentry.configureScope((scope) {
scope.addAttachment(attachment);
scope.addAttachment(attachment);
});
```
Original file line number Diff line number Diff line change
@@ -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<void> 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;
};
});
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```dart {3}
await SentryFlutter.init((options) {
options.beforeBreadcrumb = (breadcrumb, hint) {
return 'a.spammy.Logger' == breadcrumb.category ? null : breadcrumb;
};
});
```
8 changes: 2 additions & 6 deletions platform-includes/performance/configure-sample-rate/dart.mdx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,6 +8,6 @@ Sentry.init((options) => {
+ options.tracesSampler = (samplingContext) {
+ // return a number between 0 and 1 or null (to fallback
+ // to configured value)
};
+ };
});
```
28 changes: 10 additions & 18 deletions platform-includes/performance/configure-sample-rate/flutter.mdx
Original file line number Diff line number Diff line change
@@ -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)
+ };
});
```
10 changes: 4 additions & 6 deletions platform-includes/performance/traces-sample-rate/dart.mdx
Original file line number Diff line number Diff line change
@@ -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;
});
```
14 changes: 4 additions & 10 deletions platform-includes/performance/traces-sample-rate/flutter.mdx
Original file line number Diff line number Diff line change
@@ -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;
});
```
Loading

0 comments on commit 69bd829

Please sign in to comment.