flutter.tsx 5.5 KB

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