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