fastapi.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. }: {
  17. dsn?: string;
  18. } = {}): LayoutProps['steps'] => [
  19. {
  20. type: StepType.INSTALL,
  21. description: (
  22. <p>
  23. {tct(
  24. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentryFastApiCode:fastapi] extra:',
  25. {
  26. sentrySdkCode: <code />,
  27. sentryFastApiCode: <code />,
  28. }
  29. )}
  30. </p>
  31. ),
  32. configurations: [
  33. {
  34. language: 'bash',
  35. code: "pip install --upgrade 'sentry-sdk[fastapi]'",
  36. },
  37. ],
  38. },
  39. {
  40. type: StepType.CONFIGURE,
  41. description: t(
  42. 'To configure the Sentry SDK, initialize it before your app has been initialized:'
  43. ),
  44. configurations: [
  45. {
  46. language: 'python',
  47. code: `
  48. from fastapi import FastAPI
  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 = FastAPI()
  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 fastapi import FastAPI
  82. app = FastAPI()
  83. @app.get("/sentry-debug")
  84. async def trigger_error():
  85. division_by_zero = 1 / 0
  86. `,
  87. },
  88. ],
  89. additionalInfo: t(
  90. 'Visiting this route will trigger an error that will be captured by Sentry.'
  91. ),
  92. },
  93. ];
  94. // Configuration End
  95. export function GettingStartedWithFastApi({dsn, ...props}: ModuleProps) {
  96. return <Layout steps={steps({dsn})} introduction={introduction} {...props} />;
  97. }
  98. export default GettingStartedWithFastApi;