dart.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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: ^${
  32. sourcePackageRegistries?.isLoading
  33. ? t('\u2026loading')
  34. : sourcePackageRegistries?.data?.['sentry.dart']?.version ?? '7.8.0'
  35. }
  36. `,
  37. },
  38. ],
  39. },
  40. {
  41. type: StepType.CONFIGURE,
  42. description: (
  43. <p>
  44. {tct('Import [sentry: sentry] and initialize it', {
  45. sentry: <code />,
  46. })}
  47. </p>
  48. ),
  49. configurations: [
  50. {
  51. language: 'dart',
  52. code: `
  53. import 'package:sentry/sentry.dart';
  54. Future<void> main() async {
  55. await Sentry.init((options) {
  56. options.dsn = '${dsn}';
  57. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  58. // We recommend adjusting this value in production.
  59. options.tracesSampleRate = 1.0;
  60. });
  61. // or define SENTRY_DSN via Dart environment variable (--dart-define)
  62. }
  63. `,
  64. additionalInfo: (
  65. <p>
  66. {tct(
  67. '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.',
  68. {
  69. sentryDsn: <code />,
  70. sentryRelease: <code />,
  71. sentryDist: <code />,
  72. sentryEnv: <code />,
  73. dartDefine: <code />,
  74. }
  75. )}
  76. </p>
  77. ),
  78. },
  79. ],
  80. },
  81. {
  82. type: StepType.VERIFY,
  83. description: t(
  84. 'Create an intentional error, so you can test that everything is working:'
  85. ),
  86. configurations: [
  87. {
  88. language: 'dart',
  89. code: `
  90. import 'package:sentry/sentry.dart';
  91. try {
  92. aMethodThatMightFail();
  93. } catch (exception, stackTrace) {
  94. await Sentry.captureException(
  95. exception,
  96. stackTrace: stackTrace,
  97. );
  98. }
  99. `,
  100. additionalInfo: (
  101. <p>
  102. {tct(
  103. "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.",
  104. {
  105. break: <br />,
  106. }
  107. )}
  108. </p>
  109. ),
  110. },
  111. ],
  112. },
  113. {
  114. title: t('Performance'),
  115. description: t(
  116. "You'll be able to monitor the performance of your app using the SDK. For example:"
  117. ),
  118. configurations: [
  119. {
  120. language: 'dart',
  121. code: `
  122. import 'package:sentry/sentry.dart';
  123. final transaction = Sentry.startTransaction('processOrderBatch()', 'task');
  124. try {
  125. await processOrderBatch(transaction);
  126. } catch (exception) {
  127. transaction.throwable = exception;
  128. transaction.status = SpanStatus.internalError();
  129. } finally {
  130. await transaction.finish();
  131. }
  132. Future<void> processOrderBatch(ISentrySpan span) async {
  133. // span operation: task, span description: operation
  134. final innerSpan = span.startChild('task', description: 'operation');
  135. try {
  136. // omitted code
  137. } catch (exception) {
  138. innerSpan.throwable = exception;
  139. innerSpan.status = SpanStatus.notFound();
  140. } finally {
  141. await innerSpan.finish();
  142. }
  143. }
  144. `,
  145. additionalInfo: (
  146. <p>
  147. {tct(
  148. 'To learn more about the API and automatic instrumentations, check out the [perfDocs: performance documentation].',
  149. {
  150. perfDocs: (
  151. <ExternalLink href="https://docs.sentry.io/platforms/dart/performance/instrumentation/" />
  152. ),
  153. }
  154. )}
  155. </p>
  156. ),
  157. },
  158. ],
  159. },
  160. ];
  161. // Configuration End
  162. export function GettingStartedWithDart({
  163. dsn,
  164. sourcePackageRegistries,
  165. ...props
  166. }: ModuleProps) {
  167. return <Layout steps={steps({dsn, sourcePackageRegistries})} {...props} />;
  168. }
  169. export default GettingStartedWithDart;