gcpfunctions.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 {t, tct} from 'sentry/locale';
  14. import {getInstallConfig, getSdkInitSnippet} from 'sentry/utils/gettingStartedDocs/node';
  15. type Params = DocsParams;
  16. const getSdkSetupSnippet = (params: Params) => `
  17. // IMPORTANT: Make sure to import and initialize Sentry at the top of your file.
  18. ${getSdkInitSnippet(params, 'gpc')}
  19. // Place any other require/import statements here
  20. // Use wrapHttpFunction to instrument your http functions
  21. exports.helloHttp = Sentry.wrapHttpFunction((req, res) => {
  22. /* Your function code */
  23. });
  24. // Use wrapEventFunction to instrument your background functions
  25. exports.helloEvents = Sentry.wrapEventFunction(
  26. (data, context, callback) => {
  27. /* Your function code */
  28. }
  29. );
  30. // Use wrapCloudEventFunction to instrument your CloudEvent functions
  31. exports.helloEvents = Sentry.wrapCloudEventFunction(
  32. (context, callback) => {
  33. /* Your function code */
  34. }
  35. );`;
  36. const getVerifySnippet = () => `
  37. exports.helloHttp = Sentry.wrapHttpFunction((req, res) => {
  38. throw new Error("oh, hello there!");
  39. });`;
  40. const onboarding: OnboardingConfig = {
  41. introduction: () =>
  42. tct('In this quick guide you’ll use [strong:npm] or [strong:yarn] to set up:', {
  43. strong: <strong />,
  44. }),
  45. install: params => [
  46. {
  47. type: StepType.INSTALL,
  48. description: tct(
  49. 'Add the Sentry Serverless SDK as a dependency to your [code:package.json]:',
  50. {code: <code />}
  51. ),
  52. configurations: [
  53. {
  54. language: 'json',
  55. configurations: getInstallConfig(params, {
  56. basePackage: '@sentry/google-cloud-serverless',
  57. }),
  58. },
  59. ],
  60. },
  61. ],
  62. configure: params => [
  63. {
  64. type: StepType.CONFIGURE,
  65. description: tct(
  66. 'Ensure that Sentry is imported and initialized at the beginning of your file, prior to any other [code:require] or [code:import] statements. Then, use the Sentry SDK to wrap your functions:',
  67. {
  68. code: <code />,
  69. }
  70. ),
  71. configurations: [
  72. {
  73. language: 'javascript',
  74. code: getSdkSetupSnippet(params),
  75. },
  76. ],
  77. },
  78. getUploadSourceMapsStep({
  79. guideLink:
  80. 'https://docs.sentry.io/platforms/javascript/guides/gcp-functions/sourcemaps/',
  81. ...params,
  82. }),
  83. ],
  84. verify: () => [
  85. {
  86. type: StepType.VERIFY,
  87. description: t(
  88. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  89. ),
  90. configurations: [
  91. {
  92. language: 'javascript',
  93. code: getVerifySnippet(),
  94. },
  95. ],
  96. },
  97. ],
  98. };
  99. const crashReportOnboarding: OnboardingConfig = {
  100. introduction: () => getCrashReportModalIntroduction(),
  101. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  102. configure: () => [
  103. {
  104. type: StepType.CONFIGURE,
  105. description: getCrashReportModalConfigDescription({
  106. link: 'https://docs.sentry.io/platforms/javascript/guides/gcp-functions/user-feedback/configuration/#crash-report-modal',
  107. }),
  108. },
  109. ],
  110. verify: () => [],
  111. nextSteps: () => [],
  112. };
  113. const docs: Docs = {
  114. onboarding,
  115. crashReportOnboarding,
  116. };
  117. export default docs;