bun.tsx 5.7 KB

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