fastapi.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 = (
  8. <p>
  9. {tct('The FastAPI integration adds support for the [link:FastAPI Framework].', {
  10. link: <ExternalLink href="https://fastapi.tiangolo.com/" />,
  11. })}
  12. </p>
  13. );
  14. export const steps = ({
  15. dsn,
  16. }: Partial<Pick<ModuleProps, 'dsn'>> = {}): LayoutProps['steps'] => [
  17. {
  18. type: StepType.INSTALL,
  19. description: (
  20. <p>
  21. {tct(
  22. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentryFastApiCode:fastapi] extra:',
  23. {
  24. sentrySdkCode: <code />,
  25. sentryFastApiCode: <code />,
  26. }
  27. )}
  28. </p>
  29. ),
  30. configurations: [
  31. {
  32. language: 'bash',
  33. code: "pip install --upgrade 'sentry-sdk[fastapi]'",
  34. },
  35. ],
  36. },
  37. {
  38. type: StepType.CONFIGURE,
  39. description: t(
  40. 'To configure the Sentry SDK, initialize it before your app has been initialized:'
  41. ),
  42. configurations: [
  43. {
  44. language: 'python',
  45. code: `
  46. from fastapi import FastAPI
  47. import sentry_sdk
  48. sentry_sdk.init(
  49. dsn="${dsn}",
  50. # Set traces_sample_rate to 1.0 to capture 100%
  51. # of transactions for performance monitoring.
  52. # We recommend adjusting this value in production,
  53. traces_sample_rate=1.0,
  54. )
  55. app = FastAPI()
  56. `,
  57. },
  58. ],
  59. additionalInfo: (
  60. <p>
  61. {tct(
  62. '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.',
  63. {
  64. code: <code />,
  65. }
  66. )}
  67. </p>
  68. ),
  69. },
  70. {
  71. type: StepType.VERIFY,
  72. description: t(
  73. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  74. ),
  75. configurations: [
  76. {
  77. language: 'python',
  78. code: `
  79. from fastapi import FastAPI
  80. app = FastAPI()
  81. @app.get("/sentry-debug")
  82. async def trigger_error():
  83. division_by_zero = 1 / 0
  84. `,
  85. },
  86. ],
  87. additionalInfo: t(
  88. 'Visiting this route will trigger an error that will be captured by Sentry.'
  89. ),
  90. },
  91. ];
  92. // Configuration End
  93. export function GettingStartedWithFastApi({dsn, ...props}: ModuleProps) {
  94. return <Layout steps={steps({dsn})} introduction={introduction} {...props} />;
  95. }
  96. export default GettingStartedWithFastApi;