dart.tsx 5.6 KB

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