flutter.tsx 7.0 KB

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