azurefunctions.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 {PlatformKey} from 'sentry/data/platformCategories';
  5. import {tct} from 'sentry/locale';
  6. import type {Organization} from 'sentry/types';
  7. type StepProps = {
  8. newOrg: boolean;
  9. organization: Organization;
  10. platformKey: PlatformKey;
  11. projectId: string;
  12. sentryInitContent: string;
  13. };
  14. export const steps = ({
  15. sentryInitContent,
  16. }: Partial<StepProps> = {}): LayoutProps['steps'] => [
  17. {
  18. type: StepType.INSTALL,
  19. description: (
  20. <p>{tct('Add [code:@sentry/node] as a dependency:', {code: <code />})}</p>
  21. ),
  22. configurations: [
  23. {
  24. language: 'bash',
  25. code: `
  26. # Using yarn
  27. yarn add @sentry/node
  28. # Using npm
  29. npm install --save @sentry/node
  30. `,
  31. },
  32. ],
  33. },
  34. {
  35. type: StepType.CONFIGURE,
  36. description: (
  37. <p>
  38. {tct('To set up Sentry error logging for an Azure Function:', {
  39. code: <code />,
  40. })}
  41. </p>
  42. ),
  43. configurations: [
  44. {
  45. language: 'javascript',
  46. code: `
  47. "use strict";
  48. const Sentry = require("@sentry/node");
  49. Sentry.init({
  50. ${sentryInitContent},
  51. });
  52. module.exports = async function (context, req) {
  53. try {
  54. await notExistFunction();
  55. } catch (e) {
  56. Sentry.captureException(e);
  57. await Sentry.flush(2000);
  58. }
  59. context.res = {
  60. status: 200,
  61. body: "Hello from Azure Cloud Function!",
  62. };
  63. };
  64. `,
  65. },
  66. {
  67. language: 'javascript',
  68. description: (
  69. <p>
  70. {tct(
  71. 'Note: You need to call both [code:captureException] and [code:flush] for captured events to be successfully delivered to Sentry.',
  72. {}
  73. )}
  74. </p>
  75. ),
  76. },
  77. ],
  78. },
  79. ];
  80. export function GettingStartedWithAzurefunctions({
  81. dsn,
  82. organization,
  83. newOrg,
  84. platformKey,
  85. projectId,
  86. }: ModuleProps) {
  87. const sentryInitContent: string[] = [`dsn: "${dsn}"`];
  88. return (
  89. <Layout
  90. steps={steps({
  91. sentryInitContent: sentryInitContent.join('\n'),
  92. organization,
  93. newOrg,
  94. platformKey,
  95. projectId,
  96. })}
  97. newOrg={newOrg}
  98. platformKey={platformKey}
  99. />
  100. );
  101. }
  102. export default GettingStartedWithAzurefunctions;