gcpfunctions.tsx 3.8 KB

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