sanic.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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('The Sanic integration adds support for the [link:Sanic Web Framework].', {
  10. link: <ExternalLink href="https://github.com/sanic-org/sanic" />,
  11. })}
  12. </p>
  13. );
  14. export const steps = ({
  15. sentryInitContent,
  16. }: {
  17. sentryInitContent: string;
  18. }): LayoutProps['steps'] => [
  19. {
  20. type: StepType.INSTALL,
  21. description: (
  22. <p>
  23. {tct(
  24. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentrySanicCode:sanic] extra:',
  25. {
  26. sentrySdkCode: <code />,
  27. sentrySanicCode: <code />,
  28. }
  29. )}
  30. </p>
  31. ),
  32. configurations: [
  33. {
  34. language: 'bash',
  35. code: '$ pip install --upgrade sentry-sdk[sanic]',
  36. },
  37. {
  38. description: (
  39. <p>
  40. {tct(
  41. "f you're on Python 3.6, you also need the [code:aiocontextvars] package:",
  42. {
  43. code: <code />,
  44. }
  45. )}
  46. </p>
  47. ),
  48. language: 'bash',
  49. code: '$ pip install --upgrade aiocontextvars',
  50. },
  51. ],
  52. },
  53. {
  54. type: StepType.CONFIGURE,
  55. description: (
  56. <p>
  57. {tct(
  58. 'If you have the [codeSanic:sanic] package in your dependencies, the Sanic integration will be enabled automatically when you initialize the Sentry SDK. Initialize the Sentry SDK before your app has been initialized:',
  59. {
  60. codeSanic: <code />,
  61. }
  62. )}
  63. </p>
  64. ),
  65. configurations: [
  66. {
  67. language: 'python',
  68. code: `
  69. from sanic import Sanic
  70. import sentry_sdk
  71. sentry_sdk.init(
  72. ${sentryInitContent}
  73. )
  74. app = Sanic(__name__)
  75. `,
  76. },
  77. ],
  78. },
  79. {
  80. type: StepType.VERIFY,
  81. description: t(
  82. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  83. ),
  84. configurations: [
  85. {
  86. language: 'python',
  87. code: `from sanic import Sanic
  88. from sanic.response import text
  89. sentry_sdk.init(
  90. ${sentryInitContent}
  91. )
  92. app = Sanic(__name__)
  93. @app.get("/")
  94. async def hello_world(request):
  95. 1 / 0 # raises an error
  96. return text("Hello, world.")
  97. `,
  98. },
  99. ],
  100. additionalInfo: (
  101. <p>
  102. {tct(
  103. 'When you point your browser to [link:http://localhost:8000/] an error will be sent to Sentry.',
  104. {
  105. link: <ExternalLink href="http://localhost:8000/" />,
  106. }
  107. )}
  108. </p>
  109. ),
  110. },
  111. ];
  112. // Configuration End
  113. export function GettingStartedWithSanic({dsn, ...props}: ModuleProps) {
  114. const otherConfigs: string[] = [];
  115. let sentryInitContent: string[] = [` dsn="${dsn}",`];
  116. sentryInitContent = sentryInitContent.concat(otherConfigs);
  117. return (
  118. <Layout
  119. introduction={introduction}
  120. steps={steps({
  121. sentryInitContent: sentryInitContent.join('\n'),
  122. })}
  123. {...props}
  124. />
  125. );
  126. }
  127. export default GettingStartedWithSanic;