django.tsx 6.4 KB

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