flutter.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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('Debug Symbols'),
  166. configurations: [
  167. {
  168. description: t(
  169. 'We offer a range of methods to provide Sentry with debug symbols so that you can see symbolicated stack traces and triage issues faster.'
  170. ),
  171. },
  172. {
  173. description: (
  174. <p>
  175. {tct(
  176. "Complete stack traces will be shown for your Dart error by default, but if you use [splitDebugInfo: split-debug-info] and [obfuscate: obfuscate], you'll need to [uploadDebugSymbols: upload the debug information files] generated by the [flutter: flutter] build.",
  177. {
  178. splitDebugInfo: <code />,
  179. obfuscate: <code />,
  180. uploadDebugSymbols: (
  181. <ExternalLink href="https://docs.sentry.io/platforms/flutter/upload-debug/" />
  182. ),
  183. flutter: <code />,
  184. }
  185. )}
  186. </p>
  187. ),
  188. },
  189. {
  190. description: (
  191. <p>
  192. {tct(
  193. "You'll also need to [uploadDebug: upload the debug information files] generated by the [flutter: flutter] build for iOS, macOS, and Android NDK native crashes.",
  194. {
  195. uploadDebug: (
  196. <ExternalLink href="https://docs.sentry.io/platforms/flutter/upload-debug/" />
  197. ),
  198. flutter: <code />,
  199. }
  200. )}
  201. </p>
  202. ),
  203. },
  204. ],
  205. },
  206. {
  207. title: t('Source Context'),
  208. configurations: [
  209. {
  210. description: (
  211. <p>
  212. {tct(
  213. "If Sentry has access to your application's source code, it can show snippets of code [sourceContext: source context] around the location of stack frames, which helps to quickly pinpoint problematic code.",
  214. {
  215. sourceContext: <i />,
  216. }
  217. )}
  218. </p>
  219. ),
  220. },
  221. {
  222. description: (
  223. <p>
  224. {tct(
  225. "To enable source context, you'll need to upload debug symbols to Sentry by following the [sourceContext: Uploading Source Code Context for Flutter Android, iOS, and macOS] guide.",
  226. {
  227. sourceContext: (
  228. <ExternalLink href="https://docs.sentry.io/platforms/flutter/upload-debug/#uploading-source-code-context-for-flutter-android-ios-and-macos" />
  229. ),
  230. }
  231. )}
  232. </p>
  233. ),
  234. },
  235. ],
  236. },
  237. ];
  238. // Configuration End
  239. export function GettingStartedWithFlutter({
  240. dsn,
  241. sourcePackageRegistries,
  242. ...props
  243. }: ModuleProps) {
  244. return <Layout steps={steps({dsn, sourcePackageRegistries})} {...props} />;
  245. }
  246. export default GettingStartedWithFlutter;