django.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  3. import {
  4. type Docs,
  5. DocsPageLocation,
  6. type DocsParams,
  7. type OnboardingConfig,
  8. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  9. import {getPythonMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  10. import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  11. import {
  12. AlternativeConfiguration,
  13. crashReportOnboardingPython,
  14. } from 'sentry/gettingStartedDocs/python/python';
  15. import {t, tct} from 'sentry/locale';
  16. type Params = DocsParams;
  17. const getInstallSnippet = () => `pip install --upgrade 'sentry-sdk[django]'`;
  18. const getSdkSetupSnippet = (params: Params) => `
  19. import sentry_sdk
  20. sentry_sdk.init(
  21. dsn="${params.dsn.public}",${
  22. params.isPerformanceSelected
  23. ? `
  24. # Set traces_sample_rate to 1.0 to capture 100%
  25. # of transactions for tracing.
  26. traces_sample_rate=1.0,`
  27. : ''
  28. }${
  29. params.isProfilingSelected &&
  30. params.profilingOptions?.defaultProfilingMode !== 'continuous'
  31. ? `
  32. # Set profiles_sample_rate to 1.0 to profile 100%
  33. # of sampled transactions.
  34. # We recommend adjusting this value in production.
  35. profiles_sample_rate=1.0,`
  36. : params.isProfilingSelected &&
  37. params.profilingOptions?.defaultProfilingMode === 'continuous'
  38. ? `
  39. _experiments={
  40. # Set continuous_profiling_auto_start to True
  41. # to automatically start the profiler on when
  42. # possible.
  43. "continuous_profiling_auto_start": True,
  44. },`
  45. : ''
  46. }
  47. )
  48. `;
  49. const onboarding: OnboardingConfig = {
  50. install: (params: Params) => [
  51. {
  52. type: StepType.INSTALL,
  53. description: tct(
  54. 'Install [code:sentry-sdk] from PyPI with the [code:django] extra:',
  55. {
  56. code: <code />,
  57. }
  58. ),
  59. configurations: [
  60. {
  61. description:
  62. params.docsLocation === DocsPageLocation.PROFILING_PAGE
  63. ? tct(
  64. 'You need a minimum version [code:1.18.0] of the [code:sentry-python] SDK for the profiling feature.',
  65. {
  66. code: <code />,
  67. }
  68. )
  69. : undefined,
  70. language: 'bash',
  71. code: getInstallSnippet(),
  72. },
  73. ],
  74. },
  75. ],
  76. configure: (params: Params) => [
  77. {
  78. type: StepType.CONFIGURE,
  79. description: tct(
  80. 'Initialize the Sentry SDK in your Django [code:settings.py] file:',
  81. {
  82. code: <code />,
  83. }
  84. ),
  85. configurations: [
  86. {
  87. code: [
  88. {
  89. label: 'settings.py',
  90. value: 'settings.py',
  91. language: 'python',
  92. code: getSdkSetupSnippet(params),
  93. },
  94. ],
  95. },
  96. ],
  97. additionalInfo: <AlternativeConfiguration />,
  98. },
  99. ],
  100. verify: () => [
  101. {
  102. type: StepType.VERIFY,
  103. description: t(
  104. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  105. ),
  106. configurations: [
  107. {
  108. code: [
  109. {
  110. label: 'urls.py',
  111. value: 'urls.py',
  112. language: 'python',
  113. code: `
  114. from django.urls import path
  115. def trigger_error(request):
  116. division_by_zero = 1 / 0
  117. urlpatterns = [
  118. path('sentry-debug/', trigger_error),
  119. # ...
  120. ]
  121. `,
  122. },
  123. ],
  124. },
  125. ],
  126. additionalInfo: (
  127. <div>
  128. <p>
  129. {tct(
  130. '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.',
  131. {
  132. link: <ExternalLink href="http://localhost:8000/sentry-debug/" />,
  133. }
  134. )}
  135. </p>
  136. <br />
  137. <p>
  138. {t(
  139. 'It can take a couple of moments for the data to appear in Sentry. Bear with us, the internet is huge.'
  140. )}
  141. </p>
  142. </div>
  143. ),
  144. },
  145. ],
  146. nextSteps: () => [],
  147. };
  148. const performanceOnboarding: OnboardingConfig = {
  149. introduction: () =>
  150. t(
  151. "Adding Performance to your Django project is simple. Make sure you've got these basics down."
  152. ),
  153. install: onboarding.install,
  154. configure: params => [
  155. {
  156. type: StepType.CONFIGURE,
  157. description: tct(
  158. 'To configure the Sentry SDK, initialize it in your [code:settings.py] file:',
  159. {code: <code />}
  160. ),
  161. configurations: [
  162. {
  163. language: 'python',
  164. code: `
  165. import sentry-sdk
  166. sentry_sdk.init(
  167. dsn: "${params.dsn.public}",
  168. // Set traces_sample_rate to 1.0 to capture 100%
  169. // of transactions for performance monitoring.
  170. traces_sample_rate=1.0,
  171. )`,
  172. additionalInfo: tct(
  173. 'Learn more about tracing [linkTracingOptions:options], how to use the [linkTracesSampler:traces_sampler] function, or how to [linkSampleTransactions:sample transactions].',
  174. {
  175. linkTracingOptions: (
  176. <ExternalLink href="https://docs.sentry.io/platforms/python/configuration/options/#tracing-options" />
  177. ),
  178. linkTracesSampler: (
  179. <ExternalLink href="https://docs.sentry.io/platforms/python/configuration/sampling/" />
  180. ),
  181. linkSampleTransactions: (
  182. <ExternalLink href="https://docs.sentry.io/platforms/python/configuration/sampling/" />
  183. ),
  184. }
  185. ),
  186. },
  187. ],
  188. },
  189. ],
  190. verify: () => [
  191. {
  192. type: StepType.VERIFY,
  193. description: tct(
  194. 'Verify that performance monitoring is working correctly with our [link:automatic instrumentation] by simply using your Python application.',
  195. {
  196. link: (
  197. <ExternalLink href="https://docs.sentry.io/platforms/python/tracing/instrumentation/automatic-instrumentation/" />
  198. ),
  199. }
  200. ),
  201. additionalInfo: tct(
  202. 'You have the option to manually construct a transaction using [link:custom instrumentation].',
  203. {
  204. link: (
  205. <ExternalLink href="https://docs.sentry.io/platforms/python/tracing/instrumentation/custom-instrumentation/" />
  206. ),
  207. }
  208. ),
  209. },
  210. ],
  211. nextSteps: () => [],
  212. };
  213. const docs: Docs = {
  214. onboarding,
  215. replayOnboardingJsLoader,
  216. customMetricsOnboarding: getPythonMetricsOnboarding({
  217. installSnippet: getInstallSnippet(),
  218. }),
  219. performanceOnboarding,
  220. crashReportOnboarding: crashReportOnboardingPython,
  221. };
  222. export default docs;