django.tsx 4.1 KB

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