gcpfunctions.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  5. import {PlatformKey} from 'sentry/data/platformCategories';
  6. import {t, tct} from 'sentry/locale';
  7. import type {Organization} from 'sentry/types';
  8. type StepProps = {
  9. newOrg: boolean;
  10. organization: Organization;
  11. platformKey: PlatformKey;
  12. projectId: string;
  13. sentryInitContent: string;
  14. };
  15. const performanceOtherConfig = `// Performance Monitoring
  16. tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!`;
  17. export const steps = ({
  18. sentryInitContent,
  19. ...props
  20. }: Partial<StepProps> = {}): LayoutProps['steps'] => [
  21. {
  22. type: StepType.INSTALL,
  23. description: (
  24. <p>
  25. {tct(
  26. 'Add the Sentry Serverless SDK as a dependency to your [code:package.json]:',
  27. {code: <code />}
  28. )}
  29. </p>
  30. ),
  31. configurations: [
  32. {
  33. language: 'json',
  34. code: `
  35. dependencies: {
  36. //...
  37. "@sentry/serverless": "^7"
  38. }
  39. `,
  40. },
  41. ],
  42. },
  43. {
  44. title: t('Configure SDK for Http Functions'),
  45. description: (
  46. <p>
  47. {tct('Use [code:wrapHttpFunction] to wrap your http function:', {
  48. code: <code />,
  49. })}
  50. </p>
  51. ),
  52. configurations: [
  53. {
  54. language: 'javascript',
  55. code: `
  56. const Sentry = require("@sentry/serverless");
  57. Sentry.GCPFunction.init({
  58. ${sentryInitContent}
  59. });
  60. exports.helloHttp = Sentry.GCPFunction.wrapHttpFunction((req, res) => {
  61. /* Your function code */
  62. });
  63. `,
  64. },
  65. ],
  66. },
  67. {
  68. title: t('Configure SDK for Background Functions'),
  69. description: (
  70. <p>
  71. {tct('Use [code:wrapEventFunction] to wrap your background function:', {
  72. code: <code />,
  73. })}
  74. </p>
  75. ),
  76. configurations: [
  77. {
  78. language: 'javascript',
  79. code: `
  80. const Sentry = require("@sentry/serverless");
  81. Sentry.GCPFunction.init({
  82. ${sentryInitContent}
  83. });
  84. exports.helloEvents = Sentry.GCPFunction.wrapEventFunction(
  85. (data, context, callback) => {
  86. /* Your function code */
  87. }
  88. );
  89. `,
  90. },
  91. ],
  92. },
  93. {
  94. title: t('Configure SDK for CloudEvent Functions'),
  95. description: (
  96. <p>
  97. {tct('Use [code:wrapCloudEventFunction] to wrap your CloudEvent function:', {
  98. code: <code />,
  99. })}
  100. </p>
  101. ),
  102. configurations: [
  103. {
  104. language: 'javascript',
  105. code: `
  106. const Sentry = require("@sentry/serverless");
  107. Sentry.GCPFunction.init({
  108. ${sentryInitContent}
  109. });
  110. exports.helloEvents = Sentry.GCPFunction.wrapCloudEventFunction(
  111. (context, callback) => {
  112. /* Your function code */
  113. }
  114. );
  115. `,
  116. },
  117. ],
  118. },
  119. getUploadSourceMapsStep({
  120. guideLink: 'https://docs.sentry.io/platforms/node/guides/express/sourcemaps/',
  121. ...props,
  122. }),
  123. {
  124. type: StepType.VERIFY,
  125. description: t(
  126. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  127. ),
  128. configurations: [
  129. {
  130. language: 'javascript',
  131. code: `
  132. exports.helloHttp = Sentry.GCPFunction.wrapHttpFunction((req, res) => {
  133. throw new Error("oh, hello there!");
  134. });
  135. `,
  136. },
  137. ],
  138. },
  139. ];
  140. export function GettingStartedWithGCPFunctions({
  141. dsn,
  142. organization,
  143. newOrg,
  144. platformKey,
  145. projectId,
  146. }: ModuleProps) {
  147. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  148. const otherConfigs = [performanceOtherConfig];
  149. if (otherConfigs.length > 0) {
  150. sentryInitContent = sentryInitContent.concat(otherConfigs);
  151. }
  152. return (
  153. <Layout
  154. steps={steps({
  155. sentryInitContent: sentryInitContent.join('\n'),
  156. organization,
  157. newOrg,
  158. platformKey,
  159. projectId,
  160. })}
  161. newOrg={newOrg}
  162. platformKey={platformKey}
  163. />
  164. );
  165. }
  166. export default GettingStartedWithGCPFunctions;