gcpfunctions.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import Alert from 'sentry/components/alert';
  4. import ExternalLink from 'sentry/components/links/externalLink';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import {
  7. type Docs,
  8. DocsPageLocation,
  9. type DocsParams,
  10. type OnboardingConfig,
  11. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  12. import {getPythonMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  13. import {
  14. AlternativeConfiguration,
  15. crashReportOnboardingPython,
  16. } from 'sentry/gettingStartedDocs/python/python';
  17. import {t, tct} from 'sentry/locale';
  18. import {space} from 'sentry/styles/space';
  19. type Params = DocsParams;
  20. const getInstallSnippet = () => `pip install --upgrade sentry-sdk`;
  21. const getSdkSetupSnippet = (params: Params) => `
  22. import sentry_sdk
  23. from sentry_sdk.integrations.gcp import GcpIntegration
  24. sentry_sdk.init(
  25. dsn="${params.dsn.public}",
  26. integrations=[GcpIntegration()],${
  27. params.isPerformanceSelected
  28. ? `
  29. # Set traces_sample_rate to 1.0 to capture 100%
  30. # of transactions for tracing.
  31. traces_sample_rate=1.0,`
  32. : ''
  33. }${
  34. params.isProfilingSelected &&
  35. params.profilingOptions?.defaultProfilingMode === 'transaction'
  36. ? `
  37. # Set profiles_sample_rate to 1.0 to profile 100%
  38. # of sampled transactions.
  39. # We recommend adjusting this value in production.
  40. profiles_sample_rate=1.0,`
  41. : params.isProfilingSelected &&
  42. params.profilingOptions?.defaultProfilingMode === 'continuous'
  43. ? `
  44. _experiments={
  45. # Set continuous_profiling_auto_start to True
  46. # to automatically start the profiler on when
  47. # possible.
  48. "continuous_profiling_auto_start": True,
  49. },`
  50. : ''
  51. }
  52. )
  53. def http_function_entrypoint(request):
  54. ...`;
  55. const getTimeoutWarningSnippet = (params: Params) => `
  56. sentry_sdk.init(
  57. dsn="${params.dsn.public}",
  58. integrations=[
  59. GcpIntegration(timeout_warning=True),
  60. ],
  61. )`;
  62. const onboarding: OnboardingConfig = {
  63. install: (params: Params) => [
  64. {
  65. type: StepType.INSTALL,
  66. description: (
  67. <p>{tct('Install our Python SDK using [code:pip]:', {code: <code />})}</p>
  68. ),
  69. configurations: [
  70. {
  71. description:
  72. params.docsLocation === DocsPageLocation.PROFILING_PAGE
  73. ? tct(
  74. 'You need a minimum version [code:1.18.0] of the [code:sentry-python] SDK for the profiling feature.',
  75. {
  76. code: <code />,
  77. }
  78. )
  79. : undefined,
  80. language: 'bash',
  81. code: getInstallSnippet(),
  82. },
  83. ],
  84. },
  85. ],
  86. configure: (params: Params) => [
  87. {
  88. type: StepType.CONFIGURE,
  89. description: t(
  90. 'You can use the Google Cloud Functions integration for the Python SDK like this:'
  91. ),
  92. configurations: [
  93. {
  94. language: 'python',
  95. code: getSdkSetupSnippet(params),
  96. },
  97. ],
  98. additionalInfo: (
  99. <Fragment>
  100. {params.isProfilingSelected &&
  101. params.profilingOptions?.defaultProfilingMode === 'continuous' && (
  102. <Fragment>
  103. <AlternativeConfiguration />
  104. <br />
  105. </Fragment>
  106. )}
  107. {tct("Check out Sentry's [link:GCP sample apps] for detailed examples.", {
  108. link: (
  109. <ExternalLink href="https://github.com/getsentry/examples/tree/master/gcp-cloud-functions" />
  110. ),
  111. })}
  112. </Fragment>
  113. ),
  114. },
  115. {
  116. title: t('Timeout Warning'),
  117. description: tct(
  118. 'The timeout warning reports an issue when the function execution time is near the [link:configured timeout].',
  119. {
  120. link: (
  121. <ExternalLink href="https://cloud.google.com/functions/docs/concepts/execution-environment#timeout" />
  122. ),
  123. }
  124. ),
  125. configurations: [
  126. {
  127. description: tct(
  128. 'To enable the warning, update the SDK initialization to set [code:timeout_warning] to [code:true]:',
  129. {code: <code />}
  130. ),
  131. language: 'python',
  132. code: getTimeoutWarningSnippet(params),
  133. },
  134. {
  135. description: t(
  136. 'The timeout warning is sent only if the timeout in the Cloud Function configuration is set to a value greater than one second.'
  137. ),
  138. },
  139. ],
  140. additionalInfo: (
  141. <AlertWithMarginBottom type="info">
  142. {tct(
  143. 'If you are using a web framework in your Cloud Function, the framework might catch those exceptions before we get to see them. Make sure to enable the framework specific integration as well, if one exists. See [link:Integrations] for more information.',
  144. {
  145. link: (
  146. <ExternalLink href="https://docs.sentry.io/platforms/python/#integrations" />
  147. ),
  148. }
  149. )}
  150. </AlertWithMarginBottom>
  151. ),
  152. },
  153. ],
  154. verify: () => [],
  155. };
  156. const docs: Docs = {
  157. onboarding,
  158. customMetricsOnboarding: getPythonMetricsOnboarding({
  159. installSnippet: getInstallSnippet(),
  160. }),
  161. crashReportOnboarding: crashReportOnboardingPython,
  162. };
  163. export default docs;
  164. const AlertWithMarginBottom = styled(Alert)`
  165. margin-top: ${space(2)};
  166. margin-bottom: 0;
  167. `;