tryton.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. sentryInitContent,
  16. }: {
  17. sentryInitContent: 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: `# wsgi.py
  35. import sentry_sdk
  36. from sentry_sdk.integrations.trytond import TrytondWSGIIntegration
  37. sentry_sdk.init(
  38. ${sentryInitContent}
  39. )
  40. from trytond.application import app as application
  41. # ...
  42. `,
  43. },
  44. {
  45. description: t(
  46. '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.'
  47. ),
  48. language: 'python',
  49. code: `
  50. # wsgi.py
  51. # ...
  52. from trytond.exceptions import TrytonException
  53. from trytond.exceptions import UserError
  54. @application.error_handler
  55. def _(app, request, e):
  56. if isinstance(e, TrytonException):
  57. return
  58. else:
  59. event_id = sentry_sdk.last_event_id()
  60. data = UserError('Custom message', f'{event_id}{e}')
  61. return app.make_response(request, data)
  62. `,
  63. },
  64. ],
  65. },
  66. ];
  67. // Configuration End
  68. export function GettingStartedWithTryton({dsn, ...props}: ModuleProps) {
  69. const otherConfigs: string[] = [];
  70. let sentryInitContent: string[] = [
  71. ` dsn="${dsn}",`,
  72. ` integrations=[`,
  73. ` sentry_sdk.integrations.trytond.TrytondWSGIIntegration(),`,
  74. ` ],`,
  75. ];
  76. sentryInitContent = sentryInitContent.concat(otherConfigs);
  77. return (
  78. <Layout
  79. introduction={introduction}
  80. steps={steps({
  81. sentryInitContent: sentryInitContent.join('\n'),
  82. })}
  83. {...props}
  84. />
  85. );
  86. }
  87. export default GettingStartedWithTryton;