sanic.tsx 3.4 KB

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