flask.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  3. import {
  4. Docs,
  5. DocsParams,
  6. OnboardingConfig,
  7. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  8. import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  9. import {t, tct} from 'sentry/locale';
  10. type Params = DocsParams;
  11. const getSdkSetupSnippet = (params: Params) => `
  12. import sentry_sdk
  13. from flask import Flask
  14. sentry_sdk.init(
  15. dsn="${params.dsn}",${
  16. params.isPerformanceSelected
  17. ? `
  18. # Set traces_sample_rate to 1.0 to capture 100%
  19. # of transactions for performance monitoring.
  20. traces_sample_rate=1.0,`
  21. : ''
  22. }${
  23. params.isProfilingSelected
  24. ? `
  25. # Set profiles_sample_rate to 1.0 to profile 100%
  26. # of sampled transactions.
  27. # We recommend adjusting this value in production.
  28. profiles_sample_rate=1.0,`
  29. : ''
  30. }
  31. )
  32. `;
  33. const onboarding: OnboardingConfig = {
  34. introduction: () =>
  35. tct('The Flask integration adds support for the [link:Flask Framework].', {
  36. link: <ExternalLink href="https://flask.palletsprojects.com" />,
  37. }),
  38. install: () => [
  39. {
  40. type: StepType.INSTALL,
  41. description: tct(
  42. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentryFlaskCode:flask] extra:',
  43. {
  44. sentrySdkCode: <code />,
  45. sentryFlaskCode: <code />,
  46. }
  47. ),
  48. configurations: [
  49. {
  50. language: 'bash',
  51. code: "pip install --upgrade 'sentry-sdk[flask]'",
  52. },
  53. ],
  54. },
  55. ],
  56. configure: (params: Params) => [
  57. {
  58. type: StepType.CONFIGURE,
  59. description: tct(
  60. 'If you have the [codeFlask:flask] package in your dependencies, the Flask integration will be enabled automatically when you initialize the Sentry SDK. Initialize the Sentry SDK before your app has been initialized:',
  61. {
  62. codeFlask: <code />,
  63. }
  64. ),
  65. configurations: [
  66. {
  67. language: 'python',
  68. code: `
  69. ${getSdkSetupSnippet(params)}
  70. app = Flask(__name__)
  71. `,
  72. },
  73. ],
  74. additionalInfo: tct(
  75. 'The above configuration captures both error and performance data. To reduce the volume of performance data captured, change [code:traces_sample_rate] to a value between 0 and 1.',
  76. {code: <code />}
  77. ),
  78. },
  79. ],
  80. verify: (params: Params) => [
  81. {
  82. type: StepType.VERIFY,
  83. description: t(
  84. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  85. ),
  86. configurations: [
  87. {
  88. language: 'python',
  89. code: `
  90. ${getSdkSetupSnippet(params)}
  91. app = Flask(__name__)
  92. @app.route("/")
  93. def hello_world():
  94. 1/0 # raises an error
  95. return "<p>Hello, World!</p>"
  96. `,
  97. },
  98. ],
  99. additionalInfo: (
  100. <span>
  101. <p>
  102. {tct(
  103. 'When you point your browser to [link:http://localhost:5000/] a transaction in the Performance section of Sentry will be created.',
  104. {
  105. link: <ExternalLink href="http://localhost:5000/" />,
  106. }
  107. )}
  108. </p>
  109. <p>
  110. {t(
  111. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  112. )}
  113. </p>
  114. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  115. </span>
  116. ),
  117. },
  118. ],
  119. nextSteps: () => [],
  120. };
  121. const docs: Docs = {
  122. onboarding,
  123. replayOnboardingJsLoader,
  124. };
  125. export default docs;