serverless.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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}",${
  19. params.isPerformanceSelected
  20. ? `
  21. # Set traces_sample_rate to 1.0 to capture 100%
  22. # of transactions for performance monitoring.
  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: () => [
  62. {
  63. type: StepType.INSTALL,
  64. description: tct('Install our Python SDK using [code:pip]:', {
  65. code: <code />,
  66. }),
  67. configurations: [
  68. {
  69. language: 'bash',
  70. code: getInstallSnippet(),
  71. },
  72. ],
  73. },
  74. ],
  75. configure: (params: Params) => [
  76. {
  77. type: StepType.CONFIGURE,
  78. description: tct(
  79. 'Apply the [code:serverless_function] decorator to each function that might throw errors:',
  80. {code: <code />}
  81. ),
  82. configurations: [
  83. {
  84. language: 'python',
  85. code: getSdkSetupSnippet(params),
  86. },
  87. ],
  88. },
  89. ],
  90. verify: () => [
  91. {
  92. type: StepType.VERIFY,
  93. description: tct(
  94. 'Wrap a functions with the [code:serverless_function] that triggers an error:',
  95. {
  96. code: <code />,
  97. }
  98. ),
  99. configurations: [
  100. {
  101. language: 'python',
  102. code: getVerifySnippet(),
  103. },
  104. ],
  105. additionalInfo: tct(
  106. 'Now deploy your function. When you now run your function an error event will be sent to Sentry.',
  107. {}
  108. ),
  109. },
  110. ],
  111. };
  112. const docs: Docs = {
  113. onboarding,
  114. customMetricsOnboarding: getPythonMetricsOnboarding({
  115. installSnippet: getInstallSnippet(),
  116. }),
  117. crashReportOnboarding: crashReportOnboardingPython,
  118. };
  119. export default docs;