python.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  2. import type {
  3. Docs,
  4. DocsParams,
  5. OnboardingConfig,
  6. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  7. import {getPythonMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  8. import {t, tct} from 'sentry/locale';
  9. type Params = DocsParams;
  10. const getInstallSnippet = () => `pip install --upgrade sentry-sdk`;
  11. const getSdkSetupSnippet = (params: Params) => `
  12. import sentry_sdk
  13. sentry_sdk.init(
  14. dsn="${params.dsn}",${
  15. params.isPerformanceSelected
  16. ? `
  17. # Set traces_sample_rate to 1.0 to capture 100%
  18. # of transactions for performance monitoring.
  19. traces_sample_rate=1.0,`
  20. : ''
  21. }${
  22. params.isProfilingSelected
  23. ? `
  24. # Set profiles_sample_rate to 1.0 to profile 100%
  25. # of sampled transactions.
  26. # We recommend adjusting this value in production.
  27. profiles_sample_rate=1.0,`
  28. : ''
  29. }
  30. )`;
  31. const onboarding: OnboardingConfig = {
  32. install: () => [
  33. {
  34. type: StepType.INSTALL,
  35. description: tct('Install our Python SDK using [code:pip]:', {
  36. code: <code />,
  37. }),
  38. configurations: [
  39. {
  40. language: 'bash',
  41. code: getInstallSnippet(),
  42. },
  43. ],
  44. },
  45. ],
  46. configure: (params: Params) => [
  47. {
  48. type: StepType.CONFIGURE,
  49. description: t(
  50. "Import and initialize the Sentry SDK early in your application's setup:"
  51. ),
  52. configurations: [
  53. {
  54. language: 'python',
  55. code: getSdkSetupSnippet(params),
  56. },
  57. ],
  58. },
  59. ],
  60. verify: () => [
  61. {
  62. type: StepType.VERIFY,
  63. description: t(
  64. 'One way to verify your setup is by intentionally causing an error that breaks your application.'
  65. ),
  66. configurations: [
  67. {
  68. language: 'python',
  69. description: t(
  70. 'Raise an unhandled Python exception by inserting a divide by zero expression into your application:'
  71. ),
  72. code: 'division_by_zero = 1 / 0',
  73. },
  74. ],
  75. },
  76. ],
  77. };
  78. const docs: Docs = {
  79. onboarding,
  80. customMetricsOnboarding: getPythonMetricsOnboarding({
  81. installSnippet: getInstallSnippet(),
  82. }),
  83. };
  84. export default docs;