flask.tsx 3.9 KB

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