tryton.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 {ProductSolution} from 'sentry/components/onboarding/productSelection';
  6. import {t, tct} from 'sentry/locale';
  7. // Configuration Start
  8. const profilingConfiguration = ` # Set profiles_sample_rate to 1.0 to profile 100%
  9. # of sampled transactions.
  10. # We recommend adjusting this value in production.
  11. profiles_sample_rate=1.0,`;
  12. const performanceConfiguration = ` # Set traces_sample_rate to 1.0 to capture 100%
  13. # of transactions for performance monitoring.
  14. # We recommend adjusting this value in production.
  15. traces_sample_rate=1.0,`;
  16. const introduction = (
  17. <p>
  18. {tct('The Tryton integration adds support for the [link:Tryton Framework Server].', {
  19. link: <ExternalLink href="https://www.tryton.org/" />,
  20. })}
  21. </p>
  22. );
  23. export const steps = ({
  24. sentryInitContent,
  25. }: {
  26. sentryInitContent: string;
  27. }): LayoutProps['steps'] => [
  28. {
  29. type: StepType.CONFIGURE,
  30. description: (
  31. <p>
  32. {tct(
  33. 'To configure the SDK, initialize it with the integration in a custom [code:wsgi.py] script:',
  34. {
  35. code: <code />,
  36. }
  37. )}
  38. </p>
  39. ),
  40. configurations: [
  41. {
  42. language: 'python',
  43. code: `
  44. # wsgi.py
  45. import sentry_sdk
  46. import sentry_sdk.integrations.trytond
  47. sentry_sdk.init(
  48. ${sentryInitContent}
  49. )
  50. from trytond.application import app as application
  51. # ...
  52. `,
  53. },
  54. {
  55. description: t(
  56. 'In Tryton>=5.4 an error handler can be registered to respond the client with a custom error message including the Sentry event id instead of a traceback.'
  57. ),
  58. language: 'python',
  59. code: `
  60. # wsgi.py
  61. # ...
  62. from trytond.exceptions import TrytonException
  63. from trytond.exceptions import UserError
  64. @application.error_handler
  65. def _(app, request, e):
  66. if isinstance(e, TrytonException):
  67. return
  68. else:
  69. event_id = sentry_sdk.last_event_id()
  70. data = UserError('Custom message', f'{event_id}{e}')
  71. return app.make_response(request, data)
  72. `,
  73. },
  74. ],
  75. },
  76. ];
  77. // Configuration End
  78. export function GettingStartedWithTryton({
  79. dsn,
  80. activeProductSelection = [],
  81. ...props
  82. }: ModuleProps) {
  83. const otherConfigs: string[] = [];
  84. let sentryInitContent: string[] = [
  85. ` dsn="${dsn}",`,
  86. ` integrations=[`,
  87. ` sentry_sdk.integrations.trytond.TrytondWSGIIntegration(),`,
  88. ` ],`,
  89. ];
  90. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  91. otherConfigs.push(performanceConfiguration);
  92. }
  93. if (activeProductSelection.includes(ProductSolution.PROFILING)) {
  94. otherConfigs.push(profilingConfiguration);
  95. }
  96. sentryInitContent = sentryInitContent.concat(otherConfigs);
  97. return (
  98. <Layout
  99. introduction={introduction}
  100. steps={steps({
  101. sentryInitContent: sentryInitContent.join('\n'),
  102. })}
  103. {...props}
  104. />
  105. );
  106. }
  107. export default GettingStartedWithTryton;