symfony.tsx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  4. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import {t, tct} from 'sentry/locale';
  7. // Configuration Start
  8. const introduction = (
  9. <p>
  10. {tct(
  11. 'Symfony is supported via the [code:sentry-symfony] package as a native bundle.',
  12. {code: <code />}
  13. )}
  14. </p>
  15. );
  16. export const steps = ({
  17. dsn,
  18. }: Partial<Pick<ModuleProps, 'dsn'>> = {}): LayoutProps['steps'] => [
  19. {
  20. type: StepType.INSTALL,
  21. configurations: [
  22. {
  23. language: 'bash',
  24. description: (
  25. <p>
  26. {tct('Install the [code:sentry/sentry-symfony] bundle:', {code: <code />})}
  27. </p>
  28. ),
  29. code: 'composer require sentry/sentry-symfony',
  30. },
  31. {
  32. language: 'yaml',
  33. description: (
  34. <p>
  35. {tct(
  36. 'Due to a bug in all versions below "6.0" of the [sensioFrameworkExtraBundleCode:SensioFrameworkExtraBundle] bundle, you will likely receive an error during the execution of the command above related to the missing [nyholmPsr7FactoryPsr17FactoryCode:NyholmPsr7FactoryPsr17Factory] class. To workaround the issue, if you are not using the PSR-7 bridge, please change the configuration of that bundle as follows:',
  37. {
  38. sensioFrameworkExtraBundleCode: <code />,
  39. nyholmPsr7FactoryPsr17FactoryCode: <code />,
  40. }
  41. )}
  42. </p>
  43. ),
  44. code: `
  45. sensio_framework_extra:
  46. psr_message:
  47. enabled: false
  48. `,
  49. additionalInfo: (
  50. <p>
  51. {tct(
  52. 'For more details about the issue see [link:https://github.com/sensiolabs/SensioFrameworkExtraBundle/pull/710].',
  53. {
  54. link: (
  55. <ExternalLink href="https://github.com/sensiolabs/SensioFrameworkExtraBundle/pull/710" />
  56. ),
  57. }
  58. )}
  59. </p>
  60. ),
  61. },
  62. ],
  63. },
  64. {
  65. type: StepType.CONFIGURE,
  66. configurations: [
  67. {
  68. description: (
  69. <p>{tct('Add your DSN to your [code:.env] file:', {code: <code />})}</p>
  70. ),
  71. language: 'plain',
  72. code: `
  73. ###> sentry/sentry-symfony ###
  74. SENTRY_DSN="${dsn}"
  75. ###< sentry/sentry-symfony ###
  76. `,
  77. },
  78. ],
  79. },
  80. {
  81. type: StepType.VERIFY,
  82. description: (
  83. <p>
  84. {tct(
  85. 'To test that both logger error and exception are correctly sent to [sentryLink:sentry.io], you can create the following controller:',
  86. {
  87. sentryLink: <ExternalLink href="https://sentry.io" />,
  88. }
  89. )}
  90. </p>
  91. ),
  92. configurations: [
  93. {
  94. language: 'php',
  95. code: `
  96. <?php
  97. namespace App\\Controller;
  98. use Psr\\Log\\LoggerInterface;
  99. use Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController;
  100. use Symfony\\Component\\Routing\\Annotation\\Route;
  101. class SentryTestController extends AbstractController {
  102. /**
  103. * @var LoggerInterface
  104. */
  105. private $logger;
  106. public function __construct(LoggerInterface $logger)
  107. {
  108. $this->logger = $logger;
  109. }
  110. /**
  111. * @Route(name="sentry_test", path="/_sentry-test")
  112. */
  113. public function testLog()
  114. {
  115. // the following code will test if monolog integration logs to sentry
  116. $this->logger->error('My custom logged error.');
  117. // the following code will test if an uncaught exception logs to sentry
  118. throw new \\RuntimeException('Example exception.');
  119. }
  120. }
  121. `,
  122. },
  123. ],
  124. additionalInfo: (
  125. <p>
  126. {tct(
  127. "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.",
  128. {sentryLink: <ExternalLink href="https://sentry.io" />, code: <code />}
  129. )}
  130. </p>
  131. ),
  132. },
  133. {
  134. title: t('Performance monitoring'),
  135. description: (
  136. <Fragment>
  137. {t('Performance monitoring integrations to support tracing')}
  138. <p>
  139. {t(
  140. 'The process of logging the events that took place during a request, often across multiple services are enabled by default. To use them, update to the latest version of the SDK.'
  141. )}
  142. </p>
  143. <p>
  144. {tct(
  145. 'These integrations hook into critical paths of the framework and of the vendors. As a result, there may be a performance penalty. To disable tracing, please see the [integrationDocumentationLink:Integrations documentation].',
  146. {
  147. integrationDocumentationLink: (
  148. <ExternalLink href="https://docs.sentry.io/platforms/php/guides/symfony/performance/instrumentation/automatic-instrumentation/" />
  149. ),
  150. }
  151. )}
  152. </p>
  153. </Fragment>
  154. ),
  155. configurations: [
  156. {
  157. description: (
  158. <p>
  159. {tct(
  160. "If you [strong:are not] using Symfony Flex, you'll also need to enable the bundle in [code:config/bundles.php]:",
  161. {
  162. code: <code />,
  163. strong: <strong />,
  164. }
  165. )}
  166. </p>
  167. ),
  168. language: 'php',
  169. code: `
  170. <?php
  171. return [
  172. // ...
  173. Sentry\\SentryBundle\\SentryBundle::class => ['all' => true],
  174. ];
  175. `,
  176. },
  177. ],
  178. },
  179. {
  180. title: t('Monolog Integration'),
  181. configurations: [
  182. {
  183. description: (
  184. <p>
  185. {tct(
  186. 'If you are using [monologLink:Monolog] to report events instead of the typical error listener approach, you need this additional configuration to log the errors correctly:',
  187. {
  188. monologLink: <ExternalLink href="https://github.com/Seldaek/monolog" />,
  189. }
  190. )}
  191. </p>
  192. ),
  193. language: 'yaml',
  194. code: `
  195. sentry:
  196. register_error_listener: false # Disables the ErrorListener to avoid duplicated log in sentry
  197. register_error_handler: false # Disables the ErrorListener, ExceptionListener and FatalErrorListener integrations of the base PHP SDK
  198. monolog:
  199. handlers:
  200. sentry:
  201. type: sentry
  202. level: !php/const Monolog\\Logger::ERROR
  203. hub_id: Sentry\\State\\HubInterface
  204. `,
  205. },
  206. {
  207. description: (
  208. <p>
  209. {tct(
  210. 'f you are using a version of [monologBundleLink:MonologBundle] prior to [code:3.7], you need to configure the handler as a service instead:',
  211. {
  212. monologBundleLink: (
  213. <ExternalLink href="https://github.com/symfony/monolog-bundle" />
  214. ),
  215. code: <code />,
  216. }
  217. )}
  218. </p>
  219. ),
  220. language: 'yaml',
  221. code: `
  222. monolog:
  223. handlers:
  224. sentry:
  225. type: service
  226. id: Sentry\\Monolog\\Handler
  227. services:
  228. Sentry\\Monolog\\Handler:
  229. arguments:
  230. $hub: '@Sentry\\State\\HubInterface'
  231. $level: !php/const Monolog\\Logger::ERROR
  232. `,
  233. },
  234. {
  235. description: (
  236. <p>
  237. {tct(
  238. 'Additionally, you can register the [code:PsrLogMessageProcessor] to resolve PSR-3 placeholders in reported messages:',
  239. {
  240. code: <code />,
  241. }
  242. )}
  243. </p>
  244. ),
  245. language: 'yaml',
  246. code: `
  247. services:
  248. Monolog\\Processor\\PsrLogMessageProcessor:
  249. tags: { name: monolog.processor, handler: sentry }
  250. `,
  251. },
  252. ],
  253. },
  254. ];
  255. // Configuration End
  256. export function GettingStartedWithSymfony({dsn, ...props}: ModuleProps) {
  257. return <Layout steps={steps({dsn})} introduction={introduction} {...props} />;
  258. }
  259. export default GettingStartedWithSymfony;