tryton.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 {t, tct} from 'sentry/locale';
  6. // Configuration Start
  7. const introduction = (
  8. <p>
  9. {tct('The Tryton integration adds support for the [link:Tryton Framework Server].', {
  10. link: <ExternalLink href="https://www.tryton.org/" />,
  11. })}
  12. </p>
  13. );
  14. export const steps = ({
  15. dsn,
  16. }: Partial<Pick<ModuleProps, 'dsn'>> = {}): LayoutProps['steps'] => [
  17. {
  18. type: StepType.CONFIGURE,
  19. description: (
  20. <p>
  21. {tct(
  22. 'To configure the SDK, initialize it with the integration in a custom [code:wsgi.py] script:',
  23. {
  24. code: <code />,
  25. }
  26. )}
  27. </p>
  28. ),
  29. configurations: [
  30. {
  31. language: 'python',
  32. code: `
  33. # wsgi.py
  34. import sentry_sdk
  35. import sentry_sdk.integrations.trytond
  36. sentry_sdk.init(
  37. dsn="${dsn}",
  38. integrations=[
  39. sentry_sdk.integrations.trytond.TrytondWSGIIntegration(),
  40. ],
  41. # Set traces_sample_rate to 1.0 to capture 100%
  42. # of transactions for performance monitoring.
  43. # We recommend adjusting this value in production,
  44. traces_sample_rate=1.0,
  45. )
  46. from trytond.application import app as application
  47. # ...
  48. `,
  49. },
  50. {
  51. description: t(
  52. '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.'
  53. ),
  54. language: 'python',
  55. code: `
  56. # wsgi.py
  57. # ...
  58. from trytond.exceptions import TrytonException
  59. from trytond.exceptions import UserError
  60. @application.error_handler
  61. def _(app, request, e):
  62. if isinstance(e, TrytonException):
  63. return
  64. else:
  65. event_id = sentry_sdk.last_event_id()
  66. data = UserError('Custom message', f'{event_id}{e}')
  67. return app.make_response(request, data)
  68. `,
  69. },
  70. ],
  71. },
  72. ];
  73. // Configuration End
  74. export function GettingStartedWithTryton({dsn, ...props}: ModuleProps) {
  75. return <Layout steps={steps({dsn})} introduction={introduction} {...props} />;
  76. }
  77. export default GettingStartedWithTryton;