php.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. import Alert from 'sentry/components/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 exampleSnippets from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsExampleSnippets';
  15. import {metricTagsExplanation} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  16. import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  17. import {t, tct} from 'sentry/locale';
  18. type Params = DocsParams;
  19. const getConfigureSnippet = (params: Params) => `\\Sentry\\init([
  20. 'dsn' => '${params.dsn.public}',${
  21. params.isPerformanceSelected
  22. ? `
  23. // Specify a fixed sample rate
  24. 'traces_sample_rate' => 1.0,`
  25. : ''
  26. }${
  27. params.isProfilingSelected
  28. ? `
  29. // Set a sampling rate for profiling - this is relative to traces_sample_rate
  30. 'profiles_sample_rate' => 1.0,`
  31. : ''
  32. }
  33. ]);`;
  34. const getMetricsConfigureSnippet = () => `
  35. use function \\Sentry\\init;
  36. \\Sentry\\init([
  37. 'attach_metric_code_locations' => true,
  38. ]);`;
  39. const getVerifySnippet = () => `
  40. try {
  41. $this->functionFailsForSure();
  42. } catch (\\Throwable $exception) {
  43. \\Sentry\\captureException($exception);
  44. }`;
  45. const onboarding: OnboardingConfig = {
  46. install: params => [
  47. {
  48. type: StepType.INSTALL,
  49. description: tct(
  50. 'To install the PHP SDK, you need to be using Composer in your project. For more details about Composer, see the [composerDocumentationLink:Composer documentation].',
  51. {
  52. composerDocumentationLink: <ExternalLink href="https://getcomposer.org/doc/" />,
  53. }
  54. ),
  55. configurations: [
  56. {
  57. language: 'bash',
  58. code: 'composer require sentry/sentry',
  59. },
  60. ...(params.isProfilingSelected
  61. ? [
  62. {
  63. description: t('Install the Excimer extension via PECL:'),
  64. language: 'bash',
  65. code: 'pecl install excimer',
  66. },
  67. {
  68. description: tct(
  69. "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].",
  70. {
  71. sentryPhpDocumentationLink: (
  72. <ExternalLink href="https://docs.sentry.io/platforms/php/profiling/#installation" />
  73. ),
  74. }
  75. ),
  76. },
  77. ]
  78. : []),
  79. ],
  80. },
  81. ],
  82. configure: params => [
  83. {
  84. type: StepType.CONFIGURE,
  85. description: t(
  86. 'To capture all errors, even the one during the startup of your application, you should initialize the Sentry PHP SDK as soon as possible.'
  87. ),
  88. configurations: [
  89. {
  90. language: 'php',
  91. code: getConfigureSnippet(params),
  92. additionalInfo: params.isPerformanceSelected && (
  93. <p>
  94. {tct(
  95. 'To instrument certain regions of your code, you can [instrumentationLink:create transactions to capture them].',
  96. {
  97. instrumentationLink: (
  98. <ExternalLink href="https://docs.sentry.io/platforms/php/tracing/instrumentation/custom-instrumentation/" />
  99. ),
  100. }
  101. )}
  102. </p>
  103. ),
  104. },
  105. {
  106. description: (
  107. <Alert type="warning">
  108. {tct(
  109. 'In order to receive stack trace arguments in your errors, make sure to set [code:zend.exception_ignore_args: Off] in your php.ini',
  110. {
  111. code: <code />,
  112. }
  113. )}
  114. </Alert>
  115. ),
  116. },
  117. ],
  118. },
  119. ],
  120. verify: () => [
  121. {
  122. type: StepType.VERIFY,
  123. description: t(
  124. 'In PHP you can either capture a caught exception or capture the last error with captureLastError.'
  125. ),
  126. configurations: [
  127. {
  128. language: 'php',
  129. code: getVerifySnippet(),
  130. },
  131. ],
  132. },
  133. ],
  134. nextSteps: () => [],
  135. };
  136. const customMetricsOnboarding: OnboardingConfig = {
  137. install: () => [
  138. {
  139. type: StepType.INSTALL,
  140. description: tct(
  141. 'You need a minimum version [codeVersion:4.3.0] of the Sentry PHP SDK installed.',
  142. {
  143. codeVersion: <code />,
  144. }
  145. ),
  146. configurations: [
  147. {
  148. language: 'bash',
  149. code: 'composer install sentry/sentry',
  150. },
  151. ],
  152. },
  153. ],
  154. configure: () => [
  155. {
  156. type: StepType.CONFIGURE,
  157. description: t(
  158. 'Once the SDK is installed or updated, you can enable code locations being emitted with your metrics:'
  159. ),
  160. configurations: [
  161. {
  162. code: [
  163. {
  164. label: 'PHP',
  165. value: 'php',
  166. language: 'php',
  167. code: getMetricsConfigureSnippet(),
  168. },
  169. ],
  170. },
  171. ],
  172. },
  173. ],
  174. verify: () => [
  175. {
  176. type: StepType.VERIFY,
  177. description: tct(
  178. "Then you'll be able to add metrics as [code:counters], [code:sets], [code:distributions], and [code:gauges].",
  179. {
  180. code: <code />,
  181. }
  182. ),
  183. configurations: [
  184. {
  185. description: metricTagsExplanation,
  186. },
  187. {
  188. description: t('Try out these examples:'),
  189. code: [
  190. {
  191. label: 'Counter',
  192. value: 'counter',
  193. language: 'php',
  194. code: exampleSnippets.php.counter,
  195. },
  196. {
  197. label: 'Distribution',
  198. value: 'distribution',
  199. language: 'php',
  200. code: exampleSnippets.php.distribution,
  201. },
  202. {
  203. label: 'Set',
  204. value: 'set',
  205. language: 'php',
  206. code: exampleSnippets.php.set,
  207. },
  208. {
  209. label: 'Gauge',
  210. value: 'gauge',
  211. language: 'php',
  212. code: exampleSnippets.php.gauge,
  213. },
  214. ],
  215. },
  216. {
  217. description: t(
  218. 'It can take up to 3 minutes for the data to appear in the Sentry UI.'
  219. ),
  220. },
  221. {
  222. description: tct(
  223. 'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
  224. {
  225. docsLink: (
  226. <ExternalLink href="https://docs.sentry.io/platforms/php/metrics/" />
  227. ),
  228. }
  229. ),
  230. },
  231. ],
  232. },
  233. ],
  234. };
  235. const crashReportOnboarding: OnboardingConfig = {
  236. introduction: () => getCrashReportModalIntroduction(),
  237. install: (params: Params) => getCrashReportPHPInstallStep(params),
  238. configure: () => [
  239. {
  240. type: StepType.CONFIGURE,
  241. description: getCrashReportModalConfigDescription({
  242. link: 'https://docs.sentry.io/platforms/php/user-feedback/configuration/#crash-report-modal',
  243. }),
  244. },
  245. ],
  246. verify: () => [],
  247. nextSteps: () => [],
  248. };
  249. const performanceOnboarding: OnboardingConfig = {
  250. introduction: () =>
  251. t(
  252. "Adding Performance to your PHP project is simple. Make sure you've got these basics down."
  253. ),
  254. install: onboarding.install,
  255. configure: params => [
  256. {
  257. type: StepType.CONFIGURE,
  258. description: t(
  259. '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.'
  260. ),
  261. configurations: [
  262. {
  263. description: tct(
  264. '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.',
  265. {code: <code />}
  266. ),
  267. language: 'php',
  268. code: `
  269. \\Sentry\\init([
  270. 'dsn' => '${params.dsn.public}',
  271. // Set tracesSampleRate to 1.0 to capture 100%
  272. // of transactions for performance monitoring.
  273. 'traces_sample_rate' => 1.0,
  274. ]);
  275. `,
  276. additionalInfo: tct(
  277. '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 [linkSampleTransactions:sample transactions].',
  278. {
  279. code: <code />,
  280. linkTracingOptions: (
  281. <ExternalLink href="https://docs.sentry.io/platforms/php/configuration/options/" />
  282. ),
  283. linkTracesSampler: (
  284. <ExternalLink href="https://docs.sentry.io/platforms/php/configuration/sampling/" />
  285. ),
  286. linkSampleTransactions: (
  287. <ExternalLink href="https://docs.sentry.io/platforms/php/configuration/sampling/" />
  288. ),
  289. }
  290. ),
  291. },
  292. ],
  293. },
  294. ],
  295. verify: () => [
  296. {
  297. type: StepType.VERIFY,
  298. description: tct(
  299. 'Verify that performance monitoring is working correctly with our [link:automatic instrumentation] by simply using your Node application.',
  300. {
  301. link: (
  302. <ExternalLink href="https://docs.sentry.io/platforms/php/tracing/instrumentation/automatic-instrumentation/" />
  303. ),
  304. }
  305. ),
  306. additionalInfo: tct(
  307. 'You have the option to manually construct a transaction using [link:custom instrumentation].',
  308. {
  309. link: (
  310. <ExternalLink href="https://docs.sentry.io/platforms/php/tracing/instrumentation/custom-instrumentation/" />
  311. ),
  312. }
  313. ),
  314. },
  315. ],
  316. nextSteps: () => [],
  317. };
  318. const docs: Docs = {
  319. onboarding,
  320. replayOnboardingJsLoader,
  321. customMetricsOnboarding,
  322. performanceOnboarding,
  323. crashReportOnboarding,
  324. };
  325. export default docs;