django.tsx 3.3 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 {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. # 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. install: () => [
  38. {
  39. type: StepType.INSTALL,
  40. description: tct('Install [code:sentry-sdk] from PyPI:', {
  41. code: <code />,
  42. }),
  43. configurations: [
  44. {
  45. language: 'bash',
  46. code: getInstallSnippet(),
  47. },
  48. ],
  49. },
  50. ],
  51. configure: (params: Params) => [
  52. {
  53. type: StepType.CONFIGURE,
  54. description: tct(
  55. 'Initialize the Sentry SDK in your Django [codeSettings:settings.py] file:',
  56. {
  57. codeDjango: <code />,
  58. codeSettings: <code />,
  59. }
  60. ),
  61. configurations: [
  62. {
  63. language: 'python',
  64. code: getSdkSetupSnippet(params),
  65. },
  66. ],
  67. },
  68. ],
  69. verify: () => [
  70. {
  71. type: StepType.VERIFY,
  72. description: t(
  73. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  74. ),
  75. configurations: [
  76. {
  77. language: 'python',
  78. code: `# urls.py
  79. from django.urls import path
  80. def trigger_error(request):
  81. division_by_zero = 1 / 0
  82. urlpatterns = [
  83. path('sentry-debug/', trigger_error),
  84. # ...
  85. ]
  86. `,
  87. },
  88. ],
  89. additionalInfo: (
  90. <div>
  91. <p>
  92. {tct(
  93. '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.',
  94. {
  95. link: <ExternalLink href="http://localhost:8000/sentry-debug/" />,
  96. }
  97. )}
  98. </p>
  99. <br />
  100. <p>
  101. {t(
  102. 'It can take a couple of moments for the data to appear in Sentry. Bear with us, the internet is huge.'
  103. )}
  104. </p>
  105. </div>
  106. ),
  107. },
  108. ],
  109. nextSteps: () => [],
  110. };
  111. const docs: Docs = {
  112. onboarding,
  113. replayOnboardingJsLoader,
  114. customMetricsOnboarding: getPythonMetricsOnboarding({
  115. installSnippet: getInstallSnippet(),
  116. }),
  117. crashReportOnboarding: crashReportOnboardingPython,
  118. };
  119. export default docs;