svelte.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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`;
  33. export const steps = ({
  34. sentryInitContent,
  35. ...props
  36. }: Partial<StepProps> = {}): LayoutProps['steps'] => [
  37. {
  38. type: StepType.INSTALL,
  39. description: (
  40. <p>
  41. {tct(
  42. 'Add the Sentry SDK as a dependency using [codeNpm:npm] or [codeYarn:yarn]:',
  43. {
  44. codeYarn: <code />,
  45. codeNpm: <code />,
  46. }
  47. )}
  48. </p>
  49. ),
  50. configurations: [
  51. {
  52. language: 'bash',
  53. code: [
  54. {
  55. label: 'npm',
  56. value: 'npm',
  57. language: 'bash',
  58. code: 'npm install --save @sentry/svelte',
  59. },
  60. {
  61. label: 'yarn',
  62. value: 'yarn',
  63. language: 'bash',
  64. code: 'yarn add @sentry/svelte',
  65. },
  66. ],
  67. },
  68. ],
  69. },
  70. {
  71. type: StepType.CONFIGURE,
  72. description: (
  73. <p>
  74. {tct(
  75. "Initialize Sentry as early as possible in your application's lifecycle, usually your Svelte app's entry point ([code:main.ts/js]):",
  76. {code: <code />}
  77. )}
  78. </p>
  79. ),
  80. configurations: [
  81. {
  82. language: 'javascript',
  83. code: `
  84. import "./app.css";
  85. import App from "./App.svelte";
  86. import * as Sentry from "@sentry/svelte";
  87. Sentry.init({
  88. ${sentryInitContent}
  89. });
  90. const app = new App({
  91. target: document.getElementById("app"),
  92. });
  93. export default app;
  94. `,
  95. },
  96. ],
  97. },
  98. getUploadSourceMapsStep({
  99. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/svelte/sourcemaps/',
  100. ...props,
  101. }),
  102. {
  103. type: StepType.VERIFY,
  104. description: t(
  105. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  106. ),
  107. configurations: [
  108. {
  109. language: 'javascript',
  110. code: `
  111. // SomeComponent.svelte
  112. <button type="button" on:click="{unknownFunction}">Break the world</button>
  113. `,
  114. },
  115. ],
  116. },
  117. ];
  118. export const nextSteps = [
  119. {
  120. id: 'svelte-features',
  121. name: t('Svelte Features'),
  122. description: t('Learn about our first class integration with the Svelte framework.'),
  123. link: 'https://docs.sentry.io/platforms/javascript/guides/svelte/features/',
  124. },
  125. {
  126. id: 'performance-monitoring',
  127. name: t('Performance Monitoring'),
  128. description: t(
  129. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  130. ),
  131. link: 'https://docs.sentry.io/platforms/javascript/guides/svelte/performance/',
  132. },
  133. {
  134. id: 'session-replay',
  135. name: t('Session Replay'),
  136. description: t(
  137. '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.'
  138. ),
  139. link: 'https://docs.sentry.io/platforms/javascript/guides/svelte/session-replay/',
  140. },
  141. ];
  142. // Configuration End
  143. export function GettingStartedWithSvelte({
  144. dsn,
  145. activeProductSelection = [],
  146. platformKey,
  147. projectId,
  148. organization,
  149. newOrg,
  150. ...props
  151. }: ModuleProps) {
  152. const integrations: string[] = [];
  153. const otherConfigs: string[] = [];
  154. let nextStepDocs = [...nextSteps];
  155. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  156. integrations.push(performanceIntegration.trim());
  157. otherConfigs.push(performanceOtherConfig.trim());
  158. nextStepDocs = nextStepDocs.filter(
  159. step => step.id !== ProductSolution.PERFORMANCE_MONITORING
  160. );
  161. }
  162. if (activeProductSelection.includes(ProductSolution.SESSION_REPLAY)) {
  163. integrations.push(replayIntegration.trim());
  164. otherConfigs.push(replayOtherConfig.trim());
  165. nextStepDocs = nextStepDocs.filter(
  166. step => step.id !== ProductSolution.SESSION_REPLAY
  167. );
  168. }
  169. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  170. if (integrations.length > 0) {
  171. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  172. }
  173. if (otherConfigs.length > 0) {
  174. sentryInitContent = sentryInitContent.concat(otherConfigs);
  175. }
  176. return (
  177. <Layout
  178. steps={steps({
  179. sentryInitContent: sentryInitContent.join('\n'),
  180. organization,
  181. newOrg,
  182. platformKey,
  183. projectId,
  184. })}
  185. nextSteps={nextStepDocs}
  186. newOrg={newOrg}
  187. platformKey={platformKey}
  188. {...props}
  189. />
  190. );
  191. }
  192. export default GettingStartedWithSvelte;