azurefunctions.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  2. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  3. import {StepProps, StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  5. import {t, tct} from 'sentry/locale';
  6. import {
  7. getDefaultInitParams,
  8. getDefaultNodeImports,
  9. getInstallSnippet,
  10. getProductInitParams,
  11. getProductIntegrations,
  12. getProductSelectionMap,
  13. joinWithIndentation,
  14. } from 'sentry/utils/gettingStartedDocs/node';
  15. interface StepsParams {
  16. importContent: string;
  17. initContent: string;
  18. installSnippet: string;
  19. sourceMapStep: StepProps;
  20. }
  21. export const steps = ({
  22. installSnippet,
  23. importContent,
  24. initContent,
  25. sourceMapStep,
  26. }: StepsParams): LayoutProps['steps'] => [
  27. {
  28. type: StepType.INSTALL,
  29. description: t('Add the Sentry Node SDK as a dependency:'),
  30. configurations: [
  31. {
  32. language: 'bash',
  33. code: installSnippet,
  34. },
  35. ],
  36. },
  37. {
  38. type: StepType.CONFIGURE,
  39. description: t('To set up Sentry error logging for an Azure Function:'),
  40. configurations: [
  41. {
  42. language: 'javascript',
  43. code: `
  44. "use strict";
  45. ${importContent}
  46. Sentry.init({
  47. ${initContent}
  48. });
  49. module.exports = async function (context, req) {
  50. try {
  51. await notExistFunction();
  52. } catch (e) {
  53. Sentry.captureException(e);
  54. await Sentry.flush(2000);
  55. }
  56. context.res = {
  57. status: 200,
  58. body: "Hello from Azure Cloud Function!",
  59. };
  60. };
  61. `,
  62. },
  63. {
  64. language: 'javascript',
  65. description: (
  66. <p>
  67. {tct(
  68. 'Note: You need to call both [captureExceptionCode:captureException] and [flushCode:flush] for captured events to be successfully delivered to Sentry.',
  69. {captureExceptionCode: <code />, flushCode: <code />}
  70. )}
  71. </p>
  72. ),
  73. },
  74. ],
  75. },
  76. sourceMapStep,
  77. ];
  78. export function GettingStartedWithAzurefunctions({
  79. dsn,
  80. newOrg,
  81. platformKey,
  82. activeProductSelection = [],
  83. organization,
  84. projectId,
  85. }: ModuleProps) {
  86. const productSelection = getProductSelectionMap(activeProductSelection);
  87. const installSnippet = getInstallSnippet({productSelection});
  88. const imports = getDefaultNodeImports({productSelection});
  89. const integrations = getProductIntegrations({productSelection});
  90. const integrationParam =
  91. integrations.length > 0
  92. ? `integrations: [\n${joinWithIndentation(integrations)}\n],`
  93. : null;
  94. const initContent = joinWithIndentation([
  95. ...getDefaultInitParams({dsn}),
  96. ...(integrationParam ? [integrationParam] : []),
  97. ...getProductInitParams({productSelection}),
  98. ]);
  99. return (
  100. <Layout
  101. steps={steps({
  102. installSnippet,
  103. importContent: imports.join('\n'),
  104. initContent,
  105. sourceMapStep: getUploadSourceMapsStep({
  106. guideLink:
  107. 'https://docs.sentry.io/platforms/node/guides/azure-functions/sourcemaps/',
  108. organization,
  109. platformKey,
  110. projectId,
  111. newOrg,
  112. }),
  113. })}
  114. newOrg={newOrg}
  115. platformKey={platformKey}
  116. />
  117. );
  118. }
  119. export default GettingStartedWithAzurefunctions;