pyramid.tsx 3.2 KB

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