dart.tsx 5.7 KB

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