django.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  3. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  4. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  5. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  6. import {t, tct} from 'sentry/locale';
  7. // Configuration Start
  8. const performanceConfiguration = ` # Set traces_sample_rate to 1.0 to capture 100%
  9. # of transactions for performance monitoring.
  10. traces_sample_rate=1.0,`;
  11. const profilingConfiguration = ` # Set profiles_sample_rate to 1.0 to profile 100%
  12. # of sampled transactions.
  13. # We recommend adjusting this value in production.
  14. profiles_sample_rate=1.0,`;
  15. const introduction = (
  16. <p>
  17. {tct('The Django integration adds support for the [link:Django Web Framework].', {
  18. link: <ExternalLink href="https://www.djangoproject.com/" />,
  19. })}
  20. </p>
  21. );
  22. export const steps = ({
  23. sentryInitContent,
  24. }: {
  25. sentryInitContent?: string;
  26. } = {}): LayoutProps['steps'] => [
  27. {
  28. type: StepType.INSTALL,
  29. description: (
  30. <p>
  31. {tct('The Django integration adds support for the [link:Django Web Framework].', {
  32. link: <ExternalLink href="https://www.djangoproject.com/" />,
  33. })}
  34. </p>
  35. ),
  36. configurations: [
  37. {
  38. language: 'bash',
  39. description: (
  40. <p>
  41. {tct(
  42. 'Install [code:sentry-sdk] from PyPI with the [sentryDjangoCode:django] extra:',
  43. {
  44. code: <code />,
  45. sentryDjangoCode: <code />,
  46. }
  47. )}
  48. </p>
  49. ),
  50. code: 'pip install --upgrade sentry-sdk[django]',
  51. },
  52. ],
  53. },
  54. {
  55. type: StepType.CONFIGURE,
  56. description: (
  57. <p>
  58. {tct(
  59. 'If you have the [codeDjango:django] package in your dependencies, the Django integration will be enabled automatically when you initialize the Sentry SDK. Initialize the Sentry SDK in your Django [codeSettings:settings.py] file:',
  60. {
  61. codeDjango: <code />,
  62. codeSettings: <code />,
  63. }
  64. )}
  65. </p>
  66. ),
  67. configurations: [
  68. {
  69. language: 'python',
  70. code: `# settings.py
  71. import sentry_sdk
  72. sentry_sdk.init(
  73. ${sentryInitContent}
  74. )`,
  75. },
  76. ],
  77. },
  78. {
  79. type: StepType.VERIFY,
  80. description: t(
  81. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  82. ),
  83. configurations: [
  84. {
  85. language: 'python',
  86. code: `# urls.py
  87. from django.urls import path
  88. def trigger_error(request):
  89. division_by_zero = 1 / 0
  90. urlpatterns = [
  91. path('sentry-debug/', trigger_error),
  92. # ...
  93. ]
  94. `,
  95. },
  96. ],
  97. additionalInfo: (
  98. <div>
  99. <p>
  100. {tct(
  101. 'When you point your browser to [link:http://localhost:8000/sentry-debug/] a transaction in the Performance section of Sentry will be created.',
  102. {
  103. link: <ExternalLink href="http://localhost:8000/" />,
  104. }
  105. )}
  106. </p>
  107. <p>
  108. {t(
  109. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  110. )}
  111. </p>
  112. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  113. </div>
  114. ),
  115. },
  116. ];
  117. // Configuration End
  118. export function GettingStartedWithDjango({
  119. dsn,
  120. activeProductSelection = [],
  121. ...props
  122. }: ModuleProps) {
  123. const otherConfigs: string[] = [];
  124. let sentryInitContent: string[] = [` dsn="${dsn}",`];
  125. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  126. otherConfigs.push(performanceConfiguration);
  127. }
  128. if (activeProductSelection.includes(ProductSolution.PROFILING)) {
  129. otherConfigs.push(profilingConfiguration);
  130. }
  131. sentryInitContent = sentryInitContent.concat(otherConfigs);
  132. return (
  133. <Layout
  134. introduction={introduction}
  135. steps={steps({
  136. sentryInitContent: sentryInitContent.join('\n'),
  137. })}
  138. {...props}
  139. />
  140. );
  141. }
  142. export default GettingStartedWithDjango;