php.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 {t, tct} from 'sentry/locale';
  6. // Configuration Start
  7. export const steps = ({
  8. dsn,
  9. }: {
  10. dsn?: string;
  11. } = {}): LayoutProps['steps'] => [
  12. {
  13. type: StepType.INSTALL,
  14. description: (
  15. <p>
  16. {tct(
  17. 'To install the PHP SDK, you need to be using Composer in your project. For more details about Composer, see the [composerDocumentationLink:Composer documentation].',
  18. {
  19. composerDocumentationLink: (
  20. <ExternalLink href="https://getcomposer.org/doc/" />
  21. ),
  22. }
  23. )}
  24. </p>
  25. ),
  26. configurations: [
  27. {
  28. language: 'bash',
  29. code: 'composer require sentry/sdk',
  30. },
  31. ],
  32. },
  33. {
  34. type: StepType.CONFIGURE,
  35. description: t(
  36. 'To capture all errors, even the one during the startup of your application, you should initialize the Sentry PHP SDK as soon as possible.'
  37. ),
  38. configurations: [
  39. {
  40. language: 'php',
  41. code: `\\Sentry\\init(['dsn' => '${dsn}' ]);`,
  42. },
  43. ],
  44. },
  45. {
  46. type: StepType.VERIFY,
  47. description: t(
  48. 'In PHP you can either capture a caught exception or capture the last error with captureLastError.'
  49. ),
  50. configurations: [
  51. {
  52. language: 'php',
  53. code: `
  54. try {
  55. $this->functionFailsForSure();
  56. } catch (\\Throwable $exception) {
  57. \\Sentry\\captureException($exception);
  58. }
  59. // OR
  60. \\Sentry\\captureLastError();
  61. `,
  62. },
  63. ],
  64. },
  65. ];
  66. // Configuration End
  67. export function GettingStartedWithPHP({dsn, ...props}: ModuleProps) {
  68. return <Layout steps={steps({dsn})} {...props} />;
  69. }
  70. export default GettingStartedWithPHP;