chalice.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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: (params: Params) => [
  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. description: params.isProfilingSelected
  58. ? tct(
  59. 'You need a minimum version [codeVersion:1.18.0] of the [codePackage:sentry-python] SDK for the profiling feature.',
  60. {
  61. codeVersion: <code />,
  62. codePackage: <code />,
  63. }
  64. )
  65. : undefined,
  66. language: 'bash',
  67. code: getInstallSnippet(),
  68. },
  69. ],
  70. },
  71. ],
  72. configure: (params: Params) => [
  73. {
  74. type: StepType.CONFIGURE,
  75. description: t(
  76. 'To configure the SDK, initialize it with the integration before or after your app has been initialized:'
  77. ),
  78. configurations: [
  79. {
  80. language: 'python',
  81. code: getSdkSetupSnippet(params),
  82. },
  83. ],
  84. },
  85. ],
  86. verify: () => [
  87. {
  88. type: StepType.VERIFY,
  89. description: t('To verify that everything is working trigger an error on purpose:'),
  90. configurations: [
  91. {
  92. language: 'python',
  93. code: getVerifySnippet(),
  94. },
  95. ],
  96. additionalInfo: tct(
  97. 'When you enter the [code:"/"] route or the scheduled task is run, an error event will be sent to Sentry.',
  98. {
  99. code: <code />,
  100. }
  101. ),
  102. },
  103. ],
  104. };
  105. const docs: Docs = {
  106. onboarding,
  107. customMetricsOnboarding: getPythonMetricsOnboarding({
  108. installSnippet: getInstallSnippet(),
  109. }),
  110. crashReportOnboarding: crashReportOnboardingPython,
  111. };
  112. export default docs;