asgi.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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(
  10. 'The ASGI middleware can be used to instrument any [link:ASGI-compatible web framework] to attach request data for your events.',
  11. {
  12. link: <ExternalLink href="https://asgi.readthedocs.io/en/latest/" />,
  13. }
  14. )}
  15. </p>
  16. );
  17. export const steps = ({
  18. dsn,
  19. }: Partial<Pick<ModuleProps, 'dsn'>> = {}): LayoutProps['steps'] => [
  20. {
  21. type: StepType.CONFIGURE,
  22. description: (
  23. <p>
  24. {tct(
  25. 'This can be used to instrument, for example [starletteLink:Starlette] or [djangoLink:Django Channels 2.0].',
  26. {
  27. starletteLink: <ExternalLink href="https://www.starlette.io/middleware/" />,
  28. djangoLink: (
  29. <ExternalLink href="https://channels.readthedocs.io/en/latest/" />
  30. ),
  31. }
  32. )}
  33. </p>
  34. ),
  35. configurations: [
  36. {
  37. language: 'python',
  38. code: `
  39. import sentry_sdk
  40. from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
  41. from myapp import asgi_app
  42. sentry_sdk.init(
  43. dsn="${dsn}",
  44. # Set traces_sample_rate to 1.0 to capture 100%
  45. # of transactions for performance monitoring.
  46. # We recommend adjusting this value in production,
  47. traces_sample_rate=1.0,
  48. )
  49. asgi_app = SentryAsgiMiddleware(asgi_app)
  50. `,
  51. },
  52. ],
  53. additionalInfo: t('The middleware supports both ASGI 2 and ASGI 3 transparently.'),
  54. },
  55. ];
  56. // Configuration End
  57. export function GettingStartedWithASGI({dsn, ...props}: ModuleProps) {
  58. return <Layout steps={steps({dsn})} introduction={introduction} {...props} />;
  59. }
  60. export default GettingStartedWithASGI;