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