tryton.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 {
  9. AlternativeConfiguration,
  10. crashReportOnboardingPython,
  11. } from 'sentry/gettingStartedDocs/python/python';
  12. import {t, tct} from 'sentry/locale';
  13. type Params = DocsParams;
  14. const getSdkSetupSnippet = (params: Params) => `
  15. import sentry_sdk
  16. from sentry_sdk.integrations.trytond import TrytondWSGIIntegration
  17. sentry_sdk.init(
  18. dsn="${params.dsn.public}",
  19. integrations:[
  20. sentry_sdk.integrations.trytond.TrytondWSGIIntegration(),
  21. ],${
  22. params.isPerformanceSelected
  23. ? `
  24. # Set traces_sample_rate to 1.0 to capture 100%
  25. # of transactions for tracing.
  26. traces_sample_rate=1.0,`
  27. : ''
  28. }${
  29. params.isProfilingSelected &&
  30. params.profilingOptions?.defaultProfilingMode !== 'continuous'
  31. ? `
  32. # Set profiles_sample_rate to 1.0 to profile 100%
  33. # of sampled transactions.
  34. # We recommend adjusting this value in production.
  35. profiles_sample_rate=1.0,`
  36. : params.isProfilingSelected &&
  37. params.profilingOptions?.defaultProfilingMode === 'continuous'
  38. ? `
  39. _experiments={
  40. # Set continuous_profiling_auto_start to True
  41. # to automatically start the profiler on when
  42. # possible.
  43. "continuous_profiling_auto_start": True,
  44. },`
  45. : ''
  46. }
  47. )
  48. from trytond.application import app as application
  49. # ...`;
  50. const getErrorHandlerSnippet = () => `
  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. const onboarding: OnboardingConfig = {
  63. introduction: () =>
  64. tct('The Tryton integration adds support for the [link:Tryton Framework Server].', {
  65. link: <ExternalLink href="https://www.tryton.org/" />,
  66. }),
  67. install: () => [],
  68. configure: (params: Params) => [
  69. {
  70. type: StepType.CONFIGURE,
  71. description: tct(
  72. 'To configure the SDK, initialize it with the integration in a custom [code:wsgi.py] script:',
  73. {
  74. code: <code />,
  75. }
  76. ),
  77. configurations: [
  78. {
  79. code: [
  80. {
  81. label: 'wsgi.py',
  82. value: 'wsgi.py',
  83. language: 'python',
  84. code: getSdkSetupSnippet(params),
  85. },
  86. ],
  87. },
  88. {
  89. description: t(
  90. '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.'
  91. ),
  92. language: 'python',
  93. code: [
  94. {
  95. label: 'wsgi.py',
  96. value: 'wsgi.py',
  97. language: 'python',
  98. code: getErrorHandlerSnippet(),
  99. },
  100. ],
  101. },
  102. ],
  103. additionalInfo: <AlternativeConfiguration />,
  104. },
  105. ],
  106. verify: () => [],
  107. };
  108. const docs: Docs = {
  109. onboarding,
  110. crashReportOnboarding: crashReportOnboardingPython,
  111. };
  112. export default docs;