starlette.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. }: {
  16. dsn?: string;
  17. } = {}): LayoutProps['steps'] => [
  18. {
  19. type: StepType.INSTALL,
  20. description: (
  21. <p>
  22. {tct(
  23. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentryStarletteCode:starlette] extra:',
  24. {
  25. sentrySdkCode: <code />,
  26. sentryStarletteCode: <code />,
  27. }
  28. )}
  29. </p>
  30. ),
  31. configurations: [
  32. {
  33. language: 'bash',
  34. code: "pip install --upgrade 'sentry-sdk[starlette]'",
  35. },
  36. ],
  37. },
  38. {
  39. type: StepType.CONFIGURE,
  40. description: (
  41. <p>
  42. {tct(
  43. '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:',
  44. {code: <code />}
  45. )}
  46. </p>
  47. ),
  48. configurations: [
  49. {
  50. language: 'python',
  51. code: `
  52. from starlette.applications import Starlette
  53. import sentry_sdk
  54. sentry_sdk.init(
  55. dsn="${dsn}",
  56. # Set traces_sample_rate to 1.0 to capture 100%
  57. # of transactions for performance monitoring.
  58. # We recommend adjusting this value in production,
  59. traces_sample_rate=1.0,
  60. )
  61. app = Starlette(routes=[...])
  62. `,
  63. },
  64. ],
  65. additionalInfo: (
  66. <p>
  67. {tct(
  68. '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.',
  69. {
  70. code: <code />,
  71. }
  72. )}
  73. </p>
  74. ),
  75. },
  76. {
  77. type: StepType.VERIFY,
  78. description: t(
  79. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  80. ),
  81. configurations: [
  82. {
  83. language: 'python',
  84. code: `
  85. from starlette.applications import Starlette
  86. from starlette.routing import Route
  87. async def trigger_error(request):
  88. division_by_zero = 1 / 0
  89. app = Starlette(routes=[
  90. Route("/sentry-debug", trigger_error),
  91. ])
  92. `,
  93. additionalInfo: t(
  94. 'Visiting this route will trigger an error that will be captured by Sentry.'
  95. ),
  96. },
  97. ],
  98. },
  99. ];
  100. // Configuration End
  101. export function GettingStartedWithStarlette({dsn, ...props}: ModuleProps) {
  102. return <Layout steps={steps({dsn})} introduction={introduction} {...props} />;
  103. }
  104. export default GettingStartedWithStarlette;