gcpfunctions.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. // IMPORTANT: Make sure to import and initialize Sentry at the top of your file.
  19. ${getSdkInitSnippet(params, 'gpc')}
  20. // Place any other require/import statements here
  21. // Use wrapHttpFunction to instrument your http functions
  22. exports.helloHttp = Sentry.wrapHttpFunction((req, res) => {
  23. /* Your function code */
  24. });
  25. // Use wrapEventFunction to instrument your background functions
  26. exports.helloEvents = Sentry.wrapEventFunction(
  27. (data, context, callback) => {
  28. /* Your function code */
  29. }
  30. );
  31. // Use wrapCloudEventFunction to instrument your CloudEvent functions
  32. exports.helloEvents = Sentry.wrapCloudEventFunction(
  33. (context, callback) => {
  34. /* Your function code */
  35. }
  36. );`;
  37. const getVerifySnippet = () => `
  38. exports.helloHttp = Sentry.wrapHttpFunction((req, res) => {
  39. throw new Error("oh, hello there!");
  40. });`;
  41. const getMetricsConfigureSnippet = (params: DocsParams) => `
  42. Sentry.init({
  43. dsn: "${params.dsn}",
  44. _experiments: {
  45. metricsAggregator: true,
  46. },
  47. });`;
  48. const onboarding: OnboardingConfig = {
  49. install: params => [
  50. {
  51. type: StepType.INSTALL,
  52. description: tct(
  53. 'Add the Sentry Serverless SDK as a dependency to your [code:package.json]:',
  54. {code: <code />}
  55. ),
  56. configurations: [
  57. {
  58. language: 'json',
  59. configurations: getInstallConfig(params, {
  60. basePackage: '@sentry/google-cloud-functions',
  61. }),
  62. },
  63. ],
  64. },
  65. ],
  66. configure: params => [
  67. {
  68. type: StepType.CONFIGURE,
  69. description: tct(
  70. 'Ensure that Sentry is imported and initialized at the beginning of your file, prior to any other [require:require] or [import:import] statements. Then, use the Sentry SDK to wrap your functions:',
  71. {
  72. import: <code />,
  73. require: <code />,
  74. }
  75. ),
  76. configurations: [
  77. {
  78. language: 'javascript',
  79. code: getSdkSetupSnippet(params),
  80. },
  81. ],
  82. },
  83. getUploadSourceMapsStep({
  84. guideLink:
  85. 'https://docs.sentry.io/platforms/javascript/guides/gcp-functions/sourcemaps/',
  86. ...params,
  87. }),
  88. ],
  89. verify: () => [
  90. {
  91. type: StepType.VERIFY,
  92. description: t(
  93. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  94. ),
  95. configurations: [
  96. {
  97. language: 'javascript',
  98. code: getVerifySnippet(),
  99. },
  100. ],
  101. },
  102. ],
  103. };
  104. const customMetricsOnboarding: OnboardingConfig = {
  105. install: params => [
  106. {
  107. type: StepType.INSTALL,
  108. description: tct(
  109. 'You need a minimum version [codeVersion:8.0.0] of [codePackage:@sentry/google-cloud-serverless]:',
  110. {
  111. codeVersion: <code />,
  112. codePackage: <code />,
  113. }
  114. ),
  115. configurations: getInstallConfig(params, {
  116. basePackage: '@sentry/google-cloud-functions',
  117. }),
  118. },
  119. ],
  120. configure: params => [
  121. {
  122. type: StepType.CONFIGURE,
  123. description: tct(
  124. 'To enable capturing metrics, you first need to add the [codeIntegration:metricsAggregator] experiment to your [codeNamespace:Sentry.init] call in your main process.',
  125. {
  126. codeIntegration: <code />,
  127. codeNamespace: <code />,
  128. }
  129. ),
  130. configurations: [
  131. {
  132. code: [
  133. {
  134. label: 'JavaScript',
  135. value: 'javascript',
  136. language: 'javascript',
  137. code: getMetricsConfigureSnippet(params),
  138. },
  139. ],
  140. },
  141. ],
  142. },
  143. ],
  144. verify: getJSServerMetricsOnboarding().verify,
  145. };
  146. const crashReportOnboarding: OnboardingConfig = {
  147. introduction: () => getCrashReportModalIntroduction(),
  148. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  149. configure: () => [
  150. {
  151. type: StepType.CONFIGURE,
  152. description: getCrashReportModalConfigDescription({
  153. link: 'https://docs.sentry.io/platforms/javascript/guides/gcp-functions/user-feedback/configuration/#crash-report-modal',
  154. }),
  155. },
  156. ],
  157. verify: () => [],
  158. nextSteps: () => [],
  159. };
  160. const docs: Docs = {
  161. onboarding,
  162. customMetricsOnboarding,
  163. crashReportOnboarding,
  164. };
  165. export default docs;