symfony.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. interface StepsParams {
  8. dsn: string;
  9. hasPerformance: boolean;
  10. hasProfiling: boolean;
  11. }
  12. // Configuration Start
  13. const introduction = (
  14. <p>
  15. {tct(
  16. 'Symfony is supported via the [code:sentry-symfony] package as a native bundle.',
  17. {code: <code />}
  18. )}
  19. </p>
  20. );
  21. export const steps = ({
  22. dsn,
  23. hasPerformance,
  24. hasProfiling,
  25. }: StepsParams): LayoutProps['steps'] => [
  26. {
  27. type: StepType.INSTALL,
  28. configurations: [
  29. {
  30. language: 'bash',
  31. description: (
  32. <p>
  33. {tct('Install the [code:sentry/sentry-symfony] bundle:', {code: <code />})}
  34. </p>
  35. ),
  36. code: 'composer require sentry/sentry-symfony',
  37. },
  38. ...(hasProfiling
  39. ? [
  40. {
  41. description: t('Install the Excimer extension via PECL:'),
  42. language: 'bash',
  43. code: 'pecl install excimer',
  44. },
  45. ]
  46. : []),
  47. ],
  48. },
  49. {
  50. type: StepType.CONFIGURE,
  51. configurations: [
  52. {
  53. description: (
  54. <p>{tct('Add your DSN to your [code:.env] file:', {code: <code />})}</p>
  55. ),
  56. language: 'shell',
  57. code: `
  58. ###> sentry/sentry-symfony ###
  59. SENTRY_DSN="${dsn}"
  60. ###< sentry/sentry-symfony ###
  61. `,
  62. },
  63. ...(hasPerformance || hasProfiling
  64. ? [
  65. {
  66. description: (
  67. <p>
  68. {tct(
  69. 'Add further configuration options to your [code:config/packages/sentry.yaml] file:',
  70. {code: <code />}
  71. )}
  72. </p>
  73. ),
  74. language: 'yaml',
  75. code: `when@prod:
  76. sentry:
  77. dsn: '%env(SENTRY_DSN)%'${
  78. hasPerformance
  79. ? `
  80. # Specify a fixed sample rate
  81. traces_sample_rate: 1.0`
  82. : ''
  83. }${
  84. hasProfiling
  85. ? `
  86. # Set a sampling rate for profiling - this is relative to traces_sample_rate
  87. profiles_sample_rate: 1.0`
  88. : ''
  89. }`,
  90. },
  91. ]
  92. : []),
  93. ],
  94. },
  95. {
  96. type: StepType.VERIFY,
  97. description: (
  98. <p>
  99. {tct(
  100. 'To test that both logger error and exception are correctly sent to [sentryLink:sentry.io], you can create the following controller:',
  101. {
  102. sentryLink: <ExternalLink href="https://sentry.io" />,
  103. }
  104. )}
  105. </p>
  106. ),
  107. configurations: [
  108. {
  109. language: 'php',
  110. code: `
  111. <?php
  112. namespace App\\Controller;
  113. use Psr\\Log\\LoggerInterface;
  114. use Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController;
  115. use Symfony\\Component\\Routing\\Annotation\\Route;
  116. class SentryTestController extends AbstractController {
  117. /**
  118. * @var LoggerInterface
  119. */
  120. private $logger;
  121. public function __construct(LoggerInterface $logger)
  122. {
  123. $this->logger = $logger;
  124. }
  125. /**
  126. * @Route(name="sentry_test", path="/_sentry-test")
  127. */
  128. public function testLog()
  129. {
  130. // the following code will test if monolog integration logs to sentry
  131. $this->logger->error('My custom logged error.');
  132. // the following code will test if an uncaught exception logs to sentry
  133. throw new \\RuntimeException('Example exception.');
  134. }
  135. }
  136. `,
  137. },
  138. ],
  139. additionalInfo: (
  140. <p>
  141. {tct(
  142. "After you visit the [code:/_sentry-test page], you can view and resolve the recorded error by logging into [sentryLink:sentry.io] and opening your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.",
  143. {sentryLink: <ExternalLink href="https://sentry.io" />, code: <code />}
  144. )}
  145. </p>
  146. ),
  147. },
  148. ];
  149. // Configuration End
  150. export function GettingStartedWithSymfony({
  151. dsn,
  152. activeProductSelection = [],
  153. ...props
  154. }: ModuleProps) {
  155. const hasPerformance = activeProductSelection.includes(
  156. ProductSolution.PERFORMANCE_MONITORING
  157. );
  158. const hasProfiling = activeProductSelection.includes(ProductSolution.PROFILING);
  159. return (
  160. <Layout
  161. introduction={introduction}
  162. steps={steps({dsn, hasPerformance, hasProfiling})}
  163. {...props}
  164. />
  165. );
  166. }
  167. export default GettingStartedWithSymfony;