falcon.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  3. import {
  4. type Docs,
  5. DocsPageLocation,
  6. type DocsParams,
  7. type OnboardingConfig,
  8. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  9. import {getPythonMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  10. import {
  11. feedbackOnboardingJsLoader,
  12. replayOnboardingJsLoader,
  13. } from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  14. import {
  15. AlternativeConfiguration,
  16. crashReportOnboardingPython,
  17. featureFlagOnboarding,
  18. } from 'sentry/gettingStartedDocs/python/python';
  19. import {t, tct} from 'sentry/locale';
  20. type Params = DocsParams;
  21. const getInstallSnippet = () => `pip install --upgrade 'sentry-sdk[falcon]'`;
  22. const getSdkSetupSnippet = (params: Params) => `
  23. import falcon
  24. import sentry_sdk
  25. sentry_sdk.init(
  26. dsn="${params.dsn.public}",${
  27. params.isPerformanceSelected
  28. ? `
  29. # Set traces_sample_rate to 1.0 to capture 100%
  30. # of transactions for tracing.
  31. traces_sample_rate=1.0,`
  32. : ''
  33. }${
  34. params.isProfilingSelected &&
  35. params.profilingOptions?.defaultProfilingMode !== 'continuous'
  36. ? `
  37. # Set profiles_sample_rate to 1.0 to profile 100%
  38. # of sampled transactions.
  39. # We recommend adjusting this value in production.
  40. profiles_sample_rate=1.0,`
  41. : params.isProfilingSelected &&
  42. params.profilingOptions?.defaultProfilingMode === 'continuous'
  43. ? `
  44. _experiments={
  45. # Set continuous_profiling_auto_start to True
  46. # to automatically start the profiler on when
  47. # possible.
  48. "continuous_profiling_auto_start": True,
  49. },`
  50. : ''
  51. }
  52. )
  53. `;
  54. const onboarding: OnboardingConfig = {
  55. introduction: () =>
  56. tct('The Falcon integration adds support for the [link:Falcon Web Framework].', {
  57. link: <ExternalLink href="https://falconframework.org/" />,
  58. }),
  59. install: (params: Params) => [
  60. {
  61. type: StepType.INSTALL,
  62. description: tct(
  63. 'Install [code:sentry-sdk] from PyPI with the [code:falcon] extra:',
  64. {
  65. code: <code />,
  66. }
  67. ),
  68. configurations: [
  69. {
  70. description:
  71. params.docsLocation === DocsPageLocation.PROFILING_PAGE
  72. ? tct(
  73. 'You need a minimum version [code:1.18.0] of the [code:sentry-python] SDK for the profiling feature.',
  74. {
  75. code: <code />,
  76. }
  77. )
  78. : undefined,
  79. language: 'bash',
  80. code: getInstallSnippet(),
  81. },
  82. ],
  83. },
  84. ],
  85. configure: (params: Params) => [
  86. {
  87. type: StepType.CONFIGURE,
  88. description: tct(
  89. '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:',
  90. {
  91. codeFalcon: <code />,
  92. }
  93. ),
  94. configurations: [
  95. {
  96. language: 'python',
  97. code: `
  98. ${getSdkSetupSnippet(params)}
  99. api = falcon.API()
  100. `,
  101. },
  102. ],
  103. additionalInfo: <AlternativeConfiguration />,
  104. },
  105. ],
  106. verify: (params: Params) => [
  107. {
  108. type: StepType.VERIFY,
  109. description: t(
  110. 'To verify that everything is working, trigger an error on purpose:'
  111. ),
  112. configurations: [
  113. {
  114. language: 'python',
  115. code: `
  116. ${getSdkSetupSnippet(params)}
  117. class HelloWorldResource:
  118. def on_get(self, req, resp):
  119. message = {
  120. 'hello': "world",
  121. }
  122. 1 / 0 # raises an error
  123. resp.media = message
  124. app = falcon.App()
  125. app.add_route('/', HelloWorldResource())
  126. `,
  127. },
  128. ],
  129. additionalInfo: (
  130. <div>
  131. <p>
  132. {tct(
  133. 'When you point your browser to [link:http://localhost:8000/] a transaction in the Performance section of Sentry will be created.',
  134. {
  135. link: <ExternalLink href="http://localhost:8000/" />,
  136. }
  137. )}
  138. </p>
  139. <p>
  140. {t(
  141. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  142. )}
  143. </p>
  144. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  145. </div>
  146. ),
  147. },
  148. ],
  149. nextSteps: () => [],
  150. };
  151. const docs: Docs = {
  152. onboarding,
  153. replayOnboardingJsLoader,
  154. customMetricsOnboarding: getPythonMetricsOnboarding({
  155. installSnippet: getInstallSnippet(),
  156. }),
  157. crashReportOnboarding: crashReportOnboardingPython,
  158. featureFlagOnboarding,
  159. feedbackOnboardingJsLoader,
  160. };
  161. export default docs;