laravel.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. 'This guide is for Laravel 8+. We also provide instructions for [otherVersionsLink:other versions] as well as [lumenSpecificLink:Lumen-specific instructions].',
  12. {
  13. otherVersionsLink: (
  14. <ExternalLink href="https://docs.sentry.io/platforms/php/guides/laravel/other-versions/" />
  15. ),
  16. lumenSpecificLink: (
  17. <ExternalLink href="https://docs.sentry.io/platforms/php/guides/laravel/other-versions/lumen/" />
  18. ),
  19. }
  20. )}
  21. </p>
  22. );
  23. export const steps = ({
  24. dsn,
  25. }: {
  26. dsn?: string;
  27. } = {}): LayoutProps['steps'] => [
  28. {
  29. type: StepType.INSTALL,
  30. configurations: [
  31. {
  32. description: (
  33. <p>
  34. {tct('Install the [code:sentry/sentry-laravel] package:', {
  35. code: <code />,
  36. })}
  37. </p>
  38. ),
  39. language: 'bash',
  40. code: `composer require sentry/sentry-laravel`,
  41. },
  42. {
  43. description: (
  44. <p>
  45. {tct(
  46. 'Enable capturing unhandled exception to report to Sentry by making the following change to your [code:App/Exceptions/Handler.php]:',
  47. {
  48. code: <code />,
  49. }
  50. )}
  51. </p>
  52. ),
  53. language: 'php',
  54. code: `
  55. public function register() {
  56. $this->reportable(function (Throwable $e) {
  57. if (app()->bound('sentry')) {
  58. app('sentry')->captureException($e);
  59. }
  60. });
  61. }
  62. `,
  63. },
  64. ],
  65. additionalInfo: (
  66. <p>
  67. {tct(
  68. 'Alternatively, you can configure Sentry in your [laravelLogChannelLink:Laravel Log Channel], allowing you to log [codeInfo:info] and [codeDebug:debug] as well.',
  69. {
  70. codeInfo: <code />,
  71. codeDebug: <code />,
  72. laravelLogChannelLink: (
  73. <ExternalLink href="https://docs.sentry.io/platforms/php/guides/laravel/usage/#log-channels" />
  74. ),
  75. }
  76. )}
  77. </p>
  78. ),
  79. },
  80. {
  81. type: StepType.CONFIGURE,
  82. configurations: [
  83. {
  84. description: t('Configure the Sentry DSN with this command:'),
  85. language: 'shell',
  86. code: `php artisan sentry:publish --dsn=${dsn}`,
  87. },
  88. {
  89. description: (
  90. <p>
  91. {tct(
  92. 'It creates the config file ([sentryPHPCode:config/sentry.php]) and adds the [dsnCode:DSN] to your ".env" file.',
  93. {dsnCode: <code />, sentryPHPCode: <code />}
  94. )}
  95. </p>
  96. ),
  97. language: 'shell',
  98. code: `SENTRY_LARAVEL_DSN=${dsn}`,
  99. },
  100. ],
  101. },
  102. {
  103. type: StepType.VERIFY,
  104. configurations: [
  105. {
  106. description: <h5>{t('Verify With Artisan')}</h5>,
  107. configurations: [
  108. {
  109. description: (
  110. <p>
  111. {tct(
  112. 'You can test your configuration using the provided [code:sentry:test] artisan command:',
  113. {
  114. code: <code />,
  115. }
  116. )}
  117. </p>
  118. ),
  119. language: 'shell',
  120. code: 'php artisan sentry:test',
  121. },
  122. ],
  123. },
  124. {
  125. description: <h5>{t('Verify With Code')}</h5>,
  126. configurations: [
  127. {
  128. description: t(
  129. 'You can verify that Sentry is capturing errors in your Laravel application by creating a route that will throw an exception:'
  130. ),
  131. language: 'php',
  132. code: `
  133. Route::get('/debug-sentry', function () {
  134. throw new Exception('My first Sentry error!');
  135. });
  136. `,
  137. additionalInfo: t(
  138. 'Visiting this route will trigger an exception that will be captured by Sentry.'
  139. ),
  140. },
  141. ],
  142. },
  143. ],
  144. },
  145. {
  146. title: t('Performance Monitoring'),
  147. configurations: [
  148. {
  149. description: (
  150. <p>
  151. {tct(
  152. 'Set [tracesSampleRateCode:traces_sample_rate] in [sentryPhpCode:config/sentry.php] or [sentryTracesSampleRateCode:SENTRY_TRACES_SAMPLE_RATE] in your ".env" to a value greater than "0.0". Setting a value greater than "0.0" will enable Performance Monitoring, "0" (the default) will disable Performance Monitoring.',
  153. {
  154. tracesSampleRateCode: <code />,
  155. sentryPhpCode: <code />,
  156. sentryTracesSampleRateCode: <code />,
  157. }
  158. )}
  159. </p>
  160. ),
  161. language: 'shell',
  162. code: `
  163. # Be sure to lower this value in production otherwise you could burn through your quota quickly.
  164. SENTRY_TRACES_SAMPLE_RATE=1.0
  165. `,
  166. additionalInfo: (
  167. <Fragment>
  168. {t(
  169. 'The example configuration above will transmit 100% of captured traces. Be sure to lower this value in production or you could use up your quota quickly.'
  170. )}
  171. <p>
  172. {tct(
  173. 'You can also be more granular with the sample rate by using the traces_sampler option. Learn more in [usingSampleToFilterLink:Using Sampling to Filter Transaction Events].',
  174. {
  175. usingSampleToFilterLink: (
  176. <ExternalLink href="https://docs.sentry.io/platforms/php/guides/laravel/configuration/filtering/#using-sampling-to-filter-transaction-events" />
  177. ),
  178. }
  179. )}
  180. </p>
  181. <p>
  182. {tct(
  183. "Performance data is transmitted using a new event type called 'transactions', which you can learn about in Distributed Tracing.",
  184. {
  185. distributedTracingLink: (
  186. <ExternalLink href="https://docs.sentry.io/product/sentry-basics/tracing/distributed-tracing/#traces-transactions-and-spans" />
  187. ),
  188. }
  189. )}
  190. </p>
  191. </Fragment>
  192. ),
  193. },
  194. ],
  195. },
  196. {
  197. title: t('Local Development and Testing'),
  198. description: (
  199. <Fragment>
  200. {t(
  201. 'When Sentry is installed in your application, it will also be active when you are developing or running tests.'
  202. )}
  203. <p>
  204. {tct(
  205. "You most likely don't want errors to be sent to Sentry when you are developing or running tests. To avoid this, set the DSN value to [code:null] to disable sending errors to Sentry.",
  206. {
  207. code: <code />,
  208. }
  209. )}
  210. </p>
  211. <p>
  212. {tct(
  213. 'You can also do this by not defining [sentryLaravelDsnCode:SENTRY_LARAVEL_DSN] in your [envCode:.env] or by defining it as [sentryLaravelDsnNullCode:SENTRY_LARAVEL_DSN=null].',
  214. {
  215. sentryLaravelDsnNullCode: <code />,
  216. envCode: <code />,
  217. sentryLaravelDsnCode: <code />,
  218. }
  219. )}
  220. </p>
  221. <p>
  222. {t(
  223. "If you do leave Sentry enabled when developing or running tests, it's possible for it to have a negative effect on the performance of your application or test suite."
  224. )}
  225. </p>
  226. </Fragment>
  227. ),
  228. },
  229. ];
  230. // Configuration End
  231. export function GettingStartedWithLaravel({dsn, ...props}: ModuleProps) {
  232. return <Layout steps={steps({dsn})} introduction={introduction} {...props} />;
  233. }
  234. export default GettingStartedWithLaravel;