azurefunctions.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  2. import type {
  3. Docs,
  4. DocsParams,
  5. OnboardingConfig,
  6. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  7. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  8. import {
  9. getCrashReportJavaScriptInstallStep,
  10. getCrashReportModalConfigDescription,
  11. getCrashReportModalIntroduction,
  12. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  13. import {getJSServerMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  14. import {t, tct} from 'sentry/locale';
  15. import {getInstallConfig, getSdkInitSnippet} from 'sentry/utils/gettingStartedDocs/node';
  16. type Params = DocsParams;
  17. const getSdkSetupSnippet = (params: Params) => `
  18. "use strict";
  19. // IMPORTANT: Make sure to import and initialize Sentry at the top of your file.
  20. ${getSdkInitSnippet(params, 'node')}
  21. // Place any other require/import statements here
  22. module.exports = async function (context, req) {
  23. try {
  24. await notExistFunction();
  25. } catch (e) {
  26. Sentry.captureException(e);
  27. await Sentry.flush(2000);
  28. }
  29. context.res = {
  30. status: 200,
  31. body: "Hello from Azure Cloud Function!",
  32. };
  33. };
  34. `;
  35. const onboarding: OnboardingConfig = {
  36. install: params => [
  37. {
  38. type: StepType.INSTALL,
  39. description: t('Add the Sentry Node SDK as a dependency:'),
  40. configurations: getInstallConfig(params),
  41. },
  42. ],
  43. configure: params => [
  44. {
  45. type: StepType.CONFIGURE,
  46. description: tct(
  47. 'Ensure that Sentry is imported and initialized at the beginning of your file, prior to any other [require:require] or [import:import] statements.',
  48. {import: <code />, require: <code />}
  49. ),
  50. configurations: [
  51. {
  52. language: 'javascript',
  53. description: tct(
  54. 'Note: You need to call both [captureExceptionCode:captureException] and [flushCode:flush] for captured events to be successfully delivered to Sentry.',
  55. {captureExceptionCode: <code />, flushCode: <code />}
  56. ),
  57. },
  58. {
  59. language: 'javascript',
  60. code: getSdkSetupSnippet(params),
  61. },
  62. ],
  63. },
  64. getUploadSourceMapsStep({
  65. guideLink:
  66. 'https://docs.sentry.io/platforms/javascript/guides/azure-functions/sourcemaps/',
  67. ...params,
  68. }),
  69. ],
  70. verify: () => [],
  71. };
  72. const crashReportOnboarding: OnboardingConfig = {
  73. introduction: () => getCrashReportModalIntroduction(),
  74. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  75. configure: () => [
  76. {
  77. type: StepType.CONFIGURE,
  78. description: getCrashReportModalConfigDescription({
  79. link: 'https://docs.sentry.io/platforms/javascript/guides/azure-functions/user-feedback/configuration/#crash-report-modal',
  80. }),
  81. },
  82. ],
  83. verify: () => [],
  84. nextSteps: () => [],
  85. };
  86. const docs: Docs = {
  87. onboarding,
  88. customMetricsOnboarding: getJSServerMetricsOnboarding(),
  89. crashReportOnboarding,
  90. };
  91. export default docs;