azurefunctions.tsx 2.8 KB

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