sanic.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  3. import type {
  4. Docs,
  5. DocsParams,
  6. OnboardingConfig,
  7. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  8. import {getPythonMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  9. import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  10. import {crashReportOnboardingPython} from 'sentry/gettingStartedDocs/python/python';
  11. import {t, tct} from 'sentry/locale';
  12. type Params = DocsParams;
  13. const getInstallSnippet = () => `pip install --upgrade 'sentry-sdk[sanic]'`;
  14. const getSdkSetupSnippet = (params: Params) => `from sanic import Sanic
  15. import sentry_sdk
  16. sentry_sdk.init(
  17. dsn="${params.dsn.public}",
  18. )
  19. `;
  20. const onboarding: OnboardingConfig = {
  21. introduction: () =>
  22. tct('The Sanic integration adds support for the [link:Sanic Web Framework].', {
  23. link: <ExternalLink href="https://github.com/sanic-org/sanic" />,
  24. }),
  25. install: () => [
  26. {
  27. type: StepType.INSTALL,
  28. description: tct(
  29. 'Install [code:sentry-sdk] from PyPI with the [code:sanic] extra:',
  30. {
  31. code: <code />,
  32. }
  33. ),
  34. configurations: [
  35. {
  36. language: 'bash',
  37. code: getInstallSnippet(),
  38. },
  39. {
  40. description: (
  41. <p>
  42. {tct(
  43. "If you're on Python 3.6, you also need the [code:aiocontextvars] package:",
  44. {
  45. code: <code />,
  46. }
  47. )}
  48. </p>
  49. ),
  50. language: 'bash',
  51. code: 'pip install --upgrade aiocontextvars',
  52. },
  53. ],
  54. },
  55. ],
  56. configure: (params: Params) => [
  57. {
  58. type: StepType.CONFIGURE,
  59. description: tct(
  60. '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:',
  61. {
  62. codeSanic: <code />,
  63. }
  64. ),
  65. configurations: [
  66. {
  67. language: 'python',
  68. code: `${getSdkSetupSnippet(params)}
  69. app = Sanic(__name__)
  70. `,
  71. },
  72. ],
  73. },
  74. ],
  75. verify: (params: Params) => [
  76. {
  77. type: StepType.VERIFY,
  78. description: t(
  79. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  80. ),
  81. configurations: [
  82. {
  83. language: 'python',
  84. code: `from sanic.response import text
  85. ${getSdkSetupSnippet(params)}
  86. app = Sanic(__name__)
  87. @app.get("/")
  88. async def hello_world(request):
  89. 1 / 0 # raises an error
  90. return text("Hello, world.")
  91. `,
  92. },
  93. ],
  94. additionalInfo: tct(
  95. 'When you point your browser to [link:http://localhost:8000/] an error will be sent to Sentry.',
  96. {
  97. link: <ExternalLink href="http://localhost:8000/" />,
  98. }
  99. ),
  100. },
  101. ],
  102. nextSteps: () => [],
  103. };
  104. const docs: Docs = {
  105. onboarding,
  106. replayOnboardingJsLoader,
  107. customMetricsOnboarding: getPythonMetricsOnboarding({
  108. installSnippet: getInstallSnippet(),
  109. }),
  110. crashReportOnboarding: crashReportOnboardingPython,
  111. };
  112. export default docs;