django.tsx 6.7 KB

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