serverless.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 {t, tct} from 'sentry/locale';
  11. type Params = DocsParams;
  12. const getInstallSnippet = () => `pip install --upgrade sentry-sdk`;
  13. const getSdkSetupSnippet = (params: Params) => `
  14. import sentry_sdk
  15. from sentry_sdk.integrations.serverless import serverless_function
  16. sentry_sdk.init(
  17. dsn="${params.dsn}",${
  18. params.isPerformanceSelected
  19. ? `
  20. # Set traces_sample_rate to 1.0 to capture 100%
  21. # of transactions for performance monitoring.
  22. traces_sample_rate=1.0,`
  23. : ''
  24. }${
  25. params.isProfilingSelected
  26. ? `
  27. # Set profiles_sample_rate to 1.0 to profile 100%
  28. # of sampled transactions.
  29. # We recommend adjusting this value in production.
  30. profiles_sample_rate=1.0,`
  31. : ''
  32. }
  33. )
  34. @serverless_function
  35. def my_function(...): ...`;
  36. const getVerifySnippet = () => `import sentry_sdk
  37. from sentry_sdk.integrations.serverless import serverless_function
  38. sentry_sdk.init(...) # same as above
  39. @serverless_function
  40. def my_function(...):
  41. 1/0 # raises an error`;
  42. const onboarding: OnboardingConfig = {
  43. introduction: () => (
  44. <Fragment>
  45. <p>
  46. {tct(
  47. '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.',
  48. {
  49. link: (
  50. <ExternalLink href="https://docs.sentry.io/platforms/python/#serverless" />
  51. ),
  52. }
  53. )}
  54. </p>
  55. {t(
  56. 'If you use a serverless provider not directly supported by the SDK, you can use this generic integration.'
  57. )}
  58. </Fragment>
  59. ),
  60. install: () => [
  61. {
  62. type: StepType.INSTALL,
  63. description: tct('Install our Python SDK using [code:pip]:', {
  64. code: <code />,
  65. }),
  66. configurations: [
  67. {
  68. language: 'bash',
  69. code: getInstallSnippet(),
  70. },
  71. ],
  72. },
  73. ],
  74. configure: (params: Params) => [
  75. {
  76. type: StepType.CONFIGURE,
  77. description: tct(
  78. 'Apply the [code:serverless_function] decorator to each function that might throw errors:',
  79. {code: <code />}
  80. ),
  81. configurations: [
  82. {
  83. language: 'python',
  84. code: getSdkSetupSnippet(params),
  85. },
  86. ],
  87. },
  88. ],
  89. verify: () => [
  90. {
  91. type: StepType.VERIFY,
  92. description: tct(
  93. 'Wrap a functions with the [code:serverless_function] that triggers an error:',
  94. {
  95. code: <code />,
  96. }
  97. ),
  98. configurations: [
  99. {
  100. language: 'python',
  101. code: getVerifySnippet(),
  102. },
  103. ],
  104. additionalInfo: tct(
  105. 'Now deploy your function. When you now run your function an error event will be sent to Sentry.',
  106. {}
  107. ),
  108. },
  109. ],
  110. };
  111. const docs: Docs = {
  112. onboarding,
  113. customMetricsOnboarding: getPythonMetricsOnboarding({
  114. installSnippet: getInstallSnippet(),
  115. }),
  116. };
  117. export default docs;