laravel.tsx 7.2 KB

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