php.tsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. import {Alert} from 'sentry/components/core/alert';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import type {
  5. Docs,
  6. DocsParams,
  7. OnboardingConfig,
  8. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  9. import {
  10. getCrashReportModalConfigDescription,
  11. getCrashReportModalIntroduction,
  12. getCrashReportPHPInstallStep,
  13. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  14. import {
  15. feedbackOnboardingJsLoader,
  16. replayOnboardingJsLoader,
  17. } from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  18. import {t, tct} from 'sentry/locale';
  19. type Params = DocsParams;
  20. const getConfigureSnippet = (params: Params) => `\\Sentry\\init([
  21. 'dsn' => '${params.dsn.public}',${
  22. params.isPerformanceSelected
  23. ? `
  24. // Specify a fixed sample rate
  25. 'traces_sample_rate' => 1.0,`
  26. : ''
  27. }${
  28. params.isProfilingSelected
  29. ? `
  30. // Set a sampling rate for profiling - this is relative to traces_sample_rate
  31. 'profiles_sample_rate' => 1.0,`
  32. : ''
  33. }
  34. ]);`;
  35. const getVerifySnippet = () => `
  36. try {
  37. $this->functionFailsForSure();
  38. } catch (\\Throwable $exception) {
  39. \\Sentry\\captureException($exception);
  40. }`;
  41. const onboarding: OnboardingConfig = {
  42. install: params => [
  43. {
  44. type: StepType.INSTALL,
  45. description: tct(
  46. 'To install the PHP SDK, you need to be using Composer in your project. For more details about Composer, see the [composerDocumentationLink:Composer documentation].',
  47. {
  48. composerDocumentationLink: <ExternalLink href="https://getcomposer.org/doc/" />,
  49. }
  50. ),
  51. configurations: [
  52. {
  53. language: 'bash',
  54. code: 'composer require sentry/sentry',
  55. },
  56. ...(params.isProfilingSelected
  57. ? [
  58. {
  59. description: t('Install the Excimer extension via PECL:'),
  60. language: 'bash',
  61. code: 'pecl install excimer',
  62. },
  63. {
  64. description: tct(
  65. "The Excimer PHP extension supports PHP 7.2 and up. Excimer requires Linux or macOS and doesn't support Windows. For additional ways to install Excimer, see [sentryPhpDocumentationLink: Sentry documentation].",
  66. {
  67. sentryPhpDocumentationLink: (
  68. <ExternalLink href="https://docs.sentry.io/platforms/php/profiling/#installation" />
  69. ),
  70. }
  71. ),
  72. },
  73. ]
  74. : []),
  75. ],
  76. },
  77. ],
  78. configure: params => [
  79. {
  80. type: StepType.CONFIGURE,
  81. description: t(
  82. 'To capture all errors, even the one during the startup of your application, you should initialize the Sentry PHP SDK as soon as possible.'
  83. ),
  84. configurations: [
  85. {
  86. language: 'php',
  87. code: getConfigureSnippet(params),
  88. additionalInfo: params.isPerformanceSelected && (
  89. <p>
  90. {tct(
  91. 'To instrument certain regions of your code, you can [instrumentationLink:create transactions to capture them].',
  92. {
  93. instrumentationLink: (
  94. <ExternalLink href="https://docs.sentry.io/platforms/php/tracing/instrumentation/custom-instrumentation/" />
  95. ),
  96. }
  97. )}
  98. </p>
  99. ),
  100. },
  101. {
  102. description: (
  103. <Alert.Container>
  104. <Alert type="warning">
  105. {tct(
  106. 'In order to receive stack trace arguments in your errors, make sure to set [code:zend.exception_ignore_args: Off] in your php.ini',
  107. {
  108. code: <code />,
  109. }
  110. )}
  111. </Alert>
  112. </Alert.Container>
  113. ),
  114. },
  115. ],
  116. },
  117. ],
  118. verify: () => [
  119. {
  120. type: StepType.VERIFY,
  121. description: t(
  122. 'In PHP you can either capture a caught exception or capture the last error with captureLastError.'
  123. ),
  124. configurations: [
  125. {
  126. language: 'php',
  127. code: getVerifySnippet(),
  128. },
  129. ],
  130. },
  131. ],
  132. nextSteps: () => [],
  133. };
  134. const crashReportOnboarding: OnboardingConfig = {
  135. introduction: () => getCrashReportModalIntroduction(),
  136. install: (params: Params) => getCrashReportPHPInstallStep(params),
  137. configure: () => [
  138. {
  139. type: StepType.CONFIGURE,
  140. description: getCrashReportModalConfigDescription({
  141. link: 'https://docs.sentry.io/platforms/php/user-feedback/configuration/#crash-report-modal',
  142. }),
  143. },
  144. ],
  145. verify: () => [],
  146. nextSteps: () => [],
  147. };
  148. const performanceOnboarding: OnboardingConfig = {
  149. introduction: () =>
  150. t(
  151. "Adding Performance to your PHP project is simple. Make sure you've got these basics down."
  152. ),
  153. install: onboarding.install,
  154. configure: params => [
  155. {
  156. type: StepType.CONFIGURE,
  157. description: t(
  158. 'To capture all errors and transactions, even the one during the startup of your application, you should initialize the Sentry PHP SDK as soon as possible.'
  159. ),
  160. configurations: [
  161. {
  162. description: tct(
  163. 'To initialize the SDK before everything else, create an external file called [code:instrument.js/mjs] and make sure to import it in your apps entrypoint before anything else.',
  164. {code: <code />}
  165. ),
  166. language: 'php',
  167. code: `
  168. \\Sentry\\init([
  169. 'dsn' => '${params.dsn.public}',
  170. // Set tracesSampleRate to 1.0 to capture 100%
  171. // of transactions for performance monitoring.
  172. 'traces_sample_rate' => 1.0,
  173. ]);
  174. `,
  175. additionalInfo: tct(
  176. 'We recommend adjusting the value of [code:tracesSampleRate] in production. Learn more about tracing [linkTracingOptions:options], how to use the [linkTracesSampler:traces_sampler] function, or how to do [linkSampleTransactions:sampling].',
  177. {
  178. code: <code />,
  179. linkTracingOptions: (
  180. <ExternalLink href="https://docs.sentry.io/platforms/php/configuration/options/" />
  181. ),
  182. linkTracesSampler: (
  183. <ExternalLink href="https://docs.sentry.io/platforms/php/configuration/sampling/" />
  184. ),
  185. linkSampleTransactions: (
  186. <ExternalLink href="https://docs.sentry.io/platforms/php/configuration/sampling/" />
  187. ),
  188. }
  189. ),
  190. },
  191. ],
  192. },
  193. ],
  194. verify: () => [
  195. {
  196. type: StepType.VERIFY,
  197. description: tct(
  198. 'Verify that performance monitoring is working correctly with our [link:automatic instrumentation] by simply using your Node application.',
  199. {
  200. link: (
  201. <ExternalLink href="https://docs.sentry.io/platforms/php/tracing/instrumentation/automatic-instrumentation/" />
  202. ),
  203. }
  204. ),
  205. },
  206. ],
  207. nextSteps: () => [],
  208. };
  209. const docs: Docs = {
  210. onboarding,
  211. replayOnboardingJsLoader,
  212. performanceOnboarding,
  213. crashReportOnboarding,
  214. feedbackOnboardingJsLoader,
  215. };
  216. export default docs;