starlette.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  3. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  4. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  5. import {t, tct} from 'sentry/locale';
  6. // Configuration Start
  7. const introduction = tct(
  8. 'The Starlette integration adds support for the Starlette Framework.',
  9. {
  10. link: <ExternalLink href="https://www.starlette.io/" />,
  11. }
  12. );
  13. export const steps = ({
  14. dsn,
  15. }: Partial<Pick<ModuleProps, 'dsn'>> = {}): LayoutProps['steps'] => [
  16. {
  17. type: StepType.INSTALL,
  18. description: (
  19. <p>
  20. {tct(
  21. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentryStarletteCode:starlette] extra:',
  22. {
  23. sentrySdkCode: <code />,
  24. sentryStarletteCode: <code />,
  25. }
  26. )}
  27. </p>
  28. ),
  29. configurations: [
  30. {
  31. language: 'bash',
  32. code: "pip install --upgrade 'sentry-sdk[starlette]'",
  33. },
  34. ],
  35. },
  36. {
  37. type: StepType.CONFIGURE,
  38. description: (
  39. <p>
  40. {tct(
  41. 'To configure the SDK, initialize it before your app has been initialized. The Sentry SDK automatically enables support for Starlette if you have the [code:starlette] Python package installed in your project. There are no configuration options you need to add when initializing the Sentry SDK as everything works out of the box:',
  42. {code: <code />}
  43. )}
  44. </p>
  45. ),
  46. configurations: [
  47. {
  48. language: 'python',
  49. code: `
  50. from starlette.applications import Starlette
  51. import sentry_sdk
  52. sentry_sdk.init(
  53. dsn="${dsn}",
  54. # Set traces_sample_rate to 1.0 to capture 100%
  55. # of transactions for performance monitoring.
  56. # We recommend adjusting this value in production,
  57. traces_sample_rate=1.0,
  58. )
  59. app = Starlette(routes=[...])
  60. `,
  61. },
  62. ],
  63. additionalInfo: (
  64. <p>
  65. {tct(
  66. 'The above configuration captures both error and performance data. To reduce the volume of performance data captured, change [code:traces_sample_rate] to a value between 0 and 1.',
  67. {
  68. code: <code />,
  69. }
  70. )}
  71. </p>
  72. ),
  73. },
  74. {
  75. type: StepType.VERIFY,
  76. description: t(
  77. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  78. ),
  79. configurations: [
  80. {
  81. language: 'python',
  82. code: `
  83. from starlette.applications import Starlette
  84. from starlette.routing import Route
  85. async def trigger_error(request):
  86. division_by_zero = 1 / 0
  87. app = Starlette(routes=[
  88. Route("/sentry-debug", trigger_error),
  89. ])
  90. `,
  91. additionalInfo: t(
  92. 'Visiting this route will trigger an error that will be captured by Sentry.'
  93. ),
  94. },
  95. ],
  96. },
  97. ];
  98. // Configuration End
  99. export function GettingStartedWithStarlette({dsn, ...props}: ModuleProps) {
  100. return <Layout steps={steps({dsn})} introduction={introduction} {...props} />;
  101. }
  102. export default GettingStartedWithStarlette;