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