aiohttp.tsx 2.3 KB

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