python.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  2. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  5. import {t, tct} from 'sentry/locale';
  6. // Configuration Start
  7. const profilingConfiguration = ` # Set profiles_sample_rate to 1.0 to profile 100%
  8. # of sampled transactions.
  9. # We recommend adjusting this value in production.
  10. profiles_sample_rate=1.0,`;
  11. const performanceConfiguration = ` # Set traces_sample_rate to 1.0 to capture 100%
  12. # of transactions for performance monitoring.
  13. # We recommend adjusting this value in production.
  14. traces_sample_rate=1.0,`;
  15. export const steps = ({
  16. sentryInitContent,
  17. }: {
  18. sentryInitContent?: string;
  19. } = {}): LayoutProps['steps'] => [
  20. {
  21. type: StepType.INSTALL,
  22. description: (
  23. <p>
  24. {tct('Install our Python SDK using [code:pip]:', {
  25. code: <code />,
  26. })}
  27. </p>
  28. ),
  29. configurations: [
  30. {
  31. language: 'bash',
  32. code: 'pip install --upgrade sentry-sdk',
  33. },
  34. ],
  35. },
  36. {
  37. type: StepType.CONFIGURE,
  38. description: t(
  39. "Import and initialize the Sentry SDK early in your application's setup:"
  40. ),
  41. configurations: [
  42. {
  43. language: 'python',
  44. code: `
  45. import sentry_sdk
  46. sentry_sdk.init(
  47. ${sentryInitContent}
  48. ) `,
  49. },
  50. ],
  51. additionalInfo: (
  52. <p>
  53. {tct(
  54. 'The above configuration captures both error and performance data. To reduce the volume of performance data captured, change [code:traces_sample_rate] to a value between 0 and 1.',
  55. {code: <code />}
  56. )}
  57. </p>
  58. ),
  59. },
  60. {
  61. type: StepType.VERIFY,
  62. description: t(
  63. 'One way to verify your setup is by intentionally causing an error that breaks your application.'
  64. ),
  65. configurations: [
  66. {
  67. language: 'python',
  68. description: t(
  69. 'Raise an unhandled Python exception by inserting a divide by zero expression into your application:'
  70. ),
  71. code: 'division_by_zero = 1 / 0',
  72. },
  73. ],
  74. },
  75. ];
  76. // Configuration End
  77. export function GettingStartedWithPython({
  78. dsn,
  79. activeProductSelection = [],
  80. ...props
  81. }: ModuleProps) {
  82. const otherConfigs: string[] = [];
  83. let sentryInitContent: string[] = [` dsn="${dsn}",`];
  84. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  85. otherConfigs.push(performanceConfiguration);
  86. }
  87. if (activeProductSelection.includes(ProductSolution.PROFILING)) {
  88. otherConfigs.push(profilingConfiguration);
  89. }
  90. sentryInitContent = sentryInitContent.concat(otherConfigs);
  91. return (
  92. <Layout
  93. steps={steps({
  94. sentryInitContent: sentryInitContent.join('\n'),
  95. })}
  96. {...props}
  97. />
  98. );
  99. }
  100. export default GettingStartedWithPython;