dart.tsx 4.6 KB

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