angular.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. import crashReportCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/crashReportCallout';
  2. import widgetCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/widgetCallout';
  3. import TracePropagationMessage from 'sentry/components/onboarding/gettingStartedDoc/replay/tracePropagationMessage';
  4. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  5. import type {
  6. Docs,
  7. DocsParams,
  8. OnboardingConfig,
  9. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  10. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  11. import {
  12. getCrashReportJavaScriptInstallStep,
  13. getCrashReportModalConfigDescription,
  14. getCrashReportModalIntroduction,
  15. getFeedbackConfigOptions,
  16. getFeedbackConfigureDescription,
  17. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  18. import {getJSMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  19. import {getProfilingDocumentHeaderConfigurationStep} from 'sentry/components/onboarding/gettingStartedDoc/utils/profilingOnboarding';
  20. import {
  21. getReplayConfigOptions,
  22. getReplayConfigureDescription,
  23. } from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
  24. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  25. import {t, tct} from 'sentry/locale';
  26. type Params = DocsParams;
  27. const getNextStep = (
  28. params: Params
  29. ): {
  30. description: string;
  31. id: string;
  32. link: string;
  33. name: string;
  34. }[] => {
  35. let nextStepDocs = [...nextSteps];
  36. if (params.isPerformanceSelected) {
  37. nextStepDocs = nextStepDocs.filter(
  38. step => step.id !== ProductSolution.PERFORMANCE_MONITORING
  39. );
  40. }
  41. if (params.isReplaySelected) {
  42. nextStepDocs = nextStepDocs.filter(
  43. step => step.id !== ProductSolution.SESSION_REPLAY
  44. );
  45. }
  46. if (params.isProfilingSelected) {
  47. nextStepDocs = nextStepDocs.filter(step => step.id !== ProductSolution.PROFILING);
  48. }
  49. return nextStepDocs;
  50. };
  51. const getInstallConfig = () => [
  52. {
  53. language: 'bash',
  54. code: [
  55. {
  56. label: 'npm',
  57. value: 'npm',
  58. language: 'bash',
  59. code: `npm install --save @sentry/angular`,
  60. },
  61. {
  62. label: 'yarn',
  63. value: 'yarn',
  64. language: 'bash',
  65. code: `yarn add @sentry/angular`,
  66. },
  67. {
  68. label: 'pnpm',
  69. value: 'pnpm',
  70. language: 'bash',
  71. code: `pnpm install @sentry/angular`,
  72. },
  73. ],
  74. },
  75. ];
  76. const onboarding: OnboardingConfig = {
  77. install: () => [
  78. {
  79. type: StepType.INSTALL,
  80. description: tct(
  81. 'Add the Sentry SDK as a dependency using [codeNpm:npm], [codeYarn:yarn] or [codePnpm:pnpm]:',
  82. {
  83. codeYarn: <code />,
  84. codeNpm: <code />,
  85. codePnpm: <code />,
  86. }
  87. ),
  88. configurations: getInstallConfig(),
  89. },
  90. ],
  91. configure: (params: Params) => [
  92. {
  93. type: StepType.CONFIGURE,
  94. configurations: [
  95. getSetupConfiguration(params),
  96. {
  97. description: tct(
  98. "Register the Sentry Angular SDK's ErrorHandler and Tracing providers in your [codeModule:app.module.ts] file:",
  99. {
  100. codeModule: <code />,
  101. }
  102. ),
  103. language: 'javascript',
  104. code: `
  105. import { APP_INITIALIZER, ErrorHandler, NgModule } from "@angular/core";
  106. import { Router } from "@angular/router";
  107. import * as Sentry from "@sentry/angular";
  108. @NgModule({
  109. // ...
  110. providers: [
  111. {
  112. provide: ErrorHandler,
  113. useValue: Sentry.createErrorHandler({
  114. showDialog: true,
  115. }),
  116. }, {
  117. provide: Sentry.TraceService,
  118. deps: [Router],
  119. },
  120. {
  121. provide: APP_INITIALIZER,
  122. useFactory: () => () => {},
  123. deps: [Sentry.TraceService],
  124. multi: true,
  125. },
  126. ],
  127. // ...
  128. })
  129. export class AppModule {}`,
  130. },
  131. ],
  132. },
  133. ...(params.isProfilingSelected
  134. ? [getProfilingDocumentHeaderConfigurationStep()]
  135. : []),
  136. getUploadSourceMapsStep({
  137. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/angular/sourcemaps/',
  138. ...params,
  139. }),
  140. ],
  141. verify: () => [
  142. {
  143. type: StepType.VERIFY,
  144. description: t(
  145. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  146. ),
  147. configurations: [
  148. {
  149. language: 'javascript',
  150. code: `myUndefinedFunction();`,
  151. },
  152. ],
  153. },
  154. ],
  155. nextSteps: (params: Params) => getNextStep(params),
  156. };
  157. export const nextSteps = [
  158. {
  159. id: 'angular-features',
  160. name: t('Angular Features'),
  161. description: t('Learn about our first class integration with the Angular framework.'),
  162. link: 'https://docs.sentry.io/platforms/javascript/guides/angular/features/',
  163. },
  164. {
  165. id: 'performance-monitoring',
  166. name: t('Performance Monitoring'),
  167. description: t(
  168. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  169. ),
  170. link: 'https://docs.sentry.io/platforms/javascript/guides/angular/tracing/',
  171. },
  172. {
  173. id: 'session-replay',
  174. name: t('Session Replay'),
  175. description: t(
  176. '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.'
  177. ),
  178. link: 'https://docs.sentry.io/platforms/javascript/guides/angular/session-replay/',
  179. },
  180. ];
  181. function getSdkSetupSnippet(params: Params) {
  182. return `
  183. import { enableProdMode } from "@angular/core";
  184. import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
  185. import * as Sentry from "@sentry/angular";
  186. import { AppModule } from "./app/app.module";
  187. import { getProfilingDocumentHeaderConfigurationStep } from '../../components/onboarding/gettingStartedDoc/utils/profilingOnboarding';
  188. Sentry.init({
  189. dsn: "${params.dsn}",
  190. integrations: [${
  191. params.isPerformanceSelected
  192. ? `
  193. Sentry.browserTracingIntegration(),`
  194. : ''
  195. }${
  196. params.isProfilingSelected
  197. ? `
  198. Sentry.browserProfilingIntegration(),`
  199. : ''
  200. }${
  201. params.isFeedbackSelected
  202. ? `
  203. Sentry.feedbackIntegration({
  204. // Additional SDK configuration goes in here, for example:
  205. colorScheme: "system",
  206. ${getFeedbackConfigOptions(params.feedbackOptions)}}),`
  207. : ''
  208. }${
  209. params.isReplaySelected
  210. ? `
  211. Sentry.replayIntegration(${getReplayConfigOptions(params.replayOptions)}),`
  212. : ''
  213. }
  214. ],${
  215. params.isPerformanceSelected
  216. ? `
  217. // Performance Monitoring
  218. tracesSampleRate: 1.0, // Capture 100% of the transactions
  219. // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
  220. tracePropagationTargets: ["localhost", /^https:\\/\\/yourserver\\.io\\/api/],`
  221. : ''
  222. }${
  223. params.isReplaySelected
  224. ? `
  225. // Session Replay
  226. 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.
  227. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.`
  228. : ''
  229. }${
  230. params.isProfilingSelected
  231. ? `
  232. // Profiling
  233. profilesSampleRate: 1.0, // Profile 100% of the transactions. This value is relative to tracesSampleRate`
  234. : ''
  235. }
  236. });`;
  237. }
  238. function getSetupConfiguration(params: Params) {
  239. const configuration = {
  240. description: tct(
  241. `Initialize the Sentry Angular SDK in your [code:main.ts] file as early as possible, before initializing Angular:`,
  242. {
  243. code: <code />,
  244. }
  245. ),
  246. language: 'javascript',
  247. code: `
  248. ${getSdkSetupSnippet(params)}
  249. enableProdMode();
  250. platformBrowserDynamic()
  251. .bootstrapModule(AppModule)
  252. .catch((err) => console.error(err));`,
  253. };
  254. return configuration;
  255. }
  256. const replayOnboarding: OnboardingConfig = {
  257. install: () => [
  258. {
  259. type: StepType.INSTALL,
  260. description: tct(
  261. 'In order to use Session Replay, you will need version 7.27.0 of [codeAngular:@sentry/angular] at minimum. You do not need to install any additional packages.',
  262. {
  263. codeAngular: <code />,
  264. codeIvy: <code />,
  265. }
  266. ),
  267. configurations: getInstallConfig(),
  268. },
  269. ],
  270. configure: (params: Params) => [
  271. {
  272. type: StepType.CONFIGURE,
  273. description: getReplayConfigureDescription({
  274. link: 'https://docs.sentry.io/platforms/javascript/guides/angular/session-replay/',
  275. }),
  276. configurations: [
  277. {
  278. code: [
  279. {
  280. label: 'JavaScript',
  281. value: 'javascript',
  282. language: 'javascript',
  283. code: getSdkSetupSnippet(params),
  284. },
  285. ],
  286. },
  287. ],
  288. additionalInfo: <TracePropagationMessage />,
  289. },
  290. ],
  291. verify: () => [],
  292. nextSteps: () => [],
  293. };
  294. const feedbackOnboarding: OnboardingConfig = {
  295. install: () => [
  296. {
  297. type: StepType.INSTALL,
  298. description: tct(
  299. 'For the User Feedback integration to work, you must have the Sentry browser SDK package, or an equivalent framework SDK (e.g. [codeAngular:@sentry/angular]) installed, minimum version 7.85.0.',
  300. {
  301. codeAngular: <code />,
  302. codeIvy: <code />,
  303. }
  304. ),
  305. configurations: getInstallConfig(),
  306. },
  307. ],
  308. configure: (params: Params) => [
  309. {
  310. type: StepType.CONFIGURE,
  311. description: getFeedbackConfigureDescription({
  312. linkConfig:
  313. 'https://docs.sentry.io/platforms/javascript/guides/angular/user-feedback/configuration/',
  314. linkButton:
  315. 'https://docs.sentry.io/platforms/javascript/guides/angular/user-feedback/configuration/#bring-your-own-button',
  316. }),
  317. configurations: [
  318. {
  319. code: [
  320. {
  321. label: 'JavaScript',
  322. value: 'javascript',
  323. language: 'javascript',
  324. code: getSdkSetupSnippet(params),
  325. },
  326. ],
  327. },
  328. ],
  329. additionalInfo: crashReportCallout({
  330. link: 'https://docs.sentry.io/platforms/javascript/guides/angular/user-feedback/#crash-report-modal',
  331. }),
  332. },
  333. ],
  334. verify: () => [],
  335. nextSteps: () => [],
  336. };
  337. const crashReportOnboarding: OnboardingConfig = {
  338. introduction: () => getCrashReportModalIntroduction(),
  339. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  340. configure: () => [
  341. {
  342. type: StepType.CONFIGURE,
  343. description: getCrashReportModalConfigDescription({
  344. link: 'https://docs.sentry.io/platforms/javascript/guides/angular/user-feedback/configuration/#crash-report-modal',
  345. }),
  346. additionalInfo: widgetCallout({
  347. link: 'https://docs.sentry.io/platforms/javascript/guides/angular/user-feedback/#user-feedback-widget',
  348. }),
  349. },
  350. ],
  351. verify: () => [],
  352. nextSteps: () => [],
  353. };
  354. const docs: Docs = {
  355. onboarding,
  356. feedbackOnboardingNpm: feedbackOnboarding,
  357. replayOnboardingNpm: replayOnboarding,
  358. customMetricsOnboarding: getJSMetricsOnboarding({getInstallConfig}),
  359. crashReportOnboarding,
  360. };
  361. export default docs;