sanic.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import List from 'sentry/components/list';
  4. import ListItem from 'sentry/components/list/listItem';
  5. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  6. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  7. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  8. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  9. import {t, tct} from 'sentry/locale';
  10. // Configuration Start
  11. const profilingConfiguration = ` # Set profiles_sample_rate to 1.0 to profile 100%
  12. # of sampled transactions.
  13. # We recommend adjusting this value in production.
  14. profiles_sample_rate=1.0,`;
  15. const performanceConfiguration = ` # Set traces_sample_rate to 1.0 to capture 100%
  16. # of transactions for performance monitoring.
  17. # We recommend adjusting this value in production.
  18. traces_sample_rate=1.0,`;
  19. const introduction = (
  20. <Fragment>
  21. <p>
  22. {tct(
  23. 'The Sanic integration adds support for the [link:Sanic Web Framework]. We support the following versions:',
  24. {
  25. link: <ExternalLink href="https://github.com/sanic-org/sanic" />,
  26. }
  27. )}
  28. </p>
  29. <List symbol="bullet">
  30. <ListItem>0.8</ListItem>
  31. <ListItem>18.12</ListItem>
  32. <ListItem>19.12</ListItem>
  33. <ListItem>20.12</ListItem>
  34. <ListItem>{t('Any version of the form "x.12" (LTS versions).')}</ListItem>
  35. </List>
  36. <p>
  37. {tct(
  38. '[strong:We do support all versions of Sanic]. However, Sanic versions between LTS releases should be considered Early Adopter. We may not support all the features in these non-LTS versions, since non-LTS versions change quickly and [link:have introduced breaking changes in the past], without prior notice.',
  39. {
  40. strong: <strong />,
  41. link: <ExternalLink href="https://github.com/sanic-org/sanic/issues/1532" />,
  42. }
  43. )}
  44. </p>
  45. {t('A Python version of "3.6" or greater is also required.')}
  46. </Fragment>
  47. );
  48. export const steps = ({
  49. sentryInitContent,
  50. }: {
  51. sentryInitContent: string;
  52. }): LayoutProps['steps'] => [
  53. {
  54. type: StepType.INSTALL,
  55. description: <p>{tct('Install [code:sentry-sdk] from PyPI:', {code: <code />})}</p>,
  56. configurations: [
  57. {
  58. language: 'bash',
  59. code: '$ pip install --upgrade sentry-sdk',
  60. },
  61. {
  62. description: (
  63. <p>
  64. {tct(
  65. "f you're on Python 3.6, you also need the [code:aiocontextvars] package:",
  66. {
  67. code: <code />,
  68. }
  69. )}
  70. </p>
  71. ),
  72. language: 'bash',
  73. code: '$ pip install --upgrade aiocontextvars',
  74. },
  75. ],
  76. },
  77. {
  78. type: StepType.CONFIGURE,
  79. description: t(
  80. 'To configure the SDK, initialize it with the integration before or after your app has been initialized:'
  81. ),
  82. configurations: [
  83. {
  84. language: 'python',
  85. code: `
  86. import sentry_sdk
  87. from sentry_sdk.integrations.sanic import SanicIntegration
  88. from sanic import Sanic
  89. sentry_sdk.init(
  90. ${sentryInitContent}
  91. )
  92. app = Sanic(__name__)
  93. `,
  94. },
  95. ],
  96. },
  97. ];
  98. // Configuration End
  99. export function GettingStartedWithSanic({
  100. dsn,
  101. activeProductSelection = [],
  102. ...props
  103. }: ModuleProps) {
  104. const otherConfigs: string[] = [];
  105. let sentryInitContent: string[] = [
  106. ` dsn="${dsn}",`,
  107. ` integrations=[SanicIntegration()],`,
  108. ];
  109. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  110. otherConfigs.push(performanceConfiguration);
  111. }
  112. if (activeProductSelection.includes(ProductSolution.PROFILING)) {
  113. otherConfigs.push(profilingConfiguration);
  114. }
  115. sentryInitContent = sentryInitContent.concat(otherConfigs);
  116. return (
  117. <Layout
  118. introduction={introduction}
  119. steps={steps({
  120. sentryInitContent: sentryInitContent.join('\n'),
  121. })}
  122. {...props}
  123. />
  124. );
  125. }
  126. export default GettingStartedWithSanic;