flutter.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  3. import type {
  4. Docs,
  5. DocsParams,
  6. OnboardingConfig,
  7. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  8. import {feedbackOnboardingCrashApiDart} from 'sentry/gettingStartedDocs/dart/dart';
  9. import {t, tct} from 'sentry/locale';
  10. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  11. type Params = DocsParams;
  12. const getInstallSnippet = (params: Params) => `
  13. dependencies:
  14. sentry_flutter: ^${getPackageVersion(params, 'sentry.dart.flutter', '7.8.0')}`;
  15. const getConfigureSnippet = (params: Params) => `
  16. import 'package:flutter/widgets.dart';
  17. import 'package:sentry_flutter/sentry_flutter.dart';
  18. Future<void> main() async {
  19. await SentryFlutter.init(
  20. (options) {
  21. options.dsn = '${params.dsn}';
  22. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  23. // We recommend adjusting this value in production.
  24. options.tracesSampleRate = 1.0;
  25. },
  26. appRunner: () => runApp(MyApp()),
  27. );
  28. // or define SENTRY_DSN via Dart environment variable (--dart-define)
  29. }`;
  30. const getVerifySnippet = () => `
  31. import 'package:sentry/sentry.dart';
  32. try {
  33. aMethodThatMightFail();
  34. } catch (exception, stackTrace) {
  35. await Sentry.captureException(
  36. exception,
  37. stackTrace: stackTrace,
  38. );
  39. }`;
  40. const getPerformanceSnippet = () => `
  41. import 'package:sentry/sentry.dart';
  42. import { getPackageVersion } from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  43. final transaction = Sentry.startTransaction('processOrderBatch()', 'task');
  44. try {
  45. await processOrderBatch(transaction);
  46. } catch (exception) {
  47. transaction.throwable = exception;
  48. transaction.status = SpanStatus.internalError();
  49. } finally {
  50. await transaction.finish();
  51. }
  52. Future<void> processOrderBatch(ISentrySpan span) async {
  53. // span operation: task, span description: operation
  54. final innerSpan = span.startChild('task', description: 'operation');
  55. try {
  56. // omitted code
  57. } catch (exception) {
  58. innerSpan.throwable = exception;
  59. innerSpan.status = SpanStatus.notFound();
  60. } finally {
  61. await innerSpan.finish();
  62. }
  63. }`;
  64. const onboarding: OnboardingConfig = {
  65. install: params => [
  66. {
  67. type: StepType.INSTALL,
  68. description: tct(
  69. 'Sentry captures data by using an SDK within your application’s runtime. Add the following to your [pubspec: pubspec.yaml]',
  70. {
  71. pubspec: <code />,
  72. }
  73. ),
  74. configurations: [
  75. {
  76. language: 'yml',
  77. partialLoading: params.sourcePackageRegistries?.isLoading,
  78. code: getInstallSnippet(params),
  79. },
  80. ],
  81. },
  82. ],
  83. configure: params => [
  84. {
  85. type: StepType.CONFIGURE,
  86. description: tct('Import [sentryFlutter: sentry_flutter] and initialize it', {
  87. sentryFlutter: <code />,
  88. }),
  89. configurations: [
  90. {
  91. language: 'dart',
  92. code: getConfigureSnippet(params),
  93. additionalInfo: tct(
  94. 'You can configure the [sentryDsn: SENTRY_DSN], [sentryRelease: SENTRY_RELEASE], [sentryDist: SENTRY_DIST], and [sentryEnv: SENTRY_ENVIRONMENT] via the Dart environment variables passing the [dartDefine: --dart-define] flag to the compiler, as noted in the code sample.',
  95. {
  96. sentryDsn: <code />,
  97. sentryRelease: <code />,
  98. sentryDist: <code />,
  99. sentryEnv: <code />,
  100. dartDefine: <code />,
  101. }
  102. ),
  103. },
  104. ],
  105. },
  106. ],
  107. verify: () => [
  108. {
  109. type: StepType.VERIFY,
  110. description: t(
  111. 'Create an intentional error, so you can test that everything is working:'
  112. ),
  113. configurations: [
  114. {
  115. language: 'dart',
  116. code: getVerifySnippet(),
  117. additionalInfo: tct(
  118. "If you're new to Sentry, use the email alert to access your account and complete a product tour.[break] If you're an existing user and have disabled alerts, you won't receive this email.",
  119. {
  120. break: <br />,
  121. }
  122. ),
  123. },
  124. ],
  125. },
  126. {
  127. title: t('Performance'),
  128. description: t(
  129. "You'll be able to monitor the performance of your app using the SDK. For example:"
  130. ),
  131. configurations: [
  132. {
  133. language: 'dart',
  134. code: getPerformanceSnippet(),
  135. additionalInfo: tct(
  136. 'To learn more about the API and automatic instrumentations, check out the [perfDocs: performance documentation].',
  137. {
  138. perfDocs: (
  139. <ExternalLink href="https://docs.sentry.io/platforms/flutter/performance/instrumentation/" />
  140. ),
  141. }
  142. ),
  143. },
  144. ],
  145. },
  146. ],
  147. nextSteps: () => [
  148. {
  149. name: t('Debug Symbols'),
  150. description: t(
  151. 'We offer a range of methods to provide Sentry with debug symbols so that you can see symbolicated stack traces and triage issues faster.'
  152. ),
  153. link: 'https://docs.sentry.io/platforms/flutter/upload-debug/',
  154. },
  155. {
  156. name: t('Source Context'),
  157. description: t(
  158. "If Sentry has access to your application's source code, it can show snippets of code source context around the location of stack frames, which helps to quickly pinpoint problematic code."
  159. ),
  160. link: 'https://docs.sentry.io/platforms/flutter/upload-debug/#uploading-source-context-for-flutter-android-ios-and-macos',
  161. },
  162. ],
  163. };
  164. const docs: Docs = {
  165. onboarding,
  166. feedbackOnboardingCrashApi: feedbackOnboardingCrashApiDart,
  167. };
  168. export default docs;