django.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 profilingConfiguration = `
  9. # To set a uniform sample rate
  10. # Set profiles_sample_rate to 1.0 to profile 100%
  11. # of sampled transactions.
  12. # We recommend adjusting this value in production,
  13. profiles_sample_rate=1.0,
  14. `;
  15. const performanceConfiguration = `
  16. # Set traces_sample_rate to 1.0 to capture 100%
  17. # of transactions for performance monitoring.
  18. # We recommend adjusting this value in production.
  19. traces_sample_rate=1.0,
  20. `;
  21. const piiConfiguration = `
  22. # If you wish to associate users to errors (assuming you are using
  23. # django.contrib.auth) you may enable sending PII data.
  24. send_default_pii=True,
  25. `;
  26. export const steps = ({
  27. sentryInitContent,
  28. }: {
  29. sentryInitContent?: string;
  30. } = {}): LayoutProps['steps'] => [
  31. {
  32. type: StepType.INSTALL,
  33. description: (
  34. <p>
  35. {tct(
  36. 'The Django integration adds support for the [link:Django Web Framework] from Version 1.6 upwards.',
  37. {link: <ExternalLink href="https://www.djangoproject.com/" />}
  38. )}
  39. </p>
  40. ),
  41. configurations: [
  42. {
  43. language: 'bash',
  44. description: <p>{tct('Install [code:sentry-sdk]:', {code: <code />})}</p>,
  45. code: 'pip install --upgrade sentry-sdk',
  46. },
  47. ],
  48. },
  49. {
  50. type: StepType.CONFIGURE,
  51. description: (
  52. <p>
  53. {tct(
  54. 'To configure the SDK, initialize it with the Django integration in your [code:settings.py] file:',
  55. {code: <code />}
  56. )}
  57. </p>
  58. ),
  59. configurations: [
  60. {
  61. language: 'python',
  62. code: `
  63. import sentry_sdk
  64. from sentry_sdk.integrations.django import DjangoIntegration
  65. sentry_sdk.init(
  66. ${sentryInitContent}
  67. )`,
  68. },
  69. ],
  70. },
  71. {
  72. type: StepType.VERIFY,
  73. description: t(
  74. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  75. ),
  76. configurations: [
  77. {
  78. language: 'python',
  79. code: `
  80. from django.urls import path
  81. def trigger_error(request):
  82. division_by_zero = 1 / 0
  83. urlpatterns = [
  84. path('sentry-debug/', trigger_error),
  85. # ...
  86. ]
  87. `,
  88. },
  89. ],
  90. additionalInfo: t(
  91. 'Visiting this route will trigger an error that will be captured by Sentry.'
  92. ),
  93. },
  94. ];
  95. // Configuration End
  96. export function GettingStartedWithDjango({
  97. dsn,
  98. activeProductSelection = [],
  99. ...props
  100. }: ModuleProps) {
  101. const otherConfigs: string[] = [];
  102. let sentryInitContent: string[] = [
  103. `dsn="${dsn}",`,
  104. `integrations=[DjangoIntegration()],`,
  105. piiConfiguration.trim(),
  106. ];
  107. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  108. otherConfigs.push(performanceConfiguration.trim());
  109. }
  110. if (activeProductSelection.includes(ProductSolution.PROFILING)) {
  111. otherConfigs.push(profilingConfiguration.trim());
  112. }
  113. if (otherConfigs.length > 0) {
  114. sentryInitContent = sentryInitContent.concat(otherConfigs);
  115. }
  116. return (
  117. <Layout
  118. steps={steps({
  119. sentryInitContent: sentryInitContent.join('\n'),
  120. })}
  121. {...props}
  122. />
  123. );
  124. }
  125. export default GettingStartedWithDjango;