dart.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 getInstallSnippet = (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.public}';
  23. // Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
  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: getInstallSnippet(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 [code: SENTRY_DSN], [code: SENTRY_RELEASE], [code: SENTRY_DIST], and [code: SENTRY_ENVIRONMENT] via the Dart environment variables passing the [code: --dart-define] flag to the compiler, as noted in the code sample.',
  94. {
  95. code: <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('Tracing'),
  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/tracing/instrumentation/" />
  135. ),
  136. }
  137. ),
  138. },
  139. ],
  140. },
  141. ],
  142. };
  143. export const feedbackOnboardingCrashApiDart: OnboardingConfig = {
  144. introduction: () => getCrashReportApiIntroduction(),
  145. install: () => [
  146. {
  147. type: StepType.INSTALL,
  148. description: getCrashReportInstallDescription(),
  149. configurations: [
  150. {
  151. code: [
  152. {
  153. label: 'Dart',
  154. value: 'dart',
  155. language: 'dart',
  156. code: `import 'package:sentry/sentry.dart';
  157. SentryId sentryId = Sentry.captureMessage("My message");
  158. final userFeedback = SentryUserFeedback(
  159. eventId: sentryId,
  160. comments: 'Hello World!',
  161. email: 'foo@bar.org',
  162. name: 'John Doe',
  163. );
  164. Sentry.captureUserFeedback(userFeedback);`,
  165. },
  166. ],
  167. },
  168. ],
  169. },
  170. ],
  171. configure: () => [],
  172. verify: () => [],
  173. nextSteps: () => [],
  174. };
  175. const docs: Docs = {
  176. onboarding,
  177. feedbackOnboardingCrashApi: feedbackOnboardingCrashApiDart,
  178. crashReportOnboarding: feedbackOnboardingCrashApiDart,
  179. };
  180. export default docs;