symfony.tsx 7.8 KB

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