sanic.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 {getPythonMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  9. import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  10. import {t, tct} from 'sentry/locale';
  11. type Params = DocsParams;
  12. const getInstallSnippet = () => `pip install --upgrade sentry-sdk[sanic]`;
  13. const getSdkSetupSnippet = (params: Params) => `from sanic import Sanic
  14. import sentry_sdk
  15. sentry_sdk.init(
  16. dsn="${params.dsn}",
  17. )
  18. `;
  19. const onboarding: OnboardingConfig = {
  20. introduction: () =>
  21. tct('The Sanic integration adds support for the [link:Sanic Web Framework].', {
  22. link: <ExternalLink href="https://github.com/sanic-org/sanic" />,
  23. }),
  24. install: () => [
  25. {
  26. type: StepType.INSTALL,
  27. description: tct(
  28. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentrySanicCode:sanic] extra:',
  29. {
  30. sentrySdkCode: <code />,
  31. sentrySanicCode: <code />,
  32. }
  33. ),
  34. configurations: [
  35. {
  36. language: 'bash',
  37. code: getInstallSnippet(),
  38. },
  39. {
  40. description: (
  41. <p>
  42. {tct(
  43. "f 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. };
  111. export default docs;