svelte.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  5. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  6. import {t, tct} from 'sentry/locale';
  7. import type {Organization, PlatformKey} from 'sentry/types';
  8. type StepProps = {
  9. newOrg: boolean;
  10. organization: Organization;
  11. platformKey: PlatformKey;
  12. projectId: string;
  13. sentryInitContent: string;
  14. };
  15. // Configuration Start
  16. const replayIntegration = `
  17. new Sentry.Replay(),
  18. `;
  19. const replayOtherConfig = `
  20. // Session Replay
  21. replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
  22. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
  23. `;
  24. const performanceIntegration = `
  25. new Sentry.BrowserTracing({
  26. // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
  27. tracePropagationTargets: ["localhost", /^https:\\/\\/yourserver\\.io\\/api/],
  28. }),
  29. `;
  30. const performanceOtherConfig = `
  31. // Performance Monitoring
  32. tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!
  33. `;
  34. export const steps = ({
  35. sentryInitContent,
  36. ...props
  37. }: Partial<StepProps> = {}): LayoutProps['steps'] => [
  38. {
  39. type: StepType.INSTALL,
  40. description: (
  41. <p>
  42. {tct(
  43. 'Add the Sentry SDK as a dependency using [codeNpm:npm] or [codeYarn:yarn]:',
  44. {
  45. codeYarn: <code />,
  46. codeNpm: <code />,
  47. }
  48. )}
  49. </p>
  50. ),
  51. configurations: [
  52. {
  53. language: 'bash',
  54. code: [
  55. {
  56. label: 'npm',
  57. value: 'npm',
  58. language: 'bash',
  59. code: 'npm install --save @sentry/svelte',
  60. },
  61. {
  62. label: 'yarn',
  63. value: 'yarn',
  64. language: 'bash',
  65. code: 'yarn add @sentry/svelte',
  66. },
  67. ],
  68. },
  69. ],
  70. },
  71. {
  72. type: StepType.CONFIGURE,
  73. description: (
  74. <p>
  75. {tct(
  76. "Initialize Sentry as early as possible in your application's lifecycle, usually your Svelte app's entry point ([code:main.ts/js]):",
  77. {code: <code />}
  78. )}
  79. </p>
  80. ),
  81. configurations: [
  82. {
  83. language: 'javascript',
  84. code: `
  85. import "./app.css";
  86. import App from "./App.svelte";
  87. import * as Sentry from "@sentry/svelte";
  88. Sentry.init({
  89. ${sentryInitContent}
  90. });
  91. const app = new App({
  92. target: document.getElementById("app"),
  93. });
  94. export default app;
  95. `,
  96. },
  97. ],
  98. },
  99. getUploadSourceMapsStep({
  100. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/svelte/sourcemaps/',
  101. ...props,
  102. }),
  103. {
  104. type: StepType.VERIFY,
  105. description: t(
  106. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  107. ),
  108. configurations: [
  109. {
  110. language: 'javascript',
  111. code: `
  112. // SomeComponent.svelte
  113. <button type="button" on:click="{unknownFunction}">Break the world</button>
  114. `,
  115. },
  116. ],
  117. },
  118. ];
  119. export const nextSteps = [
  120. {
  121. id: 'svelte-features',
  122. name: t('Svelte Features'),
  123. description: t('Learn about our first class integration with the Svelte framework.'),
  124. link: 'https://docs.sentry.io/platforms/javascript/guides/svelte/features/',
  125. },
  126. {
  127. id: 'performance-monitoring',
  128. name: t('Performance Monitoring'),
  129. description: t(
  130. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  131. ),
  132. link: 'https://docs.sentry.io/platforms/javascript/guides/svelte/performance/',
  133. },
  134. {
  135. id: 'session-replay',
  136. name: t('Session Replay'),
  137. description: t(
  138. 'Get to the root cause of an error or latency issue faster by seeing all the technical details related to that issue in one visual replay on your web application.'
  139. ),
  140. link: 'https://docs.sentry.io/platforms/javascript/guides/svelte/session-replay/',
  141. },
  142. ];
  143. // Configuration End
  144. export function GettingStartedWithSvelte({
  145. dsn,
  146. activeProductSelection = [],
  147. platformKey,
  148. projectId,
  149. organization,
  150. newOrg,
  151. ...props
  152. }: ModuleProps) {
  153. const integrations: string[] = [];
  154. const otherConfigs: string[] = [];
  155. let nextStepDocs = [...nextSteps];
  156. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  157. integrations.push(performanceIntegration.trim());
  158. otherConfigs.push(performanceOtherConfig.trim());
  159. nextStepDocs = nextStepDocs.filter(
  160. step => step.id !== ProductSolution.PERFORMANCE_MONITORING
  161. );
  162. }
  163. if (activeProductSelection.includes(ProductSolution.SESSION_REPLAY)) {
  164. integrations.push(replayIntegration.trim());
  165. otherConfigs.push(replayOtherConfig.trim());
  166. nextStepDocs = nextStepDocs.filter(
  167. step => step.id !== ProductSolution.SESSION_REPLAY
  168. );
  169. }
  170. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  171. if (integrations.length > 0) {
  172. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  173. }
  174. if (otherConfigs.length > 0) {
  175. sentryInitContent = sentryInitContent.concat(otherConfigs);
  176. }
  177. return (
  178. <Layout
  179. steps={steps({
  180. sentryInitContent: sentryInitContent.join('\n'),
  181. organization,
  182. newOrg,
  183. platformKey,
  184. projectId,
  185. })}
  186. nextSteps={nextStepDocs}
  187. newOrg={newOrg}
  188. platformKey={platformKey}
  189. {...props}
  190. />
  191. );
  192. }
  193. export default GettingStartedWithSvelte;