tryton.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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=[TrytondWSGIIntegration()],
  20. # Add data like request headers and IP for users,
  21. # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
  22. send_default_pii=True,${
  23. params.isPerformanceSelected
  24. ? `
  25. # Set traces_sample_rate to 1.0 to capture 100%
  26. # of transactions for tracing.
  27. traces_sample_rate=1.0,`
  28. : ''
  29. }${
  30. params.isProfilingSelected &&
  31. params.profilingOptions?.defaultProfilingMode !== 'continuous'
  32. ? `
  33. # Set profiles_sample_rate to 1.0 to profile 100%
  34. # of sampled transactions.
  35. # We recommend adjusting this value in production.
  36. profiles_sample_rate=1.0,`
  37. : params.isProfilingSelected &&
  38. params.profilingOptions?.defaultProfilingMode === 'continuous'
  39. ? `
  40. _experiments={
  41. # Set continuous_profiling_auto_start to True
  42. # to automatically start the profiler on when
  43. # possible.
  44. "continuous_profiling_auto_start": True,
  45. },`
  46. : ''
  47. }
  48. )
  49. from trytond.application import app as application
  50. # ...`;
  51. const getErrorHandlerSnippet = () => `
  52. # ...
  53. from trytond.exceptions import TrytonException
  54. from trytond.exceptions import UserError
  55. @application.error_handler
  56. def _(app, request, e):
  57. if isinstance(e, TrytonException):
  58. return
  59. else:
  60. event_id = sentry_sdk.last_event_id()
  61. data = UserError('Custom message', f'{event_id}{e}')
  62. return app.make_response(request, data)`;
  63. const onboarding: OnboardingConfig = {
  64. introduction: () =>
  65. tct('The Tryton integration adds support for the [link:Tryton Framework Server].', {
  66. link: <ExternalLink href="https://www.tryton.org/" />,
  67. }),
  68. install: () => [],
  69. configure: (params: Params) => [
  70. {
  71. type: StepType.CONFIGURE,
  72. description: tct(
  73. 'To configure the SDK, initialize it with the integration in a custom [code:wsgi.py] script:',
  74. {
  75. code: <code />,
  76. }
  77. ),
  78. configurations: [
  79. {
  80. code: [
  81. {
  82. label: 'wsgi.py',
  83. value: 'wsgi.py',
  84. language: 'python',
  85. code: getSdkSetupSnippet(params),
  86. },
  87. ],
  88. },
  89. {
  90. description: t(
  91. '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.'
  92. ),
  93. language: 'python',
  94. code: [
  95. {
  96. label: 'wsgi.py',
  97. value: 'wsgi.py',
  98. language: 'python',
  99. code: getErrorHandlerSnippet(),
  100. },
  101. ],
  102. },
  103. ],
  104. additionalInfo: <AlternativeConfiguration />,
  105. },
  106. ],
  107. verify: () => [],
  108. };
  109. const docs: Docs = {
  110. onboarding,
  111. crashReportOnboarding: crashReportOnboardingPython,
  112. };
  113. export default docs;