django.tsx 6.8 KB

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