symfony.tsx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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>
  70. {tct('Add your DSN to [code:config/packages/sentry.yaml]:', {code: <code />})}
  71. </p>
  72. ),
  73. language: 'php',
  74. code: `
  75. sentry:
  76. dsn: "%env(${dsn})%"
  77. `,
  78. },
  79. {
  80. description: <p>{tct('And in your [code:.env] file:', {code: <code />})}</p>,
  81. language: 'plain',
  82. code: `
  83. ###> sentry/sentry-symfony ###
  84. SENTRY_DSN="${dsn}"
  85. ###< sentry/sentry-symfony ###
  86. `,
  87. },
  88. ],
  89. },
  90. {
  91. type: StepType.VERIFY,
  92. description: (
  93. <p>
  94. {tct(
  95. 'To test that both logger error and exception are correctly sent to [sentryLink:sentry.io], you can create the following controller:',
  96. {
  97. sentryLink: <ExternalLink href="https://sentry.io" />,
  98. }
  99. )}
  100. </p>
  101. ),
  102. configurations: [
  103. {
  104. language: 'php',
  105. code: `
  106. <?php
  107. namespace App\\Controller;
  108. use Psr\\Log\\LoggerInterface;
  109. use Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController;
  110. use Symfony\\Component\\Routing\\Annotation\\Route;
  111. class SentryTestController extends AbstractController {
  112. /**
  113. * @var LoggerInterface
  114. */
  115. private $logger;
  116. public function __construct(LoggerInterface $logger)
  117. {
  118. $this->logger = $logger;
  119. }
  120. /**
  121. * @Route(name="sentry_test", path="/_sentry-test")
  122. */
  123. public function testLog()
  124. {
  125. // the following code will test if monolog integration logs to sentry
  126. $this->logger->error('My custom logged error.');
  127. // the following code will test if an uncaught exception logs to sentry
  128. throw new \\RuntimeException('Example exception.');
  129. }
  130. }
  131. `,
  132. },
  133. ],
  134. additionalInfo: (
  135. <p>
  136. {tct(
  137. "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.",
  138. {sentryLink: <ExternalLink href="https://sentry.io" />, code: <code />}
  139. )}
  140. </p>
  141. ),
  142. },
  143. {
  144. title: t('Performance monitoring'),
  145. description: (
  146. <Fragment>
  147. {t('Performance monitoring integrations to support tracing')}
  148. <p>
  149. {t(
  150. '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.'
  151. )}
  152. </p>
  153. <p>
  154. {tct(
  155. '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].',
  156. {
  157. integrationDocumentationLink: (
  158. <ExternalLink href="https://docs.sentry.io/platforms/php/guides/symfony/performance/instrumentation/automatic-instrumentation/" />
  159. ),
  160. }
  161. )}
  162. </p>
  163. </Fragment>
  164. ),
  165. configurations: [
  166. {
  167. description: (
  168. <p>
  169. {tct(
  170. "If you [strong:are not] using Symfony Flex, you'll also need to enable the bundle in [code:config/bundles.php]:",
  171. {
  172. code: <code />,
  173. strong: <strong />,
  174. }
  175. )}
  176. </p>
  177. ),
  178. language: 'php',
  179. code: `
  180. <?php
  181. return [
  182. // ...
  183. Sentry\\SentryBundle\\SentryBundle::class => ['all' => true],
  184. ];
  185. `,
  186. },
  187. ],
  188. },
  189. {
  190. title: t('Monolog Integration'),
  191. configurations: [
  192. {
  193. description: (
  194. <p>
  195. {tct(
  196. '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:',
  197. {
  198. monologLink: <ExternalLink href="https://github.com/Seldaek/monolog" />,
  199. }
  200. )}
  201. </p>
  202. ),
  203. language: 'yaml',
  204. code: `
  205. sentry:
  206. register_error_listener: false # Disables the ErrorListener to avoid duplicated log in sentry
  207. register_error_handler: false # Disables the ErrorListener, ExceptionListener and FatalErrorListener integrations of the base PHP SDK
  208. monolog:
  209. handlers:
  210. sentry:
  211. type: sentry
  212. level: !php/const Monolog\\Logger::ERROR
  213. hub_id: Sentry\\State\\HubInterface
  214. `,
  215. },
  216. {
  217. description: (
  218. <p>
  219. {tct(
  220. 'f you are using a version of [monologBundleLink:MonologBundle] prior to [code:3.7], you need to configure the handler as a service instead:',
  221. {
  222. monologBundleLink: (
  223. <ExternalLink href="https://github.com/symfony/monolog-bundle" />
  224. ),
  225. code: <code />,
  226. }
  227. )}
  228. </p>
  229. ),
  230. language: 'yaml',
  231. code: `
  232. monolog:
  233. handlers:
  234. sentry:
  235. type: service
  236. id: Sentry\\Monolog\\Handler
  237. services:
  238. Sentry\\Monolog\\Handler:
  239. arguments:
  240. $hub: '@Sentry\\State\\HubInterface'
  241. $level: !php/const Monolog\\Logger::ERROR
  242. `,
  243. },
  244. {
  245. description: (
  246. <p>
  247. {tct(
  248. 'Additionally, you can register the [code:PsrLogMessageProcessor] to resolve PSR-3 placeholders in reported messages:',
  249. {
  250. code: <code />,
  251. }
  252. )}
  253. </p>
  254. ),
  255. language: 'yaml',
  256. code: `
  257. services:
  258. Monolog\\Processor\\PsrLogMessageProcessor:
  259. tags: { name: monolog.processor, handler: sentry }
  260. `,
  261. },
  262. ],
  263. },
  264. ];
  265. // Configuration End
  266. export function GettingStartedWithSymfony({dsn, ...props}: ModuleProps) {
  267. return <Layout steps={steps({dsn})} introduction={introduction} {...props} />;
  268. }
  269. export default GettingStartedWithSymfony;