symfony.tsx 8.1 KB

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