php.tsx 10 KB

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