dart.tsx 4.4 KB

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