pyramid.tsx 3.2 KB

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