django.tsx 3.4 KB

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