aiohttp.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 {ProductSolution} from 'sentry/components/onboarding/productSelection';
  6. import {t, tct} from 'sentry/locale';
  7. // Configuration Start
  8. const profilingConfiguration = ` # Set profiles_sample_rate to 1.0 to profile 100%
  9. # of sampled transactions.
  10. # We recommend adjusting this value in production.
  11. profiles_sample_rate=1.0,`;
  12. const performanceConfiguration = ` # Set traces_sample_rate to 1.0 to capture 100%
  13. # of transactions for performance monitoring.
  14. # We recommend adjusting this value in production.
  15. traces_sample_rate=1.0,`;
  16. const introduction = (
  17. <p>
  18. {tct(
  19. 'The AIOHTTP integration adds support for the [link:AIOHTTP-Server Web Framework]. A Python version of 3.6 or greater is required.',
  20. {
  21. link: <ExternalLink href="https://docs.aiohttp.org/en/stable/web.html" />,
  22. }
  23. )}
  24. </p>
  25. );
  26. export const steps = ({
  27. sentryInitContent,
  28. }: {
  29. sentryInitContent: string;
  30. }): LayoutProps['steps'] => [
  31. {
  32. type: StepType.INSTALL,
  33. description: (
  34. <p>
  35. {tct('Install [code:sentry-sdk] from PyPI:', {
  36. code: <code />,
  37. })}
  38. </p>
  39. ),
  40. configurations: [
  41. {
  42. language: 'bash',
  43. code: '$ pip install --upgrade sentry-sdk',
  44. },
  45. {
  46. description: (
  47. <p>
  48. {tct(
  49. "If you're on Python 3.6, you also need the [code:aiocontextvars] package:",
  50. {
  51. code: <code />,
  52. }
  53. )}
  54. </p>
  55. ),
  56. language: 'bash',
  57. code: '$ pip install --upgrade aiocontextvars',
  58. },
  59. ],
  60. },
  61. {
  62. type: StepType.CONFIGURE,
  63. description: t('Initialize the SDK before starting the server:'),
  64. configurations: [
  65. {
  66. language: 'python',
  67. code: `
  68. import sentry_sdk
  69. from sentry_sdk.integrations.aiohttp import AioHttpIntegration
  70. sentry_sdk.init(
  71. ${sentryInitContent}
  72. )
  73. from aiohttp import web
  74. async def hello(request):
  75. return web.Response(text="Hello, world")
  76. app = web.Application()
  77. app.add_routes([web.get('/', hello)])
  78. web.run_app(app)
  79. `,
  80. },
  81. ],
  82. },
  83. ];
  84. // Configuration End
  85. export function GettingStartedWithAIOHTTP({
  86. dsn,
  87. activeProductSelection = [],
  88. ...props
  89. }: ModuleProps) {
  90. const otherConfigs: string[] = [];
  91. let sentryInitContent: string[] = [
  92. ` dsn="${dsn}",`,
  93. ` integrations=[AioHttpIntegration()],`,
  94. ];
  95. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  96. otherConfigs.push(performanceConfiguration);
  97. }
  98. if (activeProductSelection.includes(ProductSolution.PROFILING)) {
  99. otherConfigs.push(profilingConfiguration);
  100. }
  101. sentryInitContent = sentryInitContent.concat(otherConfigs);
  102. return (
  103. <Layout
  104. introduction={introduction}
  105. steps={steps({
  106. sentryInitContent: sentryInitContent.join('\n'),
  107. })}
  108. {...props}
  109. />
  110. );
  111. }
  112. export default GettingStartedWithAIOHTTP;