sanic.tsx 3.4 KB

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