chalice.tsx 2.8 KB

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