Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 68 additions & 41 deletions docs/platforms/dart/common/index.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Dart
description: Learn how to set up Sentry in your Dart app, capture your first errors and traces, and view them in Sentry.
description: Learn how to set up Sentry in your Dart app, capture your first events, and view them in Sentry.
caseStyle: camelCase
supportLevel: production
sdk: sentry.dart
Expand Down Expand Up @@ -33,50 +33,92 @@ dependencies:

## Configure

Choose the features you want to configure, and this guide will show you how:

<OnboardingOptionButtons options={["error-monitoring", "performance"]} />
Initialize **Error Monitoring** with `Sentry.init()` and run your application in its `appRunner` callback to capture uncaught exceptions and unhandled asynchronous errors. **Logs** and **Application Metrics** are enabled by default in SDK v10, and you'll learn how to send them in steps [#3](#send-logs) and [#4](#send-application-metrics-).
This guide also enables **Tracing**.

<Include name="quick-start-features-expandable" />

### Initialize the Sentry SDK

Configuration should happen as **early as possible** in your application's lifecycle.

Import and initialize the SDK in your app's entry point:
Import and initialize the SDK in your app's entry point as shown in the code snippet below.

The snippet also turns on:

- Tracing: via <PlatformLink to="/configuration/options/#tracesSampleRate">`tracesSampleRate`</PlatformLink>
- Additional user and request data: via <PlatformLink to="/configuration/options/#sendDefaultPii">`sendDefaultPii`</PlatformLink>

To skip tracing, omit `tracesSampleRate`. To discard logs or metrics, return `null` from <PlatformLink to="/logs/#beforesendlog">`beforeSendLog`</PlatformLink> or <PlatformLink to="/metrics/#beforesendmetric">`beforeSendMetric`</PlatformLink>.

```dart
import 'package:sentry/sentry.dart';

Future<void> main() async {
await Sentry.init((options) {
options.dsn = '___PUBLIC_DSN___';
// Adds request headers and IP for users, for more info visit:
// https://docs.sentry.io/platforms/dart/data-management/data-collected/
options.sendDefaultPii = true;
// ___PRODUCT_OPTION_START___ performance
// Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
// We recommend adjusting this value in production.
options.tracesSampleRate = 1.0;
// ___PRODUCT_OPTION_END___ performance
});

// you can also configure SENTRY_DSN, SENTRY_RELEASE, SENTRY_DIST, and
// SENTRY_ENVIRONMENT via Dart environment variable (--dart-define)
await Sentry.init(
(options) {
options.dsn = '___PUBLIC_DSN___';

// Allows sending default personal data, such as IP addresses,
// when available from the SDK's integrations.
options.sendDefaultPii = true;

// Enables Tracing.
// Set to 1.0 to capture 100% of spans for tracing.
// We recommend reducing this value in production.
options.tracesSampleRate = 1.0;
},
appRunner: () async {
// Start your application here.
},
);

// You can also configure SENTRY_DSN, SENTRY_RELEASE, SENTRY_DIST, and
// SENTRY_ENVIRONMENT via Dart environment variables (--dart-define).
}
```

## Verify Your Setup
The `appRunner` callback runs in a guarded error zone. This is required for automatic error capture on Dart web, where isolate error listeners are unavailable. For additional isolates, register an error listener with [`addSentryErrorListener`](https://pub.dev/documentation/sentry/latest/sentry_io/SentryIsolateExtension/addSentryErrorListener.html) from `package:sentry/sentry_io.dart`.

Let's test your setup and confirm that data reaches your Sentry project.
For finite command-line applications, call `await Sentry.close()` after all awaited application work finishes to flush buffered telemetry and close SDK resources, including the isolate error-listener port.

### Issues
## Send Logs

To verify that Sentry captures errors and creates issues in your Sentry project, add this intentional error to your application:
Call `Sentry.logger` from your application code after initialization to send structured logs at different levels. You can add attributes to make logs easier to search and filter.

See <PlatformLink to="/logs/">Set Up Logs</PlatformLink> for all available logging methods and message formatting.

```dart
import 'package:sentry/sentry.dart';
Sentry.logger.info('Order completed', attributes: {
'order_id': SentryAttribute.string('12345'),
'total': SentryAttribute.double(99.99),
});

Sentry.logger.warn('Slow operation detected');
Sentry.logger.error('Validation failed');
```

If you use the Dart `logging` package, add the <PlatformLink to="/integrations/logging/">`sentry_logging` integration</PlatformLink> to send its records to Sentry.

## Send Application Metrics <FeatureBadge type="new" />

Call `Sentry.metrics` from your application code after initialization to send counters, gauges, and distributions. Add attributes to filter and group metrics in Sentry.

See <PlatformLink to="/metrics/">Set Up Metrics</PlatformLink> for metric types, attributes, and configuration options.

```dart
Sentry.metrics.count('checkout.failed', 1);
Sentry.metrics.gauge('queue.depth', 42);
Sentry.metrics.distribution('api_latency', 187, unit: 'millisecond');
```

## Verify Your Setup

Let's test your setup and confirm that data reaches your Sentry project.

Add this inside the async `appRunner` callback to trigger and capture a test error:

```dart
try {
throw StateError('Sentry Test Error');
} catch (exception, stackTrace) {
Expand All @@ -87,16 +129,6 @@ try {
}
```

<OnboardingOption optionId="performance">

<Include name="tracing/dart-quick-start-verify-tracing-splitlayout.mdx" />

</OnboardingOption>

<Include name="logs/dart-quick-start-verify-logs-splitlayout.mdx" />

<Include name="metrics/dart-quick-start-verify-metrics-splitlayout.mdx" />

### View Captured Data in Sentry

Now, head over to your project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear).
Expand All @@ -105,16 +137,11 @@ Now, head over to your project on [Sentry.io](https://sentry.io) to view the col

## Next Steps

At this point, you should have integrated Sentry into your Dart application and should already be sending data to your Sentry project.

Now's a good time to customize your setup and look into more advanced topics.
Our next recommended steps for you are:
At this point, you should have integrated Sentry into your Dart application. Here's what to explore next:

- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup
- Continue to <PlatformLink to="/configuration/">customize your configuration</PlatformLink>
- Learn more about <PlatformLink to="/usage/">manually capturing errors or messages</PlatformLink>
- Learn about the <PlatformLink to="/features/">features of Sentry's Dart SDK</PlatformLink>
- Add <PlatformLink to="/tracing/instrumentation/">performance instrumentation to your app</PlatformLink>
- Add <PlatformLink to="/tracing/instrumentation/">performance instrumentation</PlatformLink> to your app

<Expandable permalink={false} title="Are you having problems setting up the SDK?">

Expand Down
72 changes: 39 additions & 33 deletions docs/platforms/dart/guides/flutter/index.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Flutter
description: Learn how to set up Sentry in your Flutter app, capture your first errors and traces, and view them in Sentry.
description: Learn how to set up Sentry in your Flutter app, capture your first events, and view them in Sentry.
caseStyle: camelCase
supportLevel: production
sdk: sentry.dart.flutter
Expand Down Expand Up @@ -28,34 +28,34 @@ brew install getsentry/tools/sentry-wizard && sentry-wizard -i flutter
```

```powershell {tabTitle:Windows}
$downloadUrl = "https://github.com/getsentry/sentry-wizard/releases/download/v5.1.0/sentry-wizard-win-x64.exe"
$downloadUrl = "https://github.com/getsentry/sentry-wizard/releases/download/v9.1.0/sentry-wizard-win-x64.exe"
Invoke-WebRequest $downloadUrl -OutFile sentry-wizard.exe
./sentry-wizard.exe -i flutter
```

```bash {tabTitle:macOS (Intel/x64)}
downloadUrl="https://github.com/getsentry/sentry-wizard/releases/download/v5.1.0/sentry-wizard-darwin-x64"
downloadUrl="https://github.com/getsentry/sentry-wizard/releases/download/v9.1.0/sentry-wizard-darwin-x64"
curl -L $downloadUrl -o sentry-wizard
chmod +x sentry-wizard
./sentry-wizard -i flutter
```

```bash {tabTitle:macOS (Apple Silicon/arm64)}
downloadUrl="https://github.com/getsentry/sentry-wizard/releases/download/v5.1.0/sentry-wizard-darwin-arm64"
downloadUrl="https://github.com/getsentry/sentry-wizard/releases/download/v9.1.0/sentry-wizard-darwin-arm64"
curl -L $downloadUrl -o sentry-wizard
chmod +x sentry-wizard
./sentry-wizard -i flutter
```

```bash {tabTitle:Linux (x64)}
downloadUrl="https://github.com/getsentry/sentry-wizard/releases/download/v5.1.0/sentry-wizard-linux-x64"
downloadUrl="https://github.com/getsentry/sentry-wizard/releases/download/v9.1.0/sentry-wizard-linux-x64"
curl -L $downloadUrl -o sentry-wizard
chmod +x sentry-wizard
./sentry-wizard -i flutter
```

```bash {tabTitle:Linux (arm64)}
downloadUrl="https://github.com/getsentry/sentry-wizard/releases/download/v5.1.0/sentry-wizard-linux-arm64"
downloadUrl="https://github.com/getsentry/sentry-wizard/releases/download/v9.1.0/sentry-wizard-linux-arm64"
curl -L $downloadUrl -o sentry-wizard
chmod +x sentry-wizard
./sentry-wizard -i flutter
Expand All @@ -65,7 +65,7 @@ chmod +x sentry-wizard
npx @sentry/wizard@latest -i flutter
```

This will patch your project and configure the SDK. You only need to patch the project once, then you can add the patched files to your version control system.
This will patch your project and configure the SDK. **Logs** and **Application Metrics** are enabled by default in SDK v10, and you'll learn how to send them in steps [#2](#send-logs) and [#3](#send-application-metrics-). You only need to patch the project once, then you can add the patched files to your version control system.
If you prefer, you can also [set up the SDK manually](/platforms/dart/guides/flutter/manual-setup/).

<Expandable title="The following tasks will be performed by the Sentry Wizard">
Expand All @@ -77,37 +77,47 @@ If you prefer, you can also [set up the SDK manually](/platforms/dart/guides/flu

</Expandable>

The wizard will prompt you to enable optional features. Select the same options here so this guide can show you how to verify them:
## Send Logs

<OnboardingOptionButtons
options={["error-monitoring", "performance", "session-replay"]}
/>
Call `Sentry.logger` from your application code after initialization to send structured logs at different levels. You can add attributes to make logs easier to search and filter.

<Include name="quick-start-features-expandable" />
See <PlatformLink to="/logs/">Set Up Logs</PlatformLink> for all available logging methods and message formatting.

## Verify Your Setup
```dart
Sentry.logger.info('Order completed', attributes: {
'order_id': SentryAttribute.string('12345'),
'total': SentryAttribute.double(99.99),
});

Let's test your setup and confirm that data reaches your Sentry project.
Sentry.logger.warn('Slow operation detected');
Sentry.logger.error('Validation failed');
```

### Issues
If you use the Dart `logging` package, add the <PlatformLink to="/integrations/logging/">`sentry_logging` integration</PlatformLink> to send its records to Sentry.

The wizard added a sample exception to `main.dart` that is captured when the app starts. Run your app to send it to Sentry:
## Send Application Metrics <FeatureBadge type="new" />

```bash
flutter run
```
Call `Sentry.metrics` from your application code after initialization to send counters, gauges, and distributions. Add attributes to filter and group metrics in Sentry.

After you've confirmed the issue in Sentry, remove the sample exception from `main.dart` so it isn't captured on every launch.
See <PlatformLink to="/metrics/">Set Up Metrics</PlatformLink> for metric types, attributes, and configuration options.

```dart
Sentry.metrics.count('checkout.failed', 1);
Sentry.metrics.gauge('queue.depth', 42);
Sentry.metrics.distribution('api_latency', 187, unit: 'millisecond');
```

<OnboardingOption optionId="performance">
## Verify Your Setup

<Include name="tracing/dart-quick-start-verify-tracing-splitlayout.mdx" />
Let's test your setup and confirm that data reaches your Sentry project.

</OnboardingOption>
The wizard added a sample exception to main.dart that is captured when the app starts. Run your app to send it to Sentry:

<Include name="logs/dart-quick-start-verify-logs-splitlayout.mdx" />
```bash
flutter run
```

<Include name="metrics/dart-quick-start-verify-metrics-splitlayout.mdx" />
After you've confirmed the issue in Sentry, remove the sample exception from `main.dart` so it isn't captured on every launch.

### View Captured Data in Sentry

Expand All @@ -117,16 +127,12 @@ Now, head over to your project on [Sentry.io](https://sentry.io) to view the col

## Next Steps

At this point, you should have integrated Sentry into your Flutter application and should already be sending data to your Sentry project.

Now's a good time to customize your setup and look into more advanced topics.
Our next recommended steps for you are:
At this point, you should have integrated Sentry into your Flutter application. Here's what to explore next:

- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup
- Continue to <PlatformLink to="/configuration/">customize your configuration</PlatformLink>
- Add readable <PlatformLink to="/debug-symbols/#when-to-upload-debug-symbols">stack traces</PlatformLink> to errors
- Learn about the <PlatformLink to="/features/">features of Sentry's Flutter SDK</PlatformLink>
- Add <PlatformLink to="/tracing/instrumentation/">performance instrumentation to your app</PlatformLink>
- Upload <PlatformLink to="/debug-symbols/">debug symbols and source maps</PlatformLink> for readable production stack traces. The wizard configures `sentry_dart_plugin`; run `dart run sentry_dart_plugin` after each production build to upload the files. In CI, provide `SENTRY_AUTH_TOKEN` to the upload step.
- Learn about <PlatformLink to="/session-replay/">Session Replay</PlatformLink> and its privacy controls
- Add <PlatformLink to="/tracing/instrumentation/">performance instrumentation</PlatformLink> to your app

<Expandable permalink={false} title="Are you having problems setting up the SDK?">

Expand Down
Loading
Loading