falcon.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 {ProductSolution} from 'sentry/components/onboarding/productSelection';
  6. import {t, tct} from 'sentry/locale';
  7. // Configuration Start
  8. const performanceConfiguration = ` # Set traces_sample_rate to 1.0 to capture 100%
  9. # of transactions for performance monitoring.
  10. traces_sample_rate=1.0,`;
  11. const profilingConfiguration = ` # Set profiles_sample_rate to 1.0 to profile 100%
  12. # of sampled transactions.
  13. # We recommend adjusting this value in production.
  14. profiles_sample_rate=1.0,`;
  15. const introduction = (
  16. <p>
  17. {tct('The Falcon integration adds support for the [link:Falcon Web Framework].', {
  18. link: <ExternalLink href="https://falconframework.org/" />,
  19. })}
  20. </p>
  21. );
  22. export const steps = ({
  23. sentryInitContent,
  24. }: {
  25. sentryInitContent: string;
  26. }): LayoutProps['steps'] => [
  27. {
  28. type: StepType.INSTALL,
  29. description: (
  30. <p>
  31. {tct(
  32. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentryFalconCode:falcon] extra:',
  33. {
  34. sentrySdkCode: <code />,
  35. sentryFalconCode: <code />,
  36. }
  37. )}
  38. </p>
  39. ),
  40. configurations: [
  41. {
  42. language: 'bash',
  43. code: "$ pip install --upgrade 'sentry-sdk[falcon]'",
  44. },
  45. ],
  46. },
  47. {
  48. type: StepType.CONFIGURE,
  49. description: (
  50. <p>
  51. {tct(
  52. 'If you have the [codeFalcon:falcon] package in your dependencies, the Falcon integration will be enabled automatically when you initialize the Sentry SDK. Initialize the Sentry SDK before your app has been initialized:',
  53. {
  54. codeFalcon: <code />,
  55. }
  56. )}
  57. </p>
  58. ),
  59. configurations: [
  60. {
  61. language: 'python',
  62. code: `
  63. import falcon
  64. import sentry_sdk
  65. sentry_sdk.init(
  66. ${sentryInitContent}
  67. )
  68. api = falcon.API()
  69. `,
  70. },
  71. ],
  72. },
  73. {
  74. type: StepType.VERIFY,
  75. description: t('To verify that everything is working trigger an error on purpose:'),
  76. configurations: [
  77. {
  78. language: 'python',
  79. code: `import falcon
  80. imoprt sentry_sdk
  81. sentry_sdk.init(
  82. ${sentryInitContent}
  83. )
  84. class HelloWorldResource:
  85. def on_get(self, req, resp):
  86. message = {
  87. 'hello': "world",
  88. }
  89. 1 / 0 # raises an error
  90. resp.media = message
  91. app = falcon.App()
  92. app.add_route('/', HelloWorldResource())
  93. `,
  94. },
  95. ],
  96. additionalInfo: (
  97. <div>
  98. <p>
  99. {tct(
  100. 'When you point your browser to [link:http://localhost:8000/] a transaction in the Performance section of Sentry will be created.',
  101. {
  102. link: <ExternalLink href="http://localhost:8000/" />,
  103. }
  104. )}
  105. </p>
  106. <p>
  107. {t(
  108. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  109. )}
  110. </p>
  111. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  112. </div>
  113. ),
  114. },
  115. ];
  116. // Configuration End
  117. export function GettingStartedWithFalcon({
  118. dsn,
  119. activeProductSelection = [],
  120. ...props
  121. }: ModuleProps) {
  122. const otherConfigs: string[] = [];
  123. let sentryInitContent: string[] = [` dsn="${dsn}",`];
  124. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  125. otherConfigs.push(performanceConfiguration);
  126. }
  127. if (activeProductSelection.includes(ProductSolution.PROFILING)) {
  128. otherConfigs.push(profilingConfiguration);
  129. }
  130. sentryInitContent = sentryInitContent.concat(otherConfigs);
  131. return (
  132. <Layout
  133. introduction={introduction}
  134. steps={steps({
  135. sentryInitContent: sentryInitContent.join('\n'),
  136. })}
  137. {...props}
  138. />
  139. );
  140. }
  141. export default GettingStartedWithFalcon;