aiohttp.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 AIOHTTP integration adds support for the [link:AIOHTTP-Server Web Framework]. A Python version of 3.6 or greater is required.',
  11. {
  12. link: <ExternalLink href="https://docs.aiohttp.org/en/stable/web.html" />,
  13. }
  14. )}
  15. </p>
  16. );
  17. export const steps = ({
  18. dsn,
  19. }: {
  20. dsn?: string;
  21. } = {}): LayoutProps['steps'] => [
  22. {
  23. type: StepType.INSTALL,
  24. description: (
  25. <p>
  26. {tct('Install [code:sentry-sdk] from PyPI:', {
  27. code: <code />,
  28. })}
  29. </p>
  30. ),
  31. configurations: [
  32. {
  33. language: 'bash',
  34. code: '$ pip install --upgrade sentry-sdk',
  35. },
  36. {
  37. description: (
  38. <p>
  39. {tct(
  40. "If you're on Python 3.6, you also need the [code:aiocontextvars] package:",
  41. {
  42. code: <code />,
  43. }
  44. )}
  45. </p>
  46. ),
  47. language: 'bash',
  48. code: '$ pip install --upgrade aiocontextvars',
  49. },
  50. ],
  51. },
  52. {
  53. type: StepType.CONFIGURE,
  54. description: t('Initialize the SDK before starting the server:'),
  55. configurations: [
  56. {
  57. language: 'python',
  58. code: `
  59. import sentry_sdk
  60. from sentry_sdk.integrations.aiohttp import AioHttpIntegration
  61. sentry_sdk.init(
  62. dsn="${dsn}",
  63. integrations=[
  64. AioHttpIntegration(),
  65. ],
  66. # Set traces_sample_rate to 1.0 to capture 100%
  67. # of transactions for performance monitoring.
  68. # We recommend adjusting this value in production,
  69. traces_sample_rate=1.0,
  70. )
  71. from aiohttp import web
  72. async def hello(request):
  73. return web.Response(text="Hello, world")
  74. app = web.Application()
  75. app.add_routes([web.get('/', hello)])
  76. web.run_app(app)
  77. `,
  78. },
  79. ],
  80. },
  81. ];
  82. // Configuration End
  83. export function GettingStartedWithAIOHTTP({dsn, ...props}: ModuleProps) {
  84. return <Layout steps={steps({dsn})} introduction={introduction} {...props} />;
  85. }
  86. export default GettingStartedWithAIOHTTP;