django.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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`;
  14. const getSdkSetupSnippet = (params: Params) => `
  15. import sentry_sdk
  16. sentry_sdk.init(
  17. dsn="${params.dsn.public}",${
  18. params.isPerformanceSelected
  19. ? `
  20. # Set traces_sample_rate to 1.0 to capture 100%
  21. # of transactions for tracing.
  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. install: () => [
  37. {
  38. type: StepType.INSTALL,
  39. description: tct('Install [code:sentry-sdk] from PyPI:', {
  40. code: <code />,
  41. }),
  42. configurations: [
  43. {
  44. language: 'bash',
  45. code: getInstallSnippet(),
  46. },
  47. ],
  48. },
  49. ],
  50. configure: (params: Params) => [
  51. {
  52. type: StepType.CONFIGURE,
  53. description: tct(
  54. 'Initialize the Sentry SDK in your Django [codeSettings:settings.py] file:',
  55. {
  56. codeDjango: <code />,
  57. codeSettings: <code />,
  58. }
  59. ),
  60. configurations: [
  61. {
  62. code: [
  63. {
  64. label: 'settings.py',
  65. value: 'settings.py',
  66. language: 'python',
  67. code: getSdkSetupSnippet(params),
  68. },
  69. ],
  70. },
  71. ],
  72. },
  73. ],
  74. verify: () => [
  75. {
  76. type: StepType.VERIFY,
  77. description: t(
  78. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  79. ),
  80. configurations: [
  81. {
  82. code: [
  83. {
  84. label: 'urls.py',
  85. value: 'urls.py',
  86. language: 'python',
  87. code: `
  88. from django.urls import path
  89. def trigger_error(request):
  90. division_by_zero = 1 / 0
  91. urlpatterns = [
  92. path('sentry-debug/', trigger_error),
  93. # ...
  94. ]
  95. `,
  96. },
  97. ],
  98. },
  99. ],
  100. additionalInfo: (
  101. <div>
  102. <p>
  103. {tct(
  104. 'When you point your browser to [link:http://localhost:8000/sentry-debug/] an error with a trace will be created. So you can explore errors and tracing portions of Sentry.',
  105. {
  106. link: <ExternalLink href="http://localhost:8000/sentry-debug/" />,
  107. }
  108. )}
  109. </p>
  110. <br />
  111. <p>
  112. {t(
  113. 'It can take a couple of moments for the data to appear in Sentry. Bear with us, the internet is huge.'
  114. )}
  115. </p>
  116. </div>
  117. ),
  118. },
  119. ],
  120. nextSteps: () => [],
  121. };
  122. const docs: Docs = {
  123. onboarding,
  124. replayOnboardingJsLoader,
  125. customMetricsOnboarding: getPythonMetricsOnboarding({
  126. installSnippet: getInstallSnippet(),
  127. }),
  128. crashReportOnboarding: crashReportOnboardingPython,
  129. };
  130. export default docs;