django.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  9. import {t, tct} from 'sentry/locale';
  10. type Params = DocsParams;
  11. const getSdkSetupSnippet = (params: Params) => `
  12. # settings.py
  13. import sentry_sdk
  14. sentry_sdk.init(
  15. dsn="${params.dsn}",${
  16. params.isPerformanceSelected
  17. ? `
  18. # Set traces_sample_rate to 1.0 to capture 100%
  19. # of transactions for performance monitoring.
  20. traces_sample_rate=1.0,`
  21. : ''
  22. }${
  23. params.isProfilingSelected
  24. ? `
  25. # Set profiles_sample_rate to 1.0 to profile 100%
  26. # of sampled transactions.
  27. # We recommend adjusting this value in production.
  28. profiles_sample_rate=1.0,`
  29. : ''
  30. }
  31. )
  32. `;
  33. const onboarding: OnboardingConfig = {
  34. introduction: () =>
  35. tct('The Django integration adds support for the [link:Django Web Framework].', {
  36. link: <ExternalLink href="https://www.djangoproject.com/" />,
  37. }),
  38. install: () => [
  39. {
  40. type: StepType.INSTALL,
  41. description: tct(
  42. 'The Django integration adds support for the [link:Django Web Framework].',
  43. {
  44. link: <ExternalLink href="https://www.djangoproject.com/" />,
  45. }
  46. ),
  47. configurations: [
  48. {
  49. language: 'bash',
  50. description: (
  51. <p>
  52. {tct(
  53. 'Install [code:sentry-sdk] from PyPI with the [sentryDjangoCode:django] extra:',
  54. {
  55. code: <code />,
  56. sentryDjangoCode: <code />,
  57. }
  58. )}
  59. </p>
  60. ),
  61. code: 'pip install --upgrade sentry-sdk[django]',
  62. },
  63. ],
  64. },
  65. ],
  66. configure: (params: Params) => [
  67. {
  68. type: StepType.CONFIGURE,
  69. description: tct(
  70. 'If you have the [codeDjango:django] package in your dependencies, the Django integration will be enabled automatically when you initialize the Sentry SDK. Initialize the Sentry SDK in your Django [codeSettings:settings.py] file:',
  71. {
  72. codeDjango: <code />,
  73. codeSettings: <code />,
  74. }
  75. ),
  76. configurations: [
  77. {
  78. language: 'python',
  79. code: `
  80. ${getSdkSetupSnippet(params)}
  81. api = falcon.API()
  82. `,
  83. },
  84. ],
  85. },
  86. ],
  87. verify: () => [
  88. {
  89. type: StepType.VERIFY,
  90. description: t(
  91. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  92. ),
  93. configurations: [
  94. {
  95. language: 'python',
  96. code: `# urls.py
  97. from django.urls import path
  98. def trigger_error(request):
  99. division_by_zero = 1 / 0
  100. urlpatterns = [
  101. path('sentry-debug/', trigger_error),
  102. # ...
  103. ]
  104. `,
  105. },
  106. ],
  107. additionalInfo: (
  108. <div>
  109. <p>
  110. {tct(
  111. 'When you point your browser to [link:http://localhost:8000/sentry-debug/] a transaction in the Performance section of Sentry will be created.',
  112. {
  113. link: <ExternalLink href="http://localhost:8000/" />,
  114. }
  115. )}
  116. </p>
  117. <p>
  118. {t(
  119. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  120. )}
  121. </p>
  122. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  123. </div>
  124. ),
  125. },
  126. ],
  127. nextSteps: () => [],
  128. };
  129. const docs: Docs = {
  130. onboarding,
  131. replayOnboardingJsLoader,
  132. };
  133. export default docs;