本文へ移動
cccskills
無料GitHub で公開

integrating-sentry

Integrates Sentry error tracking and performance monitoring into Flutter apps using `sentry_flutter`. Use when setting up crash reporting in Flutter, calling `SentryFlutter.init`, adding `SentryNavigatorObserver` to GoRouter, tracing HTTP requests with `sentry_dio`, capturing handled exceptions via `Sentry.captureException`, adding breadcrumbs, configuring session replay (`replay.onErrorSampleRate`), tuning `tracesSampleRate` or `profilesSampleRate`, controlling PII with `sendDefaultPii`, or setting user context after login and logout.

インストール方法を見る

含まれるファイル(1)

  • SKILL.md5.6 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Sentry Flutter Integration Guide (sentry_flutter)

Goal

Implement a robust observability and performance monitoring layer using Sentry's official Flutter SDK. This skill ensures comprehensive error tracking across the UI and Network layers, alongside performance tracking (Tracing) for application navigation and HTTP requests, without exhausting Sentry data quotas or exposing PII.

Instructions

1. Core Initialization (sentry_flutter)

You must initialize Sentry as early as possible in your application's lifecycle, wrapping runApp with SentryWidget to capture AssetBundle transaction times and basic UI interactions natively.

import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await SentryFlutter.init(
    (options) {
      options.dsn = '___PUBLIC_DSN___'; // Inject via --dart-define or .env
      
      // Controls the percentage of Tracing (Performance) transactions sent.
      // 1.0 = 100%. (Reduce in production to avoid quota exhaustion!)
      options.tracesSampleRate = 0.2; 
      
      // Profiles provide deep CPU-level insights. Tied to TracesSampleRate.
      options.profilesSampleRate = 1.0; 

      // Replay sessions to visually debug errors.
      options.replay.onErrorSampleRate = 1.0; 
      options.replay.sessionSampleRate = 0.1;

      // Ensure PII (Personally Identifiable Information) isn't recklessly sent
      options.sendDefaultPii = false; 
    },
    appRunner: () => runApp(
      SentryWidget(
        child: const MyApp(),
      ),
    ),
  );
}

2. Routing Instrumentation (GoRouter)

Sentry can automatically track how long it takes to render a screen and trace the navigation paths of users. If you are using go_router (the standard Flutter routing solution), you must inject the SentryNavigatorObserver.

import 'package:go_router/go_router.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

final GoRouter _router = GoRouter(
  initialLocation: '/',
  // 1. Add the observer to the main router
  observers: [
    SentryNavigatorObserver(),
  ],
  routes: [
    GoRoute(
      path: '/',
      builder: (context, state) => const HomeScreen(),
    ),
    GoRoute(
      path: '/details',
      builder: (context, state) => const DetailsScreen(),
    ),
  ],
);

Note: This automatically creates Spans and Breadcrumbs every time context.go() or context.push() is invoked.

3. HTTP Network Instrumentation (sentry_dio)

To trace the time spent on backend API calls and automatically log failed HTTP requests (400s, 500s) directly to Sentry, utilize the sentry_dio package.

import 'package:dio/dio.dart';
import 'package:sentry_dio/sentry_dio.dart';

final dio = Dio(
  BaseOptions(baseUrl: 'https://api.yourbackend.com'),
);

// Add the Sentry interceptor. This captures all requests/responses natively.
dio.addSentry(
  captureFailedRequests: true, // Automatically logs 4xx and 5xx responses as Exceptions
);

// Now, simply make requests. Sentry tracks the latency and errors implicitly.
Future<void> fetchUsers() async {
  final response = await dio.get('/users'); 
}

4. Manual Capturing (Exceptions & Breadcrumbs)

While Sentry automatically catches unhandled UI and async errors, you often need to manually record caught exceptions or leave "Breadcrumbs" (logging hints) leading up to an error.

import 'package:sentry_flutter/sentry_flutter.dart';

Future<void> checkout(Cart cart) async {
  // 1. Leave a Breadcrumb
  Sentry.addBreadcrumb(Breadcrumb(
    message: 'User initiated checkout process',
    category: 'ecommerce.checkout',
    level: SentryLevel.info,
    data: {'cartTotal': cart.totalPrice},
  ));

  try {
    await api.processPayment(cart);
  } catch (exception, stackTrace) {
    // 2. Capture a handled Exception explicitly
    await Sentry.captureException(
      exception,
      stackTrace: stackTrace,
    );
    // Show a user-friendly error UI
  }
}

// 3. User Context (Add this after Login)
void setUserContext(String userId, String email) {
  Sentry.configureScope((scope) => scope.setUser(SentryUser(id: userId, email: email)));
}

// 4. Clear User Context (Add this after Logout)
void clearUserContext() {
  Sentry.configureScope((scope) => scope.setUser(null));
}

Constraints

  1. Production Limits: NEVER deploy a high-volume application to production with tracesSampleRate = 1.0 unless you have an infinite budget. Start at 0.1 (10%) and adjust based on your monthly Sentry quota.
  2. PII Handling: Be extremely careful not to put user passwords, session tokens, or raw payment details into custom Breadcrumb data dictionaries. Keep sendDefaultPii = false unless strictly required & vetted by security policies.
  3. Interceptor Order: When initializing a Dio client with multiple interceptors (like Auth or Logging), ensure dio.addSentry() is initialized so it can capture the fully mutated requests (e.g., after Authorization headers are attached).

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Declarative animation patterns using flutter_animate v4.5.x with composable effects (fade, scale, slide, shimmer, shake, blur), GLSL fragment shaders, and scroll-synchronized animations. Use this skill for adding UI animations and transitions, building staggered or sequenced effects, creating custom animation effects, fixing animation jank or performance issues, implementing shimmer loading states, or adding scroll-driven animations. Supports delays, curves, adaptive effects, and easy extension method chaining (.animate()).

日本語の概要は準備中です。原文の説明を表示しています。

Poorgramer-Zack/dart-expert-skills72026年8月11日 更新

Dart 3 modern features (through 3.10) and Effective Dart best practices including records, patterns, sealed classes, dot shorthands, null-aware collection elements, and wildcard variables. Use when adopting Dart 3.7+ syntax, using dot shorthands for enums or static members, using null-aware elements in lists or maps, using wildcard _ parameters, improving code quality, or reviewing Dart code conventions.

日本語の概要は準備中です。原文の説明を表示しています。

Poorgramer-Zack/dart-expert-skills72026年8月11日 更新

Expert-level guidance for Flutter production applications: architecture decisions (Clean/Layered/Hexagonal/Feature-First), advanced state management (BLoC/Riverpod/GetX), performance optimization (eliminating jank, memory profiling, reducing rebuild overhead), code review with design pattern enforcement, scalability assessments, native platform integration (MethodChannel/EventChannel/FFI), complex UI challenges (custom render objects, slivers), testing strategies (unit/widget/integration/golden), CI/CD pipeline architecture, build optimization, and accessibility compliance. Triggers: 'architecture decision', 'design pattern', 'performance issue', 'code review', 'production problem', 'scaling concerns', 'best practices', 'technical debt', 'refactoring strategy'. Essential for complex enterprise apps, critical production debugging, architectural refactors, or when choosing between competing technical approaches.

日本語の概要は準備中です。原文の説明を表示しています。

Poorgramer-Zack/dart-expert-skills72026年8月11日 更新

Builds SEO-friendly web applications with Dart using the Jaspr framework. Use when creating Dart-based websites, blogs, or landing pages requiring semantic HTML output; implementing server-side rendering (SSR) or static site generation (SSG); adding Tailwind CSS via jaspr_tailwind; routing with jaspr_router; testing components with jaspr_test; or building full-stack Dart web apps where Flutter Web's canvas rendering is unsuitable.

日本語の概要は準備中です。原文の説明を表示しています。

Poorgramer-Zack/dart-expert-skills72026年8月11日 更新

shadcn_flutter UI component library for building accessible, themed Flutter interfaces. Use when integrating shadcn components, configuring design system theming, or building consistent widget layouts.

日本語の概要は準備中です。原文の説明を表示しています。

Poorgramer-Zack/dart-expert-skills72026年8月11日 更新

Configures Codemagic CI/CD pipelines for Flutter using `codemagic.yaml`. Use when setting up automated Flutter builds on Codemagic, configuring iOS code signing without Fastlane Match, deploying to App Store Connect or Google Play from Codemagic, caching pub dependencies in Codemagic, setting up encrypted environment variable groups, running tests with Codemagic's test dashboard, or choosing between Codemagic and GitHub Actions + Fastlane for a Flutter CI/CD pipeline.

日本語の概要は準備中です。原文の説明を表示しています。

Poorgramer-Zack/dart-expert-skills72026年8月11日 更新

Poorgramer-Zack のスキルをすべて見る

このスキルの問題を報告する