flask.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 {t, tct} from 'sentry/locale';
  6. // Configuration Start
  7. export const steps = ({
  8. dsn,
  9. }: {
  10. dsn?: string;
  11. } = {}): LayoutProps['steps'] => [
  12. {
  13. type: StepType.INSTALL,
  14. description: (
  15. <p>
  16. {tct(
  17. 'The Flask integration adds support for the [flaskWebFrameworkLink:Flask Web Framework].',
  18. {
  19. flaskWebFrameworkLink: (
  20. <ExternalLink href="https://flask.palletsprojects.com/en/2.3.x/" />
  21. ),
  22. }
  23. )}
  24. </p>
  25. ),
  26. configurations: [
  27. {
  28. language: 'bash',
  29. description: (
  30. <p>
  31. {tct('Install [code:sentry-sdk] from PyPI with the [code:flask] extra:', {
  32. code: <code />,
  33. })}
  34. </p>
  35. ),
  36. code: "pip install --upgrade 'sentry-sdk[flask]'",
  37. },
  38. ],
  39. },
  40. {
  41. type: StepType.CONFIGURE,
  42. description: t(
  43. 'To configure the SDK, initialize it with the integration before or after your app has been initialized:'
  44. ),
  45. configurations: [
  46. {
  47. language: 'python',
  48. code: `
  49. import sentry_sdk
  50. from flask import Flask
  51. from sentry_sdk.integrations.flask import FlaskIntegration
  52. sentry_sdk.init(
  53. dsn="${dsn}",
  54. integrations=[
  55. FlaskIntegration(),
  56. ],
  57. # Set traces_sample_rate to 1.0 to capture 100%
  58. # of transactions for performance monitoring.
  59. # We recommend adjusting this value in production.
  60. traces_sample_rate=1.0
  61. )
  62. app = Flask(__name__)
  63. `,
  64. },
  65. ],
  66. additionalInfo: (
  67. <p>
  68. {tct(
  69. '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.',
  70. {code: <code />}
  71. )}
  72. </p>
  73. ),
  74. },
  75. {
  76. type: StepType.VERIFY,
  77. description: t(
  78. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  79. ),
  80. configurations: [
  81. {
  82. language: 'python',
  83. code: `
  84. @app.route('/debug-sentry')
  85. def trigger_error():
  86. division_by_zero = 1 / 0
  87. `,
  88. },
  89. ],
  90. additionalInfo: t(
  91. 'Visiting this route will trigger an error that will be captured by Sentry.'
  92. ),
  93. },
  94. ];
  95. // Configuration End
  96. export function GettingStartedWithFlask({dsn, ...props}: ModuleProps) {
  97. return <Layout steps={steps({dsn})} {...props} />;
  98. }
  99. export default GettingStartedWithFlask;