tryton.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  3. import type {
  4. Docs,
  5. DocsParams,
  6. OnboardingConfig,
  7. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  8. import {t, tct} from 'sentry/locale';
  9. type Params = DocsParams;
  10. const getSdkSetupSnippet = (params: Params) => `
  11. # wsgi.py
  12. import sentry_sdk
  13. from sentry_sdk.integrations.trytond import TrytondWSGIIntegration
  14. sentry_sdk.init(
  15. dsn="${params.dsn}",
  16. integrations:[
  17. sentry_sdk.integrations.trytond.TrytondWSGIIntegration(),
  18. ],${
  19. params.isPerformanceSelected
  20. ? `
  21. # Set traces_sample_rate to 1.0 to capture 100%
  22. # of transactions for performance monitoring.
  23. traces_sample_rate=1.0,`
  24. : ''
  25. }${
  26. params.isProfilingSelected
  27. ? `
  28. # Set profiles_sample_rate to 1.0 to profile 100%
  29. # of sampled transactions.
  30. # We recommend adjusting this value in production.
  31. profiles_sample_rate=1.0,`
  32. : ''
  33. }
  34. )
  35. from trytond.application import app as application
  36. # ...`;
  37. const getErrorHandlerSnippet = () => `# wsgi.py
  38. # ...
  39. from trytond.exceptions import TrytonException
  40. from trytond.exceptions import UserError
  41. @application.error_handler
  42. def _(app, request, e):
  43. if isinstance(e, TrytonException):
  44. return
  45. else:
  46. event_id = sentry_sdk.last_event_id()
  47. data = UserError('Custom message', f'{event_id}{e}')
  48. return app.make_response(request, data)`;
  49. const onboarding: OnboardingConfig = {
  50. introduction: () =>
  51. tct('The Tryton integration adds support for the [link:Tryton Framework Server].', {
  52. link: <ExternalLink href="https://www.tryton.org/" />,
  53. }),
  54. install: () => [],
  55. configure: (params: Params) => [
  56. {
  57. type: StepType.CONFIGURE,
  58. description: tct(
  59. 'To configure the SDK, initialize it with the integration in a custom [code:wsgi.py] script:',
  60. {
  61. code: <code />,
  62. }
  63. ),
  64. configurations: [
  65. {
  66. language: 'python',
  67. code: getSdkSetupSnippet(params),
  68. },
  69. {
  70. description: t(
  71. '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.'
  72. ),
  73. language: 'python',
  74. code: getErrorHandlerSnippet(),
  75. },
  76. ],
  77. },
  78. ],
  79. verify: () => [],
  80. };
  81. const docs: Docs = {
  82. onboarding,
  83. };
  84. export default docs;