asgi.tsx 2.0 KB

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