chalice.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  2. import type {
  3. Docs,
  4. DocsParams,
  5. OnboardingConfig,
  6. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  7. import {getPythonMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  8. import {crashReportOnboardingPython} from 'sentry/gettingStartedDocs/python/python';
  9. import {t, tct} from 'sentry/locale';
  10. type Params = DocsParams;
  11. const getInstallSnippet = () => `pip install --upgrade 'sentry-sdk[chalice]'`;
  12. const getSdkSetupSnippet = (params: Params) => `
  13. import sentry_sdk
  14. from chalice import Chalice
  15. from sentry_sdk.integrations.chalice import ChaliceIntegration
  16. sentry_sdk.init(
  17. dsn="${params.dsn}",
  18. integrations=[ChaliceIntegration()],${
  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. app = Chalice(app_name="appname")`;
  36. const getVerifySnippet = () => `
  37. @app.schedule(Rate(1, unit=Rate.MINUTES))
  38. def every_minute(event):
  39. 1/0 # raises an error
  40. @app.route("/")
  41. def index():
  42. 1/0 # raises an error
  43. return {"hello": "world"}`;
  44. const onboarding: OnboardingConfig = {
  45. install: () => [
  46. {
  47. type: StepType.INSTALL,
  48. description: tct(
  49. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentryBotteCode:chalice] extra:',
  50. {
  51. sentrySdkCode: <code />,
  52. sentryBotteCode: <code />,
  53. }
  54. ),
  55. configurations: [
  56. {
  57. language: 'bash',
  58. code: getInstallSnippet(),
  59. },
  60. ],
  61. },
  62. ],
  63. configure: (params: Params) => [
  64. {
  65. type: StepType.CONFIGURE,
  66. description: t(
  67. 'To configure the SDK, initialize it with the integration before or after your app has been initialized:'
  68. ),
  69. configurations: [
  70. {
  71. language: 'python',
  72. code: getSdkSetupSnippet(params),
  73. },
  74. ],
  75. },
  76. ],
  77. verify: () => [
  78. {
  79. type: StepType.VERIFY,
  80. description: t('To verify that everything is working trigger an error on purpose:'),
  81. configurations: [
  82. {
  83. language: 'python',
  84. code: getVerifySnippet(),
  85. },
  86. ],
  87. additionalInfo: tct(
  88. 'When you enter the [code:"/"] route or the scheduled task is run, an error event will be sent to Sentry.',
  89. {
  90. code: <code />,
  91. }
  92. ),
  93. },
  94. ],
  95. };
  96. const docs: Docs = {
  97. onboarding,
  98. customMetricsOnboarding: getPythonMetricsOnboarding({
  99. installSnippet: getInstallSnippet(),
  100. }),
  101. crashReportOnboarding: crashReportOnboardingPython,
  102. };
  103. export default docs;