django.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 {t, tct} from 'sentry/locale';
  6. // Configuration Start
  7. export const steps = ({
  8. dsn,
  9. }: {
  10. dsn?: string;
  11. } = {}): LayoutProps['steps'] => [
  12. {
  13. type: StepType.INSTALL,
  14. description: (
  15. <p>
  16. {tct(
  17. 'The Django integration adds support for the [link:Django Web Framework] from Version 1.6 upwards.',
  18. {link: <ExternalLink href="https://www.djangoproject.com/" />}
  19. )}
  20. </p>
  21. ),
  22. configurations: [
  23. {
  24. language: 'bash',
  25. description: <p>{tct('Install [code:sentry-sdk]:', {code: <code />})}</p>,
  26. code: 'pip install --upgrade sentry-sdk',
  27. },
  28. ],
  29. },
  30. {
  31. type: StepType.CONFIGURE,
  32. description: (
  33. <p>
  34. {tct(
  35. 'To configure the SDK, initialize it with the Django integration in your [code:settings.py] file:',
  36. {code: <code />}
  37. )}
  38. </p>
  39. ),
  40. configurations: [
  41. {
  42. language: 'python',
  43. code: `
  44. import sentry_sdk
  45. from sentry_sdk.integrations.django import DjangoIntegration
  46. sentry_sdk.init(
  47. dsn="${dsn}",
  48. integrations=[DjangoIntegration()],
  49. # Set traces_sample_rate to 1.0 to capture 100%
  50. # of transactions for performance monitoring.
  51. # We recommend adjusting this value in production.
  52. traces_sample_rate=1.0,
  53. # If you wish to associate users to errors (assuming you are using
  54. # django.contrib.auth) you may enable sending PII data.
  55. send_default_pii=True
  56. )
  57. `,
  58. },
  59. ],
  60. },
  61. {
  62. type: StepType.VERIFY,
  63. description: t(
  64. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  65. ),
  66. configurations: [
  67. {
  68. language: 'python',
  69. description: t(
  70. 'Visiting this route will trigger an error that will be captured by Sentry.'
  71. ),
  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. },
  84. ];
  85. // Configuration End
  86. export function GettingStartedWithDjango({dsn, ...props}: ModuleProps) {
  87. return <Layout steps={steps({dsn})} {...props} />;
  88. }
  89. export default GettingStartedWithDjango;