starlette.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 = tct(
  16. 'The Starlette integration adds support for the Starlette Framework.',
  17. {
  18. link: <ExternalLink href="https://www.starlette.io/" />,
  19. }
  20. );
  21. export const steps = ({
  22. sentryInitContent,
  23. }: {
  24. sentryInitContent: string;
  25. }): LayoutProps['steps'] => [
  26. {
  27. type: StepType.INSTALL,
  28. description: (
  29. <p>
  30. {tct(
  31. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentryStarletteCode:starlette] extra:',
  32. {
  33. sentrySdkCode: <code />,
  34. sentryStarletteCode: <code />,
  35. }
  36. )}
  37. </p>
  38. ),
  39. configurations: [
  40. {
  41. language: 'bash',
  42. code: "pip install --upgrade 'sentry-sdk[starlette]'",
  43. },
  44. ],
  45. },
  46. {
  47. type: StepType.CONFIGURE,
  48. description: (
  49. <p>
  50. {tct(
  51. 'If you have the [codeStarlette:starlette] package in your dependencies, the Starlette integration will be enabled automatically when you initialize the Sentry SDK. Initialize the Sentry SDK before your app has been initialized:',
  52. {
  53. codeStarlette: <code />,
  54. }
  55. )}
  56. </p>
  57. ),
  58. configurations: [
  59. {
  60. language: 'python',
  61. code: `from starlette.applications import Starlette
  62. import sentry_sdk
  63. sentry_sdk.init(
  64. ${sentryInitContent}
  65. )
  66. app = Starlette(routes=[...])
  67. `,
  68. },
  69. ],
  70. },
  71. {
  72. type: StepType.VERIFY,
  73. description: t(
  74. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  75. ),
  76. configurations: [
  77. {
  78. language: 'python',
  79. code: `from starlette.applications import Starlette
  80. from starlette.routing import Route
  81. sentry_sdk.init(
  82. ${sentryInitContent}
  83. )
  84. async def trigger_error(request):
  85. division_by_zero = 1 / 0
  86. app = Starlette(routes=[
  87. Route("/sentry-debug", trigger_error),
  88. ])
  89. `,
  90. additionalInfo: (
  91. <div>
  92. <p>
  93. {tct(
  94. 'When you point your browser to [link:http://localhost:8000/sentry-debug/] a transaction in the Performance section of Sentry will be created.',
  95. {
  96. link: <ExternalLink href="http://localhost:8000/sentry-debug/" />,
  97. }
  98. )}
  99. </p>
  100. <p>
  101. {t(
  102. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  103. )}
  104. </p>
  105. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  106. </div>
  107. ),
  108. },
  109. ],
  110. },
  111. ];
  112. // Configuration End
  113. export function GettingStartedWithStarlette({
  114. dsn,
  115. activeProductSelection = [],
  116. ...props
  117. }: ModuleProps) {
  118. const otherConfigs: string[] = [];
  119. let sentryInitContent: string[] = [` dsn="${dsn}",`];
  120. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  121. otherConfigs.push(performanceConfiguration);
  122. }
  123. if (activeProductSelection.includes(ProductSolution.PROFILING)) {
  124. otherConfigs.push(profilingConfiguration);
  125. }
  126. sentryInitContent = sentryInitContent.concat(otherConfigs);
  127. return (
  128. <Layout
  129. introduction={introduction}
  130. steps={steps({
  131. sentryInitContent: sentryInitContent.join('\n'),
  132. })}
  133. {...props}
  134. />
  135. );
  136. }
  137. export default GettingStartedWithStarlette;