gcpfunctions.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 {ProductSolution} from 'sentry/components/onboarding/productSelection';
  15. import {t, tct} from 'sentry/locale';
  16. import type {ProductSelectionMap} from 'sentry/utils/gettingStartedDocs/node';
  17. import {getDefaulServerlessImports} from 'sentry/utils/gettingStartedDocs/node';
  18. type Params = DocsParams;
  19. const productSelection = (params: Params): ProductSelectionMap => {
  20. return {
  21. [ProductSolution.ERROR_MONITORING]: true,
  22. [ProductSolution.PROFILING]: params.isProfilingSelected,
  23. [ProductSolution.PERFORMANCE_MONITORING]: params.isPerformanceSelected,
  24. [ProductSolution.SESSION_REPLAY]: params.isReplaySelected,
  25. };
  26. };
  27. const getInstallSnippet = (params: Params) => `
  28. dependencies: {
  29. //...
  30. "@sentry/serverless": "^7",${
  31. params.isProfilingSelected
  32. ? `
  33. "@sentry/profiling-node": "^1",`
  34. : ''
  35. }
  36. //...
  37. }`;
  38. const getSdkSetupSnippet = (params: Params) => `
  39. ${getDefaulServerlessImports({productSelection: productSelection(params)}).join('\n')}
  40. Sentry.GCPFunction.init({
  41. dsn: "${params.dsn}",
  42. integrations: [${
  43. params.isProfilingSelected
  44. ? `
  45. nodeProfilingIntegration(),`
  46. : ''
  47. }
  48. ],${
  49. params.isPerformanceSelected
  50. ? `
  51. // Performance Monitoring
  52. tracesSampleRate: 1.0, // Capture 100% of the transactions`
  53. : ''
  54. }${
  55. params.isProfilingSelected
  56. ? `
  57. // Set sampling rate for profiling - this is relative to tracesSampleRate
  58. profilesSampleRate: 1.0,`
  59. : ''
  60. }
  61. });
  62. // Use wrapHttpFunction to instrument your http functions
  63. exports.helloHttp = Sentry.GCPFunction.wrapHttpFunction((req, res) => {
  64. /* Your function code */
  65. });
  66. // Use wrapEventFunction to instrument your background functions
  67. exports.helloEvents = Sentry.GCPFunction.wrapEventFunction(
  68. (data, context, callback) => {
  69. /* Your function code */
  70. }
  71. );
  72. // Use wrapCloudEventFunction to instrument your CloudEvent functions
  73. exports.helloEvents = Sentry.GCPFunction.wrapCloudEventFunction(
  74. (context, callback) => {
  75. /* Your function code */
  76. }
  77. );`;
  78. const getVerifySnippet = () => `
  79. exports.helloHttp = Sentry.GCPFunction.wrapHttpFunction((req, res) => {
  80. throw new Error("oh, hello there!");
  81. });`;
  82. const getMetricsConfigureSnippet = (params: DocsParams) => `
  83. Sentry.GCPFunction.init({
  84. dsn: "${params.dsn}",
  85. _experiments: {
  86. metricsAggregator: true,
  87. },
  88. });`;
  89. const onboarding: OnboardingConfig = {
  90. install: params => [
  91. {
  92. type: StepType.INSTALL,
  93. description: tct(
  94. 'Add the Sentry Serverless SDK as a dependency to your [code:package.json]:',
  95. {code: <code />}
  96. ),
  97. configurations: [
  98. {
  99. language: 'json',
  100. code: getInstallSnippet(params),
  101. },
  102. ],
  103. },
  104. ],
  105. configure: params => [
  106. {
  107. type: StepType.CONFIGURE,
  108. description: tct('Use the Sentry SDK to wrap your functions:', {
  109. code: <code />,
  110. }),
  111. configurations: [
  112. {
  113. language: 'javascript',
  114. code: getSdkSetupSnippet(params),
  115. },
  116. ],
  117. },
  118. getUploadSourceMapsStep({
  119. guideLink: 'https://docs.sentry.io/platforms/node/guides/gcp-functions/sourcemaps/',
  120. ...params,
  121. }),
  122. ],
  123. verify: () => [
  124. {
  125. type: StepType.VERIFY,
  126. description: t(
  127. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  128. ),
  129. configurations: [
  130. {
  131. language: 'javascript',
  132. code: getVerifySnippet(),
  133. },
  134. ],
  135. },
  136. ],
  137. };
  138. const customMetricsOnboarding: OnboardingConfig = {
  139. install: params => [
  140. {
  141. type: StepType.INSTALL,
  142. description: tct(
  143. 'You need a minimum version [codeVersion:7.91.0] of [codePackage:@sentry/serverless]:',
  144. {
  145. codeVersion: <code />,
  146. codePackage: <code />,
  147. }
  148. ),
  149. configurations: [{language: 'json', code: getInstallSnippet(params)}],
  150. },
  151. ],
  152. configure: params => [
  153. {
  154. type: StepType.CONFIGURE,
  155. description: tct(
  156. 'To enable capturing metrics, you first need to add the [codeIntegration:metricsAggregator] experiment to your [codeNamespace:Sentry.init] call in your main process.',
  157. {
  158. codeIntegration: <code />,
  159. codeNamespace: <code />,
  160. }
  161. ),
  162. configurations: [
  163. {
  164. code: [
  165. {
  166. label: 'JavaScript',
  167. value: 'javascript',
  168. language: 'javascript',
  169. code: getMetricsConfigureSnippet(params),
  170. },
  171. ],
  172. },
  173. ],
  174. },
  175. ],
  176. verify: getJSServerMetricsOnboarding().verify,
  177. };
  178. const crashReportOnboarding: OnboardingConfig = {
  179. introduction: () => getCrashReportModalIntroduction(),
  180. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  181. configure: () => [
  182. {
  183. type: StepType.CONFIGURE,
  184. description: getCrashReportModalConfigDescription({
  185. link: 'https://docs.sentry.io/platforms/node/guides/gcp-functions/user-feedback/configuration/#crash-report-modal',
  186. }),
  187. },
  188. ],
  189. verify: () => [],
  190. nextSteps: () => [],
  191. };
  192. const docs: Docs = {
  193. onboarding,
  194. customMetricsOnboarding,
  195. crashReportOnboarding,
  196. };
  197. export default docs;