gcpfunctions.tsx 4.5 KB

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