iamantoniodinuzzo/claude-flutter/sentry-init

Claude Code and agent skill by iamantoniodinuzzo/claude-flutter

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Bootstrap sentry_flutter in a Flutter+Riverpod+GoRouter project — installs deps, wires SentryFlutter.init (Approach 3), GoRouter observer, Riverpod error capture (LoggerService decorator if present, else a scaffolded ErrorLogger sink), web BetterFeedback gated by CanvasKit renderer, beforeSend/sampling policy, and a release upload checklist (source maps + dSYM). Use when the user says \"add Sentry to this app\", \"set up error monitoring\", \"bootstrap sentry-init\", \"integrate crash reporting\", or asks to wire up Sentry for a Flutter/Riverpod/GoRouter project.

Install

npx vskill@latest install iamantoniodinuzzo/claude-flutter/sentry-init

SKILL.md

The same SKILL.md was published earlier as iamantoniodinuzzo/claude-flutter/sentry-init.

sentry-init

Runtime and resources

Use the current agent's native file, search, shell, and question tools; plain-text questions and direct sequential scans are valid fallbacks. Subagents are optional and require host permission. Bundled paths below are relative to this installed skill directory; application paths are relative to the target Flutter project. Resolve sibling skills through the installed skill registry (or sibling directories), never by assuming a skills/ folder in the application. If a required dependency is absent, name it and report the affected step as unavailable; never invent its rules or claim complete coverage.

Bootstraps the Sentry Flutter SDK in an existing Flutter project that uses Riverpod and GoRouter. Run all phases in order; each phase is idempotent — if the target already has partial Sentry setup, report deltas only, do not duplicate.

Before coding anything, load the bundled references in parallel:

  • references/initialization-flow.md
  • references/error-capture-architecture.md
  • references/event-filtering-and-sampling.md
  • references/gorouter-and-dio-wiring.md
  • references/web-feedback-canvaskit.md
  • references/release-uploads.md

Also fetch the latest sentry_flutter SDK docs via context7 (getsentry/sentry-dart) before pinning any version numbers — the reference files cite minimum-tested baselines, not pinned versions.


Phase 0 — Intake & prerequisite gate

Goal: gather all project shape facts before touching any file. Never assume — detect.

Prerequisite: a Sentry account and project must already exist (sentry.io → Create Project → platform Flutter). This skill wires the SDK into the app; it does not create or configure anything on Sentry's side.

0.1 Melos workspace detection

Grep root pubspec.yaml for workspace: (pub workspaces) or melos: block.

  • Monorepo detected: ask the user which package(s) to target. All subsequent phases apply to the selected package root. Use melos exec --scope=<pkg> -- <cmd> for pub operations.
  • Single-app: target root is the project root.
0.2 GoRouter prerequisite (hard gate)

In the target pubspec.yaml, grep for go_router.

  • Not found: abort immediately with this message:

`` ✗ sentry-init requires go_router for NavigatorObserver wiring. Run the flutter-go-router skill first, then re-run sentry-init. ``

  • Found: proceed.
0.3 Error sink detection (soft)

Grep project lib/ for:

  • class LoggerService or abstract.*LoggerService
  • loggerServiceProvider

Record result as HAS_LOGGER_SERVICE=true/false and derive the sink identity Phase 4 wires everything through — LoggerService decorator and a scaffolded ErrorLogger are both sinks (something a caller hands an error to); ProviderObserver is a channel (where errors arrive from), not a competing sink:

HAS_LOGGER_SERVICESINK_PROVIDERSINK_CAPTURE call shape
trueloggerServiceProvidersink.e(msg, error, stackTrace) — takes a message
falseerrorLoggerProvidersink.logException(error, stackTrace) — no message

The two shapes are not interchangeable — Branch A's .e(...) always takes a leading message string, Branch B's .logException(...) never does. Use the row matching the detected branch verbatim; don't average the two signatures.

0.4 Optional dependency detection
ProbeGrep targetVariable
Dioimport 'package:dio/dio.dart' or dio: in pubspecHAS_DIO
logging packagelogging: in pubspecHAS_LOGGING
Existing Sentrysentry_flutter in pubspecALREADY_HAS_SENTRY

If ALREADY_HAS_SENTRY=true, proceed but operate in delta mode: report what already exists vs what needs changing.

0.5 DSN source

Ask the user how the DSN is provided. Present this priority order as default:

  1. dart_defines.json / dart_defines.json.example (key SENTRY_DSN) — recommended, compile-time, never committed
  2. --dart-define=SENTRY_DSN=... in .vscode/launch.json or Makefile
  3. .env file read at runtime

dart_defines.json is the default because it's validated prior art (see this repo's docs/adr/0001-sentry-init-dsn-source-convention.md), not a guess — a single shared file beats one .env per flavor for a toolkit that has no other skill scaffolding .env files. If the target project already uses .env-per-flavor, detect and adapt to it instead of migrating it.

Confirm the exact key name (default SENTRY_DSN). In Phase 2, the skill always emits an empty-string gate so local dev without the define simply skips Sentry init.

Determine how the value is accessed in Dart (e.g. const String.fromEnvironment('SENTRY_DSN') or via an AppEnv/Env class). Record as DSN_DART_EXPR.

0.6 Flavor detection

Grep for lib/main_*.dart or a Flavor / AppFlavor enum. List discovered flavors.

Performance monitoring is opt-in, default off. sentry-init bootstraps error monitoring; tracesSampleRate/profilesSampleRate open two additional Sentry quota buckets (spans, profiling) the course itself doesn't enable by default (see references/event-filtering-and-sampling.md). Ask the user whether to enable it. If yes, map flavors to this table — profilesSampleRate is relative to tracesSampleRate, not independent, so the values below are chosen for the stated effective rate, not copied 1:1:

FlavortracesSampleRateprofilesSampleRate (relative)effective profiling
prod / release0.21.00.2
dev / debug / staging1.01.01.0

profilesSampleRate only does anything on iOS/macOS — Sentry doesn't support profiling on Android or Web yet. tracesSampleRate still applies everywhere. If the target is Android-only or web-only, mention this before asking — the profiling half of the table is a no-op there.

Ask the user to confirm or adjust. If declined, record PERF_MONITORING=false and omit both options entirely in Phase 2 — leaving them unset consumes zero span/profile quota (both default to null in the SDK).

0.7 Package name

Grep pubspec.yaml for name:. Record as APP_PACKAGE_NAME — used for addInAppInclude.

Phase 0 summary

Before proceeding, print a one-line summary of what was detected:

✓ Target: <package>
✓ go_router: found
✓ LoggerService: <found|not found> → Phase 4 will use <Branch A|Branch B>
✓ Dio: <found|not found>
✓ DSN key: <SENTRY_DSN> via <dart_defines.json|launch.json|.env>
✓ Flavors: <list>
✓ Performance monitoring: <on|off>
✓ Package name: <name>

Ask the user to confirm before proceeding.


Phase 1 — Install dependencies

1.1 Core
bash
flutter pub add sentry_flutter
flutter pub add --dev sentry_dart_plugin

For monorepo: prefix with melos exec --scope=<pkg> -- .

Minimum-tested baseline versions (verify current latest via context7 before pinning):

  • sentry_flutter: ^9.20.0
  • sentry_dart_plugin: 3.2.0
1.2 Conditional additions
ConditionCommand
HAS_DIO=trueflutter pub add sentry_dio
HAS_LOGGING=trueflutter pub add sentry_logging
Always (for web BetterFeedback)flutter pub add feedback feedback_sentry

Minimum-tested baselines: feedback: ^3.2.0, feedback_sentry: ^3.2.0.


Phase 2 — Patch main.dart (Approach 3 — no appRunner)

See references/initialization-flow.md for full rationale and comparison of all three approaches.

2.1 Locate entrypoints

Find all flavor entrypoints: lib/main.dart, lib/main_dev.dart, lib/main_prod.dart, etc. (from Phase 0.6). Apply this phase to each.

2.2 Required initialization order
dart
const kDebugReporting = bool.fromEnvironment('SENTRY_DEBUG_REPORTING');
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// --- existing pre-Sentry init (preserve as-is) ---
// e.g. Firebase.initializeApp(...), usePathUrlStrategy(), setupEmulators()
// --- Sentry init ---
final dsn = DSN_DART_EXPR; // e.g. const String.fromEnvironment('SENTRY_DSN')
if (dsn.isNotEmpty) {
await SentryFlutter.init((options) {
options.dsn = dsn;
options.environment = FLAVOR_DART_EXPR; // e.g. flavor.name or getFlavor().name — never a string literal
// Only emit the next two lines if PERF_MONITORING=true (Phase 0.6):
options.tracesSampleRate = <0.2 or 1.0>; // from Phase 0.6 map
options.profilesSampleRate = <1.0>; // relative to tracesSampleRate — see references/event-filtering-and-sampling.md
options.attachScreenshot = false; // PII — leave off by default
options.sendDefaultPii = false;
options.considerInAppFramesByDefault = false;
options.addInAppInclude(APP_PACKAGE_NAME);
options.beforeSend = (event, hint) async {
if (kDebugMode && !kDebugReporting) return null; // suppress debug noise, unless the smoke-test flag is set
return event;
};
// Deliberate, user-initiated — never subject to the debug-noise gate.
options.beforeSendFeedback = (event, hint) => event;
});
}
// --- existing post-init (preserve as-is) ---
// e.g. createProviderContainer(), Firebase providers
runApp(
SentryWidget( // wrap tree for screenshot path
child: ProviderScope( // or UncontrolledProviderScope(container: ...)
child: MyApp(),
),
),
);
}

Critical ordering rule: Sentry must init _before_ first provider read. Do not reorder SentryFlutter.init below ProviderContainer creation. See references/initialization-flow.md.

beforeSend carries no DioException filter — the expected-offline-error filter lives at the call site (Phase 4.3), not here. See references/event-filtering-and-sampling.md for why, and SENTRY_DEBUG_REPORTING for how to run the Phase 7 smoke test without touching this file.

2.3 Idempotency

If SentryFlutter.init( already exists in the file:

  • Check the existing options block against the template above.
  • Report any missing options as a diff.
  • Do not add a second SentryFlutter.init call.
2.4 Global error hooks

Also wire in main() (idempotent — check if already present):

dart
FlutterError.onError = (details) {
Sentry.captureException(details.exception, stackTrace: details.stack);
FlutterError.presentError(details);
};
PlatformDispatcher.instance.onError = (error, stack) {
Sentry.captureException(error, stackTrace: stack);
return true;
};

If the project already has these hooks routing to a LoggerService, do not duplicate — the decorator in Phase 4 will handle Sentry capture automatically.


Phase 3 — Wire GoRouter observer

See references/gorouter-and-dio-wiring.md for full context.

3.1 Locate GoRouter constructors

Typical paths: lib/router/app_router.dart, lib/src/router/, lib/router.dart. Grep for GoRouter(.

3.2 Inject observer

For each GoRouter( call found, add observers: [SentryNavigatorObserver()]. If observers: already present, append to the list:

dart
final goRouter = GoRouter(
initialLocation: '/',
observers: [SentryNavigatorObserver()], // ← add this
routes: [...],
);

For Riverpod-wrapped variant:

dart
@riverpod
GoRouter router(Ref ref) {
return GoRouter(
observers: [SentryNavigatorObserver()], // ← add this
refreshListenable: RouterNotifier(ref),
routes: [...],
);
}

Do NOT add to MaterialApp.router — it has no navigatorObservers argument.

3.3 Named routes warning

Inspect routes for name: fields. If no named routes found, emit this advisory:

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
5

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/iamantoniodinuzzo/claude-flutter/sentry-init/badge)](https://verified-skill.com/skills/iamantoniodinuzzo/claude-flutter/sentry-init)

Something wrong with this skill or its page? Tell us.