chalice.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  2. import {
  3. type Docs,
  4. DocsPageLocation,
  5. type DocsParams,
  6. type OnboardingConfig,
  7. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  8. import {getPythonMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  9. import {
  10. AlternativeConfiguration,
  11. crashReportOnboardingPython,
  12. } from 'sentry/gettingStartedDocs/python/python';
  13. import {t, tct} from 'sentry/locale';
  14. type Params = DocsParams;
  15. const getInstallSnippet = () => `pip install --upgrade 'sentry-sdk[chalice]'`;
  16. const getSdkSetupSnippet = (params: Params) => `
  17. import sentry_sdk
  18. from chalice import Chalice
  19. from sentry_sdk.integrations.chalice import ChaliceIntegration
  20. sentry_sdk.init(
  21. dsn="${params.dsn.public}",
  22. integrations=[ChaliceIntegration()],${
  23. params.isPerformanceSelected
  24. ? `
  25. # Set traces_sample_rate to 1.0 to capture 100%
  26. # of transactions for tracing.
  27. traces_sample_rate=1.0,`
  28. : ''
  29. }${
  30. params.isProfilingSelected &&
  31. params.profilingOptions?.defaultProfilingMode !== 'continuous'
  32. ? `
  33. # Set profiles_sample_rate to 1.0 to profile 100%
  34. # of sampled transactions.
  35. # We recommend adjusting this value in production.
  36. profiles_sample_rate=1.0,`
  37. : params.isProfilingSelected &&
  38. params.profilingOptions?.defaultProfilingMode === 'continuous'
  39. ? `
  40. _experiments={
  41. # Set continuous_profiling_auto_start to True
  42. # to automatically start the profiler on when
  43. # possible.
  44. "continuous_profiling_auto_start": True,
  45. },`
  46. : ''
  47. }
  48. )
  49. app = Chalice(app_name="appname")`;
  50. const getVerifySnippet = () => `
  51. @app.schedule(Rate(1, unit=Rate.MINUTES))
  52. def every_minute(event):
  53. 1/0 # raises an error
  54. @app.route("/")
  55. def index():
  56. 1/0 # raises an error
  57. return {"hello": "world"}`;
  58. const onboarding: OnboardingConfig = {
  59. install: (params: Params) => [
  60. {
  61. type: StepType.INSTALL,
  62. description: tct(
  63. 'Install [code:sentry-sdk] from PyPI with the [code:chalice] extra:',
  64. {
  65. code: <code />,
  66. }
  67. ),
  68. configurations: [
  69. {
  70. description:
  71. params.docsLocation === DocsPageLocation.PROFILING_PAGE
  72. ? tct(
  73. 'You need a minimum version [code:1.18.0] of the [code:sentry-python] SDK for the profiling feature.',
  74. {
  75. code: <code />,
  76. }
  77. )
  78. : undefined,
  79. language: 'bash',
  80. code: getInstallSnippet(),
  81. },
  82. ],
  83. },
  84. ],
  85. configure: (params: Params) => [
  86. {
  87. type: StepType.CONFIGURE,
  88. description: t(
  89. 'To configure the SDK, initialize it with the integration before or after your app has been initialized:'
  90. ),
  91. configurations: [
  92. {
  93. language: 'python',
  94. code: getSdkSetupSnippet(params),
  95. },
  96. ],
  97. additionalInfo: params.isProfilingSelected &&
  98. params.profilingOptions?.defaultProfilingMode === 'continuous' && (
  99. <AlternativeConfiguration />
  100. ),
  101. },
  102. ],
  103. verify: () => [
  104. {
  105. type: StepType.VERIFY,
  106. description: t('To verify that everything is working trigger an error on purpose:'),
  107. configurations: [
  108. {
  109. language: 'python',
  110. code: getVerifySnippet(),
  111. },
  112. ],
  113. additionalInfo: tct(
  114. 'When you enter the [code:"/"] route or the scheduled task is run, an error event will be sent to Sentry.',
  115. {
  116. code: <code />,
  117. }
  118. ),
  119. },
  120. ],
  121. };
  122. const docs: Docs = {
  123. onboarding,
  124. customMetricsOnboarding: getPythonMetricsOnboarding({
  125. installSnippet: getInstallSnippet(),
  126. }),
  127. crashReportOnboarding: crashReportOnboardingPython,
  128. };
  129. export default docs;