tryton.tsx 2.6 KB

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