php.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. export const steps = ({
  14. dsn,
  15. hasPerformance,
  16. hasProfiling,
  17. }: StepsParams): LayoutProps['steps'] => [
  18. {
  19. type: StepType.INSTALL,
  20. configurations: [
  21. {
  22. description: (
  23. <p>
  24. {tct(
  25. 'To install the PHP SDK, you need to be using Composer in your project. For more details about Composer, see the [composerDocumentationLink:Composer documentation].',
  26. {
  27. composerDocumentationLink: (
  28. <ExternalLink href="https://getcomposer.org/doc/" />
  29. ),
  30. }
  31. )}
  32. </p>
  33. ),
  34. language: 'bash',
  35. code: 'composer require sentry/sdk',
  36. },
  37. ...(hasProfiling
  38. ? [
  39. {
  40. description: t('Install the Excimer extension via PECL:'),
  41. language: 'bash',
  42. code: 'pecl install excimer',
  43. },
  44. ]
  45. : []),
  46. ],
  47. },
  48. {
  49. type: StepType.CONFIGURE,
  50. description: t(
  51. 'To capture all errors, even the one during the startup of your application, you should initialize the Sentry PHP SDK as soon as possible.'
  52. ),
  53. configurations: [
  54. {
  55. language: 'php',
  56. code: `\\Sentry\\init([
  57. 'dsn' => '${dsn}',${
  58. hasPerformance
  59. ? `
  60. // Specify a fixed sample rate
  61. 'traces_sample_rate' => 1.0,`
  62. : ''
  63. }${
  64. hasProfiling
  65. ? `
  66. // Set a sampling rate for profiling - this is relative to traces_sample_rate
  67. 'profiles_sample_rate' => 1.0,`
  68. : ''
  69. }
  70. ]);`,
  71. additionalInfo: hasPerformance && (
  72. <p>
  73. {tct(
  74. 'To instrument certain regions of your code, you can [instrumentationLink:create transactions to capture them].',
  75. {
  76. instrumentationLink: (
  77. <ExternalLink href="https://docs.sentry.io/platforms/php/performance/instrumentation/custom-instrumentation/" />
  78. ),
  79. }
  80. )}
  81. </p>
  82. ),
  83. },
  84. ],
  85. },
  86. {
  87. type: StepType.VERIFY,
  88. description: t(
  89. 'In PHP you can either capture a caught exception or capture the last error with captureLastError.'
  90. ),
  91. configurations: [
  92. {
  93. language: 'php',
  94. code: `
  95. try {
  96. $this->functionFailsForSure();
  97. } catch (\\Throwable $exception) {
  98. \\Sentry\\captureException($exception);
  99. }`,
  100. },
  101. ],
  102. },
  103. ];
  104. // Configuration End
  105. export function GettingStartedWithPHP({
  106. dsn,
  107. activeProductSelection = [],
  108. ...props
  109. }: ModuleProps) {
  110. const hasPerformance = activeProductSelection.includes(
  111. ProductSolution.PERFORMANCE_MONITORING
  112. );
  113. const hasProfiling = activeProductSelection.includes(ProductSolution.PROFILING);
  114. return <Layout steps={steps({dsn, hasPerformance, hasProfiling})} {...props} />;
  115. }
  116. export default GettingStartedWithPHP;