python.tsx 2.9 KB

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