bun.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  9. import {t, tct} from 'sentry/locale';
  10. type Params = DocsParams;
  11. const getInstallConfig = () => [
  12. {
  13. language: 'bash',
  14. code: 'bun add @sentry/bun',
  15. },
  16. ];
  17. const getConfigureSnippet = (params: Params) => `
  18. //...
  19. import * as Sentry from "@sentry/bun";
  20. Sentry.init({
  21. dsn: "${params.dsn}",${
  22. params.isPerformanceSelected
  23. ? `
  24. // Performance Monitoring
  25. tracesSampleRate: 1.0, // Capture 100% of the transactions`
  26. : ''
  27. }
  28. });`;
  29. const getVerifySnippet = () => `try {
  30. throw new Error('Sentry Bun test');
  31. } catch (e) {
  32. Sentry.captureException(e);
  33. }`;
  34. const getMetricsConfigureSnippet = (params: DocsParams) => `
  35. Sentry.init({
  36. dsn: "${params.dsn}",
  37. _experiments: {
  38. metricsAggregator: true,
  39. },
  40. });`;
  41. const getMetricsVerifySnippet = () => `
  42. // Add 4 to a counter named 'hits'
  43. Sentry.metrics.increment('hits', 4);`;
  44. const onboarding: OnboardingConfig = {
  45. install: () => [
  46. {
  47. type: StepType.INSTALL,
  48. description: t(
  49. "Sentry captures data by using an SDK within your application's runtime."
  50. ),
  51. configurations: getInstallConfig(),
  52. },
  53. ],
  54. configure: params => [
  55. {
  56. type: StepType.CONFIGURE,
  57. description: t(
  58. "Initialize Sentry as early as possible in your application's lifecycle."
  59. ),
  60. configurations: [
  61. {
  62. language: 'javascript',
  63. code: getConfigureSnippet(params),
  64. },
  65. ],
  66. },
  67. ],
  68. verify: () => [
  69. {
  70. type: StepType.VERIFY,
  71. description: t(
  72. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  73. ),
  74. configurations: [
  75. {
  76. language: 'javascript',
  77. code: getVerifySnippet(),
  78. },
  79. ],
  80. },
  81. ],
  82. nextSteps: params =>
  83. params.isPerformanceSelected
  84. ? []
  85. : [
  86. {
  87. id: 'performance-monitoring',
  88. name: t('Performance Monitoring'),
  89. description: t(
  90. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  91. ),
  92. link: 'https://docs.sentry.io/platforms/javascript/guides/bun/performance/',
  93. },
  94. ],
  95. };
  96. const customMetricsOnboarding: OnboardingConfig = {
  97. install: () => [
  98. {
  99. type: StepType.INSTALL,
  100. description: tct(
  101. 'You need a minimum version [codeVersion:7.91.0] of [codePackage:@sentry/bun].',
  102. {
  103. codeVersion: <code />,
  104. codePackage: <code />,
  105. }
  106. ),
  107. configurations: getInstallConfig(),
  108. },
  109. ],
  110. configure: params => [
  111. {
  112. type: StepType.CONFIGURE,
  113. description: tct(
  114. 'To enable capturing metrics, you first need to add the [codeIntegration:metricsAggregator] experiment to your [codeNamespace:Sentry.init] call in your main process.',
  115. {
  116. codeIntegration: <code />,
  117. codeNamespace: <code />,
  118. }
  119. ),
  120. configurations: [
  121. {
  122. code: [
  123. {
  124. label: 'JavaScript',
  125. value: 'javascript',
  126. language: 'javascript',
  127. code: getMetricsConfigureSnippet(params),
  128. },
  129. ],
  130. },
  131. ],
  132. },
  133. ],
  134. verify: () => [
  135. {
  136. type: StepType.VERIFY,
  137. description: tct(
  138. "Then you'll be able to add metrics as [codeCounters:counters], [codeSets:sets], [codeDistribution:distributions], and [codeGauge:gauges]. These are available under the [codeNamespace:Sentry.metrics] namespace. This API is available in both renderer and main processes. Try out this example:",
  139. {
  140. codeCounters: <code />,
  141. codeSets: <code />,
  142. codeDistribution: <code />,
  143. codeGauge: <code />,
  144. codeNamespace: <code />,
  145. }
  146. ),
  147. configurations: [
  148. {
  149. code: [
  150. {
  151. label: 'JavaScript',
  152. value: 'javascript',
  153. language: 'javascript',
  154. code: getMetricsVerifySnippet(),
  155. },
  156. ],
  157. },
  158. {
  159. description: t(
  160. 'With a bit of delay you can see the data appear in the Sentry UI.'
  161. ),
  162. },
  163. {
  164. description: tct(
  165. 'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
  166. {
  167. docsLink: (
  168. <ExternalLink href="https://github.com/getsentry/sentry-javascript/discussions/9973" />
  169. ),
  170. }
  171. ),
  172. },
  173. ],
  174. },
  175. ],
  176. };
  177. const docs: Docs = {
  178. onboarding,
  179. replayOnboardingJsLoader,
  180. customMetricsOnboarding,
  181. };
  182. export default docs;