pyramid.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 {getPythonMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  9. import {
  10. feedbackOnboardingJsLoader,
  11. replayOnboardingJsLoader,
  12. } from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  13. import {
  14. crashReportOnboardingPython,
  15. featureFlagOnboarding,
  16. } from 'sentry/gettingStartedDocs/python/python';
  17. import {t, tct} from 'sentry/locale';
  18. type Params = DocsParams;
  19. const getInstallSnippet = () => `pip install --upgrade sentry-sdk`;
  20. const getSdkSetupSnippet = (params: Params) => `
  21. from pyramid.config import Configurator
  22. import sentry_sdk
  23. sentry_sdk.init(
  24. dsn="${params.dsn.public}",
  25. )
  26. `;
  27. const onboarding: OnboardingConfig = {
  28. introduction: () =>
  29. tct('The Pyramid integration adds support for the [link:Pyramid Web Framework].', {
  30. link: <ExternalLink href="https://trypyramid.com/" />,
  31. }),
  32. install: () => [
  33. {
  34. type: StepType.INSTALL,
  35. description: tct('Install [code:sentry-sdk] from PyPI:', {code: <code />}),
  36. configurations: [
  37. {
  38. language: 'bash',
  39. code: getInstallSnippet(),
  40. },
  41. ],
  42. },
  43. ],
  44. configure: (params: Params) => [
  45. {
  46. type: StepType.CONFIGURE,
  47. description: tct(
  48. 'If you have the [codePyramid:pyramid] package in your dependencies, the Pyramid integration will be enabled automatically when you initialize the Sentry SDK. Initialize the Sentry SDK before your app has been initialized:',
  49. {
  50. codePyramid: <code />,
  51. }
  52. ),
  53. configurations: [
  54. {
  55. language: 'python',
  56. code: `
  57. ${getSdkSetupSnippet(params)}
  58. with Configurator() as config:
  59. # ...
  60. `,
  61. },
  62. ],
  63. },
  64. ],
  65. verify: (params: Params) => [
  66. {
  67. type: StepType.VERIFY,
  68. description: t(
  69. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  70. ),
  71. configurations: [
  72. {
  73. language: 'python',
  74. code: `from wsgiref.simple_server import make_server
  75. from pyramid.response import Response${getSdkSetupSnippet(params)}
  76. def hello_world(request):
  77. 1/0 # raises an error
  78. return Response('Hello World!')
  79. if __name__ == '__main__':
  80. with Configurator() as config:
  81. config.add_route('hello', '/')
  82. config.add_view(hello_world, route_name='hello')
  83. app = config.make_wsgi_app()
  84. server = make_server('0.0.0.0', 6543, app)
  85. server.serve_forever()
  86. `,
  87. },
  88. ],
  89. additionalInfo: tct(
  90. 'When you point your browser to [link:http://localhost:6543/] an error event will be sent to Sentry.',
  91. {
  92. link: <ExternalLink href="http://localhost:6543/" />,
  93. }
  94. ),
  95. },
  96. ],
  97. nextSteps: () => [],
  98. };
  99. const docs: Docs = {
  100. onboarding,
  101. replayOnboardingJsLoader,
  102. customMetricsOnboarding: getPythonMetricsOnboarding({
  103. installSnippet: getInstallSnippet(),
  104. }),
  105. crashReportOnboarding: crashReportOnboardingPython,
  106. featureFlagOnboarding,
  107. feedbackOnboardingJsLoader,
  108. };
  109. export default docs;