bun.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import widgetCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/widgetCallout';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import type {
  5. Docs,
  6. DocsParams,
  7. OnboardingConfig,
  8. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  9. import {
  10. getCrashReportJavaScriptInstallStep,
  11. getCrashReportModalConfigDescription,
  12. getCrashReportModalIntroduction,
  13. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  14. import exampleSnippets from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsExampleSnippets';
  15. import {metricTagsExplanation} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  16. import {
  17. feedbackOnboardingJsLoader,
  18. replayOnboardingJsLoader,
  19. } from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  20. import {t, tct} from 'sentry/locale';
  21. type Params = DocsParams;
  22. const getInstallConfig = () => [
  23. {
  24. language: 'bash',
  25. code: 'bun add @sentry/bun',
  26. },
  27. ];
  28. const getConfigureSnippet = (params: Params) => `
  29. //...
  30. import * as Sentry from "@sentry/bun";
  31. Sentry.init({
  32. dsn: "${params.dsn.public}",${
  33. params.isPerformanceSelected
  34. ? `
  35. // Tracing
  36. tracesSampleRate: 1.0, // Capture 100% of the transactions`
  37. : ''
  38. }
  39. });`;
  40. const getVerifySnippet = () => `try {
  41. throw new Error('Sentry Bun test');
  42. } catch (e) {
  43. Sentry.captureException(e);
  44. }`;
  45. const getMetricsConfigureSnippet = (params: DocsParams) => `
  46. Sentry.init({
  47. dsn: "${params.dsn.public}",
  48. // Only needed for SDK versions < 8.0.0
  49. // _experiments: {
  50. // metricsAggregator: true,
  51. // },
  52. });`;
  53. const onboarding: OnboardingConfig = {
  54. install: () => [
  55. {
  56. type: StepType.INSTALL,
  57. description: t(
  58. "Sentry captures data by using an SDK within your application's runtime."
  59. ),
  60. configurations: getInstallConfig(),
  61. },
  62. ],
  63. configure: params => [
  64. {
  65. type: StepType.CONFIGURE,
  66. description: t(
  67. "Initialize Sentry as early as possible in your application's lifecycle."
  68. ),
  69. configurations: [
  70. {
  71. language: 'javascript',
  72. code: getConfigureSnippet(params),
  73. },
  74. ],
  75. },
  76. ],
  77. verify: () => [
  78. {
  79. type: StepType.VERIFY,
  80. description: t(
  81. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  82. ),
  83. configurations: [
  84. {
  85. language: 'javascript',
  86. code: getVerifySnippet(),
  87. },
  88. ],
  89. },
  90. ],
  91. nextSteps: () => [],
  92. };
  93. const customMetricsOnboarding: OnboardingConfig = {
  94. install: () => [
  95. {
  96. type: StepType.INSTALL,
  97. description: tct(
  98. 'You need a minimum version [code:7.91.0] of [code:@sentry/bun].',
  99. {
  100. code: <code />,
  101. }
  102. ),
  103. configurations: getInstallConfig(),
  104. },
  105. ],
  106. configure: params => [
  107. {
  108. type: StepType.CONFIGURE,
  109. description: t(
  110. 'With the default snippet in place, there is no need for any further configuration.'
  111. ),
  112. configurations: [
  113. {
  114. code: getMetricsConfigureSnippet(params),
  115. language: 'javascript',
  116. },
  117. ],
  118. },
  119. ],
  120. verify: () => [
  121. {
  122. type: StepType.VERIFY,
  123. description: tct(
  124. "Then you'll be able to add metrics as [code:counters], [code:sets], [code:distributions], and [code:gauges]. These are available under the [code:Sentry.metrics] namespace. This API is available in both renderer and main processes.",
  125. {
  126. code: <code />,
  127. }
  128. ),
  129. configurations: [
  130. {
  131. description: metricTagsExplanation,
  132. },
  133. {
  134. description: t('Try out these examples:'),
  135. code: [
  136. {
  137. label: 'Counter',
  138. value: 'counter',
  139. language: 'javascript',
  140. code: exampleSnippets.javascript.counter,
  141. },
  142. {
  143. label: 'Distribution',
  144. value: 'distribution',
  145. language: 'javascript',
  146. code: exampleSnippets.javascript.distribution,
  147. },
  148. {
  149. label: 'Set',
  150. value: 'set',
  151. language: 'javascript',
  152. code: exampleSnippets.javascript.set,
  153. },
  154. {
  155. label: 'Gauge',
  156. value: 'gauge',
  157. language: 'javascript',
  158. code: exampleSnippets.javascript.gauge,
  159. },
  160. ],
  161. },
  162. {
  163. description: t(
  164. 'It can take up to 3 minutes for the data to appear in the Sentry UI.'
  165. ),
  166. },
  167. {
  168. description: tct(
  169. 'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
  170. {
  171. docsLink: (
  172. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/bun/metrics/" />
  173. ),
  174. }
  175. ),
  176. },
  177. ],
  178. },
  179. ],
  180. };
  181. const crashReportOnboarding: OnboardingConfig = {
  182. introduction: () => getCrashReportModalIntroduction(),
  183. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  184. configure: () => [
  185. {
  186. type: StepType.CONFIGURE,
  187. description: getCrashReportModalConfigDescription({
  188. link: 'https://docs.sentry.io/platforms/javascript/guides/bun/user-feedback/configuration/#crash-report-modal',
  189. }),
  190. additionalInfo: widgetCallout({
  191. link: 'https://docs.sentry.io/platforms/javascript/guides/bun/user-feedback/#user-feedback-widget',
  192. }),
  193. },
  194. ],
  195. verify: () => [],
  196. nextSteps: () => [],
  197. };
  198. const docs: Docs = {
  199. onboarding,
  200. replayOnboardingJsLoader,
  201. customMetricsOnboarding,
  202. crashReportOnboarding,
  203. feedbackOnboardingJsLoader,
  204. };
  205. export default docs;