gcpfunctions.tsx 4.6 KB

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