django.tsx 4.0 KB

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