tryton.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 {crashReportOnboardingPython} from 'sentry/gettingStartedDocs/python/python';
  9. import {t, tct} from 'sentry/locale';
  10. type Params = DocsParams;
  11. const getSdkSetupSnippet = (params: Params) => `
  12. import sentry_sdk
  13. from sentry_sdk.integrations.trytond import TrytondWSGIIntegration
  14. sentry_sdk.init(
  15. dsn="${params.dsn.public}",
  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 tracing.
  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 = () => `
  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. code: [
  67. {
  68. label: 'wsgi.py',
  69. value: 'wsgi.py',
  70. language: 'python',
  71. code: getSdkSetupSnippet(params),
  72. },
  73. ],
  74. },
  75. {
  76. description: t(
  77. '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.'
  78. ),
  79. language: 'python',
  80. code: [
  81. {
  82. label: 'wsgi.py',
  83. value: 'wsgi.py',
  84. language: 'python',
  85. code: getErrorHandlerSnippet(),
  86. },
  87. ],
  88. },
  89. ],
  90. },
  91. ],
  92. verify: () => [],
  93. };
  94. const docs: Docs = {
  95. onboarding,
  96. crashReportOnboarding: crashReportOnboardingPython,
  97. };
  98. export default docs;