pyramid.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  3. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  4. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  5. import {t, tct} from 'sentry/locale';
  6. // Configuration Start
  7. const introduction = (
  8. <p>
  9. {tct('The Pyramid integration adds support for the [link:Pyramid Web Framework].', {
  10. link: <ExternalLink href="https://trypyramid.com/" />,
  11. })}
  12. </p>
  13. );
  14. export const steps = ({
  15. sentryInitContent,
  16. }: {
  17. sentryInitContent: string;
  18. }): LayoutProps['steps'] => [
  19. {
  20. type: StepType.INSTALL,
  21. description: <p>{tct('Install [code:sentry-sdk] from PyPI:', {code: <code />})}</p>,
  22. configurations: [
  23. {
  24. language: 'bash',
  25. code: '$ pip install --upgrade sentry-sdk',
  26. },
  27. ],
  28. },
  29. {
  30. type: StepType.CONFIGURE,
  31. description: (
  32. <p>
  33. {tct(
  34. '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:',
  35. {
  36. codePyramid: <code />,
  37. }
  38. )}
  39. </p>
  40. ),
  41. configurations: [
  42. {
  43. language: 'python',
  44. code: `
  45. from pyramid.config import Configurator
  46. import sentry_sdk
  47. sentry_sdk.init(
  48. ${sentryInitContent}
  49. )
  50. with Configurator() as config:
  51. # ...
  52. `,
  53. },
  54. ],
  55. },
  56. {
  57. type: StepType.VERIFY,
  58. description: t(
  59. 'You can easily verify your Sentry installation by creating a view that triggers an error:'
  60. ),
  61. configurations: [
  62. {
  63. language: 'python',
  64. code: `from wsgiref.simple_server import make_server
  65. from pyramid.config import Configurator
  66. from pyramid.response import Response
  67. sentry_sdk.init(
  68. ${sentryInitContent}
  69. )
  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: (
  84. <p>
  85. {tct(
  86. 'When you point your browser to [link:http://localhost:6543/] an error event will be sent to Sentry.',
  87. {
  88. link: <ExternalLink href="http://localhost:6543/" />,
  89. }
  90. )}
  91. </p>
  92. ),
  93. },
  94. ];
  95. // Configuration End
  96. export function GettingStartedWithPyramid({dsn, ...props}: ModuleProps) {
  97. const otherConfigs: string[] = [];
  98. let sentryInitContent: string[] = [` dsn="${dsn}",`];
  99. sentryInitContent = sentryInitContent.concat(otherConfigs);
  100. return (
  101. <Layout
  102. introduction={introduction}
  103. steps={steps({
  104. sentryInitContent: sentryInitContent.join('\n'),
  105. })}
  106. {...props}
  107. />
  108. );
  109. }
  110. export default GettingStartedWithPyramid;