sanic.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  3. import {
  4. Docs,
  5. DocsParams,
  6. OnboardingConfig,
  7. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  8. import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  9. import {t, tct} from 'sentry/locale';
  10. type Params = DocsParams;
  11. const getSdkSetupSnippet = (params: Params) => `from sanic import Sanic
  12. import sentry_sdk
  13. sentry_sdk.init(
  14. dsn="${params.dsn}",
  15. )
  16. `;
  17. const onboarding: OnboardingConfig = {
  18. introduction: () =>
  19. tct('The Sanic integration adds support for the [link:Sanic Web Framework].', {
  20. link: <ExternalLink href="https://github.com/sanic-org/sanic" />,
  21. }),
  22. install: () => [
  23. {
  24. type: StepType.INSTALL,
  25. description: tct(
  26. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentrySanicCode:sanic] extra:',
  27. {
  28. sentrySdkCode: <code />,
  29. sentrySanicCode: <code />,
  30. }
  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. configure: (params: Params) => [
  55. {
  56. type: StepType.CONFIGURE,
  57. description: 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. configurations: [
  64. {
  65. language: 'python',
  66. code: `${getSdkSetupSnippet(params)}
  67. app = Sanic(__name__)
  68. `,
  69. },
  70. ],
  71. },
  72. ],
  73. verify: (params: Params) => [
  74. {
  75. type: StepType.VERIFY,
  76. description: t(
  77. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  78. ),
  79. configurations: [
  80. {
  81. language: 'python',
  82. code: `from sanic.response import text
  83. ${getSdkSetupSnippet(params)}
  84. app = Sanic(__name__)
  85. @app.get("/")
  86. async def hello_world(request):
  87. 1 / 0 # raises an error
  88. return text("Hello, world.")
  89. `,
  90. },
  91. ],
  92. additionalInfo: tct(
  93. 'When you point your browser to [link:http://localhost:8000/] an error will be sent to Sentry.',
  94. {
  95. link: <ExternalLink href="http://localhost:8000/" />,
  96. }
  97. ),
  98. },
  99. ],
  100. nextSteps: () => [],
  101. };
  102. const docs: Docs = {
  103. onboarding,
  104. replayOnboardingJsLoader,
  105. };
  106. export default docs;