laravel.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  3. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  4. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  5. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  6. import {t, tct} from 'sentry/locale';
  7. interface StepsParams {
  8. dsn: string;
  9. hasPerformance: boolean;
  10. hasProfiling: boolean;
  11. }
  12. // Configuration Start
  13. const introduction = (
  14. <p>
  15. {tct(
  16. 'This guide is for Laravel 8+. We also provide instructions for [otherVersionsLink:other versions] as well as [lumenSpecificLink:Lumen-specific instructions].',
  17. {
  18. otherVersionsLink: (
  19. <ExternalLink href="https://docs.sentry.io/platforms/php/guides/laravel/other-versions/" />
  20. ),
  21. lumenSpecificLink: (
  22. <ExternalLink href="https://docs.sentry.io/platforms/php/guides/laravel/other-versions/lumen/" />
  23. ),
  24. }
  25. )}
  26. </p>
  27. );
  28. export const steps = ({
  29. dsn,
  30. hasPerformance,
  31. hasProfiling,
  32. }: StepsParams): LayoutProps['steps'] => [
  33. {
  34. type: StepType.INSTALL,
  35. configurations: [
  36. {
  37. description: (
  38. <p>
  39. {tct('Install the [code:sentry/sentry-laravel] package:', {
  40. code: <code />,
  41. })}
  42. </p>
  43. ),
  44. language: 'bash',
  45. code: `composer require sentry/sentry-laravel`,
  46. },
  47. ...(hasProfiling
  48. ? [
  49. {
  50. description: t('Install the Excimer extension via PECL:'),
  51. language: 'bash',
  52. code: 'pecl install excimer',
  53. },
  54. ]
  55. : []),
  56. {
  57. description: (
  58. <p>
  59. {tct(
  60. 'Enable capturing unhandled exception to report to Sentry by making the following change to your [code:App/Exceptions/Handler.php]:',
  61. {
  62. code: <code />,
  63. }
  64. )}
  65. </p>
  66. ),
  67. language: 'php',
  68. code: `
  69. public function register() {
  70. $this->reportable(function (Throwable $e) {
  71. if (app()->bound('sentry')) {
  72. app('sentry')->captureException($e);
  73. }
  74. });
  75. }
  76. `,
  77. },
  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 [envCode:.env] file where you can add further configuration options:',
  93. {sentryPHPCode: <code />, dsnCode: <code />, envCode: <code />}
  94. )}
  95. </p>
  96. ),
  97. language: 'shell',
  98. code: `SENTRY_LARAVEL_DSN=${dsn}${
  99. hasPerformance
  100. ? `
  101. # Specify a fixed sample rate
  102. SENTRY_TRACES_SAMPLE_RATE=1.0`
  103. : ''
  104. }${
  105. hasProfiling
  106. ? `
  107. # Set a sampling rate for profiling - this is relative to traces_sample_rate
  108. SENTRY_PROFILES_SAMPLE_RATE=1.0`
  109. : ''
  110. }`,
  111. },
  112. ],
  113. },
  114. {
  115. type: StepType.VERIFY,
  116. configurations: [
  117. {
  118. description: (
  119. <p>
  120. {tct(
  121. 'You can test your configuration using the provided [code:sentry:test] artisan command:',
  122. {
  123. code: <code />,
  124. }
  125. )}
  126. </p>
  127. ),
  128. language: 'shell',
  129. code: 'php artisan sentry:test',
  130. },
  131. ],
  132. },
  133. ];
  134. // Configuration End
  135. export function GettingStartedWithLaravel({
  136. dsn,
  137. activeProductSelection = [],
  138. ...props
  139. }: ModuleProps) {
  140. const hasPerformance = activeProductSelection.includes(
  141. ProductSolution.PERFORMANCE_MONITORING
  142. );
  143. const hasProfiling = activeProductSelection.includes(ProductSolution.PROFILING);
  144. return (
  145. <Layout
  146. introduction={introduction}
  147. steps={steps({dsn, hasPerformance, hasProfiling})}
  148. {...props}
  149. />
  150. );
  151. }
  152. export default GettingStartedWithLaravel;