serverless.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import type {
  5. Docs,
  6. DocsParams,
  7. OnboardingConfig,
  8. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  9. import {getPythonMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  10. import {crashReportOnboardingPython} from 'sentry/gettingStartedDocs/python/python';
  11. import {t, tct} from 'sentry/locale';
  12. type Params = DocsParams;
  13. const getInstallSnippet = () => `pip install --upgrade sentry-sdk`;
  14. const getSdkSetupSnippet = (params: Params) => `
  15. import sentry_sdk
  16. from sentry_sdk.integrations.serverless import serverless_function
  17. sentry_sdk.init(
  18. dsn="${params.dsn.public}",${
  19. params.isPerformanceSelected
  20. ? `
  21. # Set traces_sample_rate to 1.0 to capture 100%
  22. # of transactions for tracing.
  23. traces_sample_rate=1.0,`
  24. : ''
  25. }${
  26. params.isProfilingSelected
  27. ? `
  28. # Set profiles_sample_rate to 1.0 to profile 100%
  29. # of sampled transactions.
  30. # We recommend adjusting this value in production.
  31. profiles_sample_rate=1.0,`
  32. : ''
  33. }
  34. )
  35. @serverless_function
  36. def my_function(...): ...`;
  37. const getVerifySnippet = () => `import sentry_sdk
  38. from sentry_sdk.integrations.serverless import serverless_function
  39. sentry_sdk.init(...) # same as above
  40. @serverless_function
  41. def my_function(...):
  42. 1/0 # raises an error`;
  43. const onboarding: OnboardingConfig = {
  44. introduction: () => (
  45. <Fragment>
  46. <p>
  47. {tct(
  48. 'It is recommended to use an [link:integration for your particular serverless environment if available], as those are easier to use and capture more useful information.',
  49. {
  50. link: (
  51. <ExternalLink href="https://docs.sentry.io/platforms/python/#serverless" />
  52. ),
  53. }
  54. )}
  55. </p>
  56. {t(
  57. 'If you use a serverless provider not directly supported by the SDK, you can use this generic integration.'
  58. )}
  59. </Fragment>
  60. ),
  61. install: (params: Params) => [
  62. {
  63. type: StepType.INSTALL,
  64. description: tct('Install our Python SDK using [code:pip]:', {
  65. code: <code />,
  66. }),
  67. configurations: [
  68. {
  69. description: params.isProfilingSelected
  70. ? tct(
  71. 'You need a minimum version [codeVersion:1.18.0] of the [codePackage:sentry-python] SDK for the profiling feature.',
  72. {
  73. codeVersion: <code />,
  74. codePackage: <code />,
  75. }
  76. )
  77. : undefined,
  78. language: 'bash',
  79. code: getInstallSnippet(),
  80. },
  81. ],
  82. },
  83. ],
  84. configure: (params: Params) => [
  85. {
  86. type: StepType.CONFIGURE,
  87. description: tct(
  88. 'Apply the [code:serverless_function] decorator to each function that might throw errors:',
  89. {code: <code />}
  90. ),
  91. configurations: [
  92. {
  93. language: 'python',
  94. code: getSdkSetupSnippet(params),
  95. },
  96. ],
  97. },
  98. ],
  99. verify: () => [
  100. {
  101. type: StepType.VERIFY,
  102. description: tct(
  103. 'Wrap a functions with the [code:serverless_function] that triggers an error:',
  104. {
  105. code: <code />,
  106. }
  107. ),
  108. configurations: [
  109. {
  110. language: 'python',
  111. code: getVerifySnippet(),
  112. },
  113. ],
  114. additionalInfo: tct(
  115. 'Now deploy your function. When you now run your function an error event will be sent to Sentry.',
  116. {}
  117. ),
  118. },
  119. ],
  120. };
  121. const docs: Docs = {
  122. onboarding,
  123. customMetricsOnboarding: getPythonMetricsOnboarding({
  124. installSnippet: getInstallSnippet(),
  125. }),
  126. crashReportOnboarding: crashReportOnboardingPython,
  127. };
  128. export default docs;