sanic.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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}",
  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 [sentrySdkCode:sentry-sdk] from PyPI with the [sentrySanicCode:sanic] extra:',
  30. {
  31. sentrySdkCode: <code />,
  32. sentrySanicCode: <code />,
  33. }
  34. ),
  35. configurations: [
  36. {
  37. language: 'bash',
  38. code: getInstallSnippet(),
  39. },
  40. {
  41. description: (
  42. <p>
  43. {tct(
  44. "f you're on Python 3.6, you also need the [code:aiocontextvars] package:",
  45. {
  46. code: <code />,
  47. }
  48. )}
  49. </p>
  50. ),
  51. language: 'bash',
  52. code: 'pip install --upgrade aiocontextvars',
  53. },
  54. ],
  55. },
  56. ],
  57. configure: (params: Params) => [
  58. {
  59. type: StepType.CONFIGURE,
  60. description: tct(
  61. '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:',
  62. {
  63. codeSanic: <code />,
  64. }
  65. ),
  66. configurations: [
  67. {
  68. language: 'python',
  69. code: `${getSdkSetupSnippet(params)}
  70. app = Sanic(__name__)
  71. `,
  72. },
  73. ],
  74. },
  75. ],
  76. verify: (params: Params) => [
  77. {
  78. type: StepType.VERIFY,
  79. description: t(
  80. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  81. ),
  82. configurations: [
  83. {
  84. language: 'python',
  85. code: `from sanic.response import text
  86. ${getSdkSetupSnippet(params)}
  87. app = Sanic(__name__)
  88. @app.get("/")
  89. async def hello_world(request):
  90. 1 / 0 # raises an error
  91. return text("Hello, world.")
  92. `,
  93. },
  94. ],
  95. additionalInfo: tct(
  96. 'When you point your browser to [link:http://localhost:8000/] an error will be sent to Sentry.',
  97. {
  98. link: <ExternalLink href="http://localhost:8000/" />,
  99. }
  100. ),
  101. },
  102. ],
  103. nextSteps: () => [],
  104. };
  105. const docs: Docs = {
  106. onboarding,
  107. replayOnboardingJsLoader,
  108. customMetricsOnboarding: getPythonMetricsOnboarding({
  109. installSnippet: getInstallSnippet(),
  110. }),
  111. crashReportOnboarding: crashReportOnboardingPython,
  112. };
  113. export default docs;