bun.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  2. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  5. import {PlatformKey} from 'sentry/data/platformCategories';
  6. import {t} from 'sentry/locale';
  7. import type {Organization} from 'sentry/types';
  8. type StepProps = {
  9. newOrg: boolean;
  10. organization: Organization;
  11. platformKey: PlatformKey;
  12. projectId: string;
  13. sentryInitContent: string;
  14. };
  15. const performanceOtherConfig = `
  16. // Performance Monitoring
  17. tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!
  18. `;
  19. export const steps = ({
  20. sentryInitContent,
  21. }: Partial<StepProps> = {}): LayoutProps['steps'] => [
  22. {
  23. type: StepType.INSTALL,
  24. description: t(
  25. "Sentry captures data by using an SDK within your application's runtime."
  26. ),
  27. configurations: [
  28. {
  29. language: 'bash',
  30. code: 'bun add @sentry/bun',
  31. },
  32. ],
  33. },
  34. {
  35. type: StepType.CONFIGURE,
  36. description: t(
  37. "Initialize Sentry as early as possible in your application's lifecycle."
  38. ),
  39. configurations: [
  40. {
  41. language: 'javascript',
  42. code: `
  43. //...
  44. import * as Sentry from "@sentry/bun";
  45. Sentry.init({
  46. ${sentryInitContent}
  47. });
  48. `,
  49. },
  50. ],
  51. },
  52. {
  53. type: StepType.VERIFY,
  54. description: t(
  55. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  56. ),
  57. configurations: [
  58. {
  59. language: 'javascript',
  60. code: `try {
  61. throw new Error('Sentry Bun test');
  62. } catch (e) {
  63. Sentry.captureException(e);
  64. }`,
  65. },
  66. ],
  67. },
  68. ];
  69. export const nextSteps = [
  70. {
  71. id: 'performance-monitoring',
  72. name: t('Performance Monitoring'),
  73. description: t(
  74. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  75. ),
  76. link: 'https://docs.sentry.io/platforms/javascript/guides/bun/performance/',
  77. },
  78. ];
  79. // Configuration End
  80. export function GettingStartedWithBun({
  81. dsn,
  82. activeProductSelection = [],
  83. newOrg,
  84. platformKey,
  85. ...props
  86. }: ModuleProps) {
  87. const integrations: string[] = [];
  88. const otherConfigs: string[] = [];
  89. let nextStepDocs = [...nextSteps];
  90. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  91. otherConfigs.push(performanceOtherConfig.trim());
  92. nextStepDocs = nextStepDocs.filter(
  93. step => step.id !== ProductSolution.PERFORMANCE_MONITORING
  94. );
  95. }
  96. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  97. if (integrations.length > 0) {
  98. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  99. }
  100. if (otherConfigs.length > 0) {
  101. sentryInitContent = sentryInitContent.concat(otherConfigs);
  102. }
  103. return (
  104. <Layout
  105. steps={steps({
  106. sentryInitContent: sentryInitContent.join('\n'),
  107. })}
  108. nextSteps={nextStepDocs}
  109. platformKey={platformKey}
  110. newOrg={newOrg}
  111. {...props}
  112. />
  113. );
  114. }
  115. export default GettingStartedWithBun;