starlette.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  3. import type {
  4. Docs,
  5. DocsParams,
  6. OnboardingConfig,
  7. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  8. import {getPythonMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  9. import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  10. import {t, tct} from 'sentry/locale';
  11. type Params = DocsParams;
  12. const getInstallSnippet = () => `pip install --upgrade sentry-sdk[starlette]`;
  13. const getSdkSetupSnippet = (params: Params) => `from starlette.applications import Starlette
  14. import sentry_sdk
  15. sentry_sdk.init(
  16. dsn="${params.dsn}",${
  17. params.isPerformanceSelected
  18. ? `
  19. # Set traces_sample_rate to 1.0 to capture 100%
  20. # of transactions for performance monitoring.
  21. traces_sample_rate=1.0,`
  22. : ''
  23. }${
  24. params.isProfilingSelected
  25. ? `
  26. # Set profiles_sample_rate to 1.0 to profile 100%
  27. # of sampled transactions.
  28. # We recommend adjusting this value in production.
  29. profiles_sample_rate=1.0,`
  30. : ''
  31. }
  32. )
  33. `;
  34. const onboarding: OnboardingConfig = {
  35. introduction: () =>
  36. tct('The Starlette integration adds support for the Starlette Framework.', {
  37. link: <ExternalLink href="https://www.starlette.io/" />,
  38. }),
  39. install: () => [
  40. {
  41. type: StepType.INSTALL,
  42. description: tct(
  43. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentryStarletteCode:starlette] extra:',
  44. {
  45. sentrySdkCode: <code />,
  46. sentryStarletteCode: <code />,
  47. }
  48. ),
  49. configurations: [
  50. {
  51. language: 'bash',
  52. code: getInstallSnippet(),
  53. },
  54. ],
  55. },
  56. ],
  57. configure: (params: Params) => [
  58. {
  59. type: StepType.CONFIGURE,
  60. description: tct(
  61. 'If you have the [codeStarlette:starlette] package in your dependencies, the Starlette integration will be enabled automatically when you initialize the Sentry SDK. Initialize the Sentry SDK before your app has been initialized:',
  62. {
  63. codeStarlette: <code />,
  64. }
  65. ),
  66. configurations: [
  67. {
  68. language: 'python',
  69. code: `${getSdkSetupSnippet(params)}
  70. app = Starlette(routes=[...])
  71. `,
  72. },
  73. ],
  74. },
  75. ],
  76. verify: (params: Params) => [
  77. {
  78. type: StepType.VERIFY,
  79. description: t(
  80. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  81. ),
  82. configurations: [
  83. {
  84. language: 'python',
  85. code: `
  86. from starlette.routing import Route
  87. ${getSdkSetupSnippet(params)}
  88. async def trigger_error(request):
  89. division_by_zero = 1 / 0
  90. app = Starlette(routes=[
  91. Route("/sentry-debug", trigger_error),
  92. ])
  93. `,
  94. },
  95. ],
  96. additionalInfo: (
  97. <div>
  98. <p>
  99. {tct(
  100. 'When you point your browser to [link:http://localhost:8000/sentry-debug/] a transaction in the Performance section of Sentry will be created.',
  101. {
  102. link: <ExternalLink href="http://localhost:8000/sentry-debug/" />,
  103. }
  104. )}
  105. </p>
  106. <p>
  107. {t(
  108. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  109. )}
  110. </p>
  111. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  112. </div>
  113. ),
  114. },
  115. ],
  116. nextSteps: () => [],
  117. };
  118. const docs: Docs = {
  119. onboarding,
  120. replayOnboardingJsLoader,
  121. customMetricsOnboarding: getPythonMetricsOnboarding({
  122. installSnippet: getInstallSnippet(),
  123. }),
  124. };
  125. export default docs;