starlette.tsx 3.0 KB

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