flutter.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  3. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  4. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  5. import {t, tct} from 'sentry/locale';
  6. // Configuration Start
  7. export const steps = ({
  8. dsn,
  9. sourcePackageRegistries,
  10. }: Partial<
  11. Pick<ModuleProps, 'dsn' | 'sourcePackageRegistries'>
  12. > = {}): LayoutProps['steps'] => [
  13. {
  14. type: StepType.INSTALL,
  15. description: (
  16. <p>
  17. {tct(
  18. 'Sentry captures data by using an SDK within your application’s runtime. Add the following to your [pubspec: pubspec.yaml]',
  19. {
  20. pubspec: <code />,
  21. }
  22. )}
  23. </p>
  24. ),
  25. configurations: [
  26. {
  27. language: 'yml',
  28. partialLoading: sourcePackageRegistries?.isLoading,
  29. code: `
  30. dependencies:
  31. sentry_flutter: ^${
  32. sourcePackageRegistries?.isLoading
  33. ? t('\u2026loading')
  34. : sourcePackageRegistries?.data?.['sentry.dart.flutter']?.version ?? '7.8.0'
  35. }
  36. `,
  37. },
  38. ],
  39. },
  40. {
  41. type: StepType.CONFIGURE,
  42. description: (
  43. <p>
  44. {tct('Import [sentryFlutter: sentry_flutter] and initialize it', {
  45. sentryFlutter: <code />,
  46. })}
  47. </p>
  48. ),
  49. configurations: [
  50. {
  51. language: 'dart',
  52. code: `
  53. import 'package:flutter/widgets.dart';
  54. import 'package:sentry_flutter/sentry_flutter.dart';
  55. Future<void> main() async {
  56. await SentryFlutter.init(
  57. (options) {
  58. options.dsn = '${dsn}';
  59. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  60. // We recommend adjusting this value in production.
  61. options.tracesSampleRate = 1.0;
  62. },
  63. appRunner: () => runApp(MyApp()),
  64. );
  65. // or define SENTRY_DSN via Dart environment variable (--dart-define)
  66. }
  67. `,
  68. additionalInfo: (
  69. <p>
  70. {tct(
  71. '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.',
  72. {
  73. sentryDsn: <code />,
  74. sentryRelease: <code />,
  75. sentryDist: <code />,
  76. sentryEnv: <code />,
  77. dartDefine: <code />,
  78. }
  79. )}
  80. </p>
  81. ),
  82. },
  83. ],
  84. },
  85. {
  86. type: StepType.VERIFY,
  87. description: t(
  88. 'Create an intentional error, so you can test that everything is working:'
  89. ),
  90. configurations: [
  91. {
  92. language: 'dart',
  93. code: `
  94. import 'package:sentry/sentry.dart';
  95. try {
  96. aMethodThatMightFail();
  97. } catch (exception, stackTrace) {
  98. await Sentry.captureException(
  99. exception,
  100. stackTrace: stackTrace,
  101. );
  102. }
  103. `,
  104. additionalInfo: (
  105. <p>
  106. {tct(
  107. "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.",
  108. {
  109. break: <br />,
  110. }
  111. )}
  112. </p>
  113. ),
  114. },
  115. ],
  116. },
  117. {
  118. title: t('Performance'),
  119. description: t(
  120. "You'll be able to monitor the performance of your app using the SDK. For example:"
  121. ),
  122. configurations: [
  123. {
  124. language: 'dart',
  125. code: `
  126. import 'package:sentry/sentry.dart';
  127. final transaction = Sentry.startTransaction('processOrderBatch()', 'task');
  128. try {
  129. await processOrderBatch(transaction);
  130. } catch (exception) {
  131. transaction.throwable = exception;
  132. transaction.status = SpanStatus.internalError();
  133. } finally {
  134. await transaction.finish();
  135. }
  136. Future<void> processOrderBatch(ISentrySpan span) async {
  137. // span operation: task, span description: operation
  138. final innerSpan = span.startChild('task', description: 'operation');
  139. try {
  140. // omitted code
  141. } catch (exception) {
  142. innerSpan.throwable = exception;
  143. innerSpan.status = SpanStatus.notFound();
  144. } finally {
  145. await innerSpan.finish();
  146. }
  147. }
  148. `,
  149. additionalInfo: (
  150. <p>
  151. {tct(
  152. 'To learn more about the API and automatic instrumentations, check out the [perfDocs: performance documentation].',
  153. {
  154. perfDocs: (
  155. <ExternalLink href="https://docs.sentry.io/platforms/flutter/performance/instrumentation/" />
  156. ),
  157. }
  158. )}
  159. </p>
  160. ),
  161. },
  162. ],
  163. },
  164. {
  165. title: t('Next Steps'),
  166. configurations: [
  167. {
  168. description: (
  169. <p>
  170. {tct(
  171. '[debugSymbols: Debug Symbols]: We offer a range of methods to provide Sentry with debug symbols so that you can see symbolicated stack traces and triage issues faster.',
  172. {
  173. debugSymbols: (
  174. <ExternalLink href="https://docs.sentry.io/platforms/flutter/upload-debug/" />
  175. ),
  176. }
  177. )}
  178. </p>
  179. ),
  180. },
  181. {
  182. description: (
  183. <p>
  184. {tct(
  185. "[sourceContext: Source Context]: 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.",
  186. {
  187. sourceContext: (
  188. <ExternalLink href="https://docs.sentry.io/platforms/flutter/upload-debug/#uploading-source-context-for-flutter-android-ios-and-macos" />
  189. ),
  190. }
  191. )}
  192. </p>
  193. ),
  194. },
  195. ],
  196. },
  197. ];
  198. // Configuration End
  199. export function GettingStartedWithFlutter({
  200. dsn,
  201. sourcePackageRegistries,
  202. ...props
  203. }: ModuleProps) {
  204. return <Layout steps={steps({dsn, sourcePackageRegistries})} {...props} />;
  205. }
  206. export default GettingStartedWithFlutter;