tryton.tsx 2.3 KB

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