php.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 [codeCounters:counters], [codeSets:sets], [codeDistribution:distributions], and [codeGauge:gauges].",
  179. {
  180. codeCounters: <code />,
  181. codeSets: <code />,
  182. codeDistribution: <code />,
  183. codeGauge: <code />,
  184. codeNamespace: <code />,
  185. }
  186. ),
  187. configurations: [
  188. {
  189. description: metricTagsExplanation,
  190. },
  191. {
  192. description: t('Try out these examples:'),
  193. code: [
  194. {
  195. label: 'Counter',
  196. value: 'counter',
  197. language: 'php',
  198. code: exampleSnippets.php.counter,
  199. },
  200. {
  201. label: 'Distribution',
  202. value: 'distribution',
  203. language: 'php',
  204. code: exampleSnippets.php.distribution,
  205. },
  206. {
  207. label: 'Set',
  208. value: 'set',
  209. language: 'php',
  210. code: exampleSnippets.php.set,
  211. },
  212. {
  213. label: 'Gauge',
  214. value: 'gauge',
  215. language: 'php',
  216. code: exampleSnippets.php.gauge,
  217. },
  218. ],
  219. },
  220. {
  221. description: t(
  222. 'It can take up to 3 minutes for the data to appear in the Sentry UI.'
  223. ),
  224. },
  225. {
  226. description: tct(
  227. 'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
  228. {
  229. docsLink: (
  230. <ExternalLink href="https://docs.sentry.io/platforms/php/metrics/" />
  231. ),
  232. }
  233. ),
  234. },
  235. ],
  236. },
  237. ],
  238. };
  239. const crashReportOnboarding: OnboardingConfig = {
  240. introduction: () => getCrashReportModalIntroduction(),
  241. install: (params: Params) => getCrashReportPHPInstallStep(params),
  242. configure: () => [
  243. {
  244. type: StepType.CONFIGURE,
  245. description: getCrashReportModalConfigDescription({
  246. link: 'https://docs.sentry.io/platforms/php/user-feedback/configuration/#crash-report-modal',
  247. }),
  248. },
  249. ],
  250. verify: () => [],
  251. nextSteps: () => [],
  252. };
  253. const docs: Docs = {
  254. onboarding,
  255. replayOnboardingJsLoader,
  256. customMetricsOnboarding,
  257. crashReportOnboarding,
  258. };
  259. export default docs;