wsgi.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  4. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  7. import {t, tct} from 'sentry/locale';
  8. // Configuration Start
  9. const profilingConfiguration = ` # Set profiles_sample_rate to 1.0 to profile 100%
  10. # of sampled transactions.
  11. # We recommend adjusting this value in production.
  12. profiles_sample_rate=1.0,`;
  13. const performanceConfiguration = ` # Set traces_sample_rate to 1.0 to capture 100%
  14. # of transactions for performance monitoring.
  15. # We recommend adjusting this value in production.
  16. traces_sample_rate=1.0,`;
  17. export const steps = ({
  18. sentryInitContent,
  19. }: {
  20. sentryInitContent: string;
  21. }): LayoutProps['steps'] => [
  22. {
  23. type: StepType.INSTALL,
  24. description: (
  25. <Fragment>
  26. <p>
  27. {tct(
  28. 'It is recommended to use an [link:integration for your particular WSGI framework if available], as those are easier to use and capture more useful information.',
  29. {
  30. link: (
  31. <ExternalLink href="https://docs.sentry.io/platforms/python/#web-frameworks" />
  32. ),
  33. }
  34. )}
  35. </p>
  36. {t(
  37. 'If you use a WSGI framework not directly supported by the SDK, or wrote a raw WSGI app, you can use this generic WSGI middleware. It captures errors and attaches a basic amount of information for incoming requests.'
  38. )}
  39. </Fragment>
  40. ),
  41. configurations: [
  42. {
  43. language: 'python',
  44. code: `
  45. import sentry_sdk
  46. from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
  47. from myapp import wsgi_app
  48. sentry_sdk.init(
  49. ${sentryInitContent}
  50. )
  51. wsgi_app = SentryWsgiMiddleware(wsgi_app)
  52. `,
  53. },
  54. ],
  55. },
  56. ];
  57. // Configuration End
  58. export function GettingStartedWithWSGI({
  59. dsn,
  60. activeProductSelection = [],
  61. ...props
  62. }: ModuleProps) {
  63. const otherConfigs: string[] = [];
  64. let sentryInitContent: string[] = [` dsn="${dsn}",`];
  65. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  66. otherConfigs.push(performanceConfiguration);
  67. }
  68. if (activeProductSelection.includes(ProductSolution.PROFILING)) {
  69. otherConfigs.push(profilingConfiguration);
  70. }
  71. sentryInitContent = sentryInitContent.concat(otherConfigs);
  72. return (
  73. <Layout
  74. steps={steps({
  75. sentryInitContent: sentryInitContent.join('\n'),
  76. })}
  77. {...props}
  78. />
  79. );
  80. }
  81. export default GettingStartedWithWSGI;