flask.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 Flask integration adds support for the [link:Flask Framework].', {
  18. link: <ExternalLink href="https://flask.palletsprojects.com" />,
  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 [sentryFlaskCode:flask] extra:',
  33. {
  34. sentrySdkCode: <code />,
  35. sentryFlaskCode: <code />,
  36. }
  37. )}
  38. </p>
  39. ),
  40. configurations: [
  41. {
  42. language: 'bash',
  43. code: "pip install --upgrade 'sentry-sdk[flask]'",
  44. },
  45. ],
  46. },
  47. {
  48. type: StepType.CONFIGURE,
  49. description: (
  50. <p>
  51. {tct(
  52. '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:',
  53. {
  54. codeFlask: <code />,
  55. }
  56. )}
  57. </p>
  58. ),
  59. configurations: [
  60. {
  61. language: 'python',
  62. code: `
  63. import sentry_sdk
  64. from flask import Flask
  65. sentry_sdk.init(
  66. ${sentryInitContent}
  67. )
  68. app = Flask(__name__)
  69. `,
  70. },
  71. ],
  72. additionalInfo: (
  73. <p>
  74. {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. </p>
  79. ),
  80. },
  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: `from flask import Flask
  90. import sentry_sdk
  91. sentry_sdk.init(
  92. ${sentryInitContent}
  93. )
  94. app = Flask(__name__)
  95. @app.route("/")
  96. def hello_world():
  97. 1/0 # raises an error
  98. return "<p>Hello, World!</p>"
  99. `,
  100. },
  101. ],
  102. additionalInfo: (
  103. <span>
  104. <p>
  105. {tct(
  106. 'When you point your browser to [link:http://localhost:5000/] a transaction in the Performance section of Sentry will be created.',
  107. {
  108. link: <ExternalLink href="http://localhost:5000/" />,
  109. }
  110. )}
  111. </p>
  112. <p>
  113. {t(
  114. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  115. )}
  116. </p>
  117. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  118. </span>
  119. ),
  120. },
  121. ];
  122. // Configuration End
  123. export function GettingStartedWithFlask({
  124. dsn,
  125. activeProductSelection = [],
  126. ...props
  127. }: ModuleProps) {
  128. const otherConfigs: string[] = [];
  129. let sentryInitContent: string[] = [` dsn="${dsn}",`];
  130. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  131. otherConfigs.push(performanceConfiguration);
  132. }
  133. if (activeProductSelection.includes(ProductSolution.PROFILING)) {
  134. otherConfigs.push(profilingConfiguration);
  135. }
  136. sentryInitContent = sentryInitContent.concat(otherConfigs);
  137. return (
  138. <Layout
  139. introduction={introduction}
  140. steps={steps({
  141. sentryInitContent: sentryInitContent.join('\n'),
  142. })}
  143. {...props}
  144. />
  145. );
  146. }
  147. export default GettingStartedWithFlask;