php.tsx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  3. import type {
  4. Docs,
  5. DocsParams,
  6. OnboardingConfig,
  7. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  8. import {
  9. getCrashReportModalConfigDescription,
  10. getCrashReportModalIntroduction,
  11. getCrashReportPHPInstallStep,
  12. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  13. import exampleSnippets from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsExampleSnippets';
  14. import {metricTagsExplanation} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  15. import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  16. import {t, tct} from 'sentry/locale';
  17. type Params = DocsParams;
  18. const getConfigureSnippet = (params: Params) => `\\Sentry\\init([
  19. 'dsn' => '${params.dsn}',${
  20. params.isPerformanceSelected
  21. ? `
  22. // Specify a fixed sample rate
  23. 'traces_sample_rate' => 1.0,`
  24. : ''
  25. }${
  26. params.isProfilingSelected
  27. ? `
  28. // Set a sampling rate for profiling - this is relative to traces_sample_rate
  29. 'profiles_sample_rate' => 1.0,`
  30. : ''
  31. }
  32. ]);`;
  33. const getMetricsConfigureSnippet = () => `
  34. use function \\Sentry\\init;
  35. \\Sentry\\init([
  36. 'attach_metric_code_locations' => true,
  37. ]);`;
  38. const getVerifySnippet = () => `
  39. try {
  40. $this->functionFailsForSure();
  41. } catch (\\Throwable $exception) {
  42. \\Sentry\\captureException($exception);
  43. }`;
  44. const onboarding: OnboardingConfig = {
  45. install: params => [
  46. {
  47. type: StepType.INSTALL,
  48. description: tct(
  49. 'To install the PHP SDK, you need to be using Composer in your project. For more details about Composer, see the [composerDocumentationLink:Composer documentation].',
  50. {
  51. composerDocumentationLink: <ExternalLink href="https://getcomposer.org/doc/" />,
  52. }
  53. ),
  54. configurations: [
  55. {
  56. language: 'bash',
  57. code: 'composer require sentry/sentry',
  58. },
  59. ...(params.isProfilingSelected
  60. ? [
  61. {
  62. description: t('Install the Excimer extension via PECL:'),
  63. language: 'bash',
  64. code: 'pecl install excimer',
  65. },
  66. {
  67. description: tct(
  68. "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].",
  69. {
  70. sentryPhpDocumentationLink: (
  71. <ExternalLink href="https://docs.sentry.io/platforms/php/profiling/#installation" />
  72. ),
  73. }
  74. ),
  75. },
  76. ]
  77. : []),
  78. ],
  79. },
  80. ],
  81. configure: params => [
  82. {
  83. type: StepType.CONFIGURE,
  84. description: t(
  85. 'To capture all errors, even the one during the startup of your application, you should initialize the Sentry PHP SDK as soon as possible.'
  86. ),
  87. configurations: [
  88. {
  89. language: 'php',
  90. code: getConfigureSnippet(params),
  91. additionalInfo: params.isPerformanceSelected && (
  92. <p>
  93. {tct(
  94. 'To instrument certain regions of your code, you can [instrumentationLink:create transactions to capture them].',
  95. {
  96. instrumentationLink: (
  97. <ExternalLink href="https://docs.sentry.io/platforms/php/tracing/instrumentation/custom-instrumentation/" />
  98. ),
  99. }
  100. )}
  101. </p>
  102. ),
  103. },
  104. ],
  105. },
  106. ],
  107. verify: () => [
  108. {
  109. type: StepType.VERIFY,
  110. description: t(
  111. 'In PHP you can either capture a caught exception or capture the last error with captureLastError.'
  112. ),
  113. configurations: [
  114. {
  115. language: 'php',
  116. code: getVerifySnippet(),
  117. },
  118. ],
  119. },
  120. ],
  121. nextSteps: () => [],
  122. };
  123. const customMetricsOnboarding: OnboardingConfig = {
  124. install: () => [
  125. {
  126. type: StepType.INSTALL,
  127. description: tct(
  128. 'You need a minimum version [codeVersion:4.3.0] of the Sentry PHP SDK installed.',
  129. {
  130. codeVersion: <code />,
  131. }
  132. ),
  133. configurations: [
  134. {
  135. language: 'bash',
  136. code: 'composer install sentry/sentry',
  137. },
  138. ],
  139. },
  140. ],
  141. configure: () => [
  142. {
  143. type: StepType.CONFIGURE,
  144. description: t(
  145. 'Once the SDK is installed or updated, you can enable code locations being emitted with your metrics:'
  146. ),
  147. configurations: [
  148. {
  149. code: [
  150. {
  151. label: 'PHP',
  152. value: 'php',
  153. language: 'php',
  154. code: getMetricsConfigureSnippet(),
  155. },
  156. ],
  157. },
  158. ],
  159. },
  160. ],
  161. verify: () => [
  162. {
  163. type: StepType.VERIFY,
  164. description: tct(
  165. "Then you'll be able to add metrics as [codeCounters:counters], [codeSets:sets], [codeDistribution:distributions], and [codeGauge:gauges].",
  166. {
  167. codeCounters: <code />,
  168. codeSets: <code />,
  169. codeDistribution: <code />,
  170. codeGauge: <code />,
  171. codeNamespace: <code />,
  172. }
  173. ),
  174. configurations: [
  175. {
  176. description: metricTagsExplanation,
  177. },
  178. {
  179. description: t('Try out these examples:'),
  180. code: [
  181. {
  182. label: 'Counter',
  183. value: 'counter',
  184. language: 'php',
  185. code: exampleSnippets.php.counter,
  186. },
  187. {
  188. label: 'Distribution',
  189. value: 'distribution',
  190. language: 'php',
  191. code: exampleSnippets.php.distribution,
  192. },
  193. {
  194. label: 'Set',
  195. value: 'set',
  196. language: 'php',
  197. code: exampleSnippets.php.set,
  198. },
  199. {
  200. label: 'Gauge',
  201. value: 'gauge',
  202. language: 'php',
  203. code: exampleSnippets.php.gauge,
  204. },
  205. ],
  206. },
  207. {
  208. description: t(
  209. 'It can take up to 3 minutes for the data to appear in the Sentry UI.'
  210. ),
  211. },
  212. {
  213. description: tct(
  214. 'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
  215. {
  216. docsLink: (
  217. <ExternalLink href="https://docs.sentry.io/platforms/php/metrics/" />
  218. ),
  219. }
  220. ),
  221. },
  222. ],
  223. },
  224. ],
  225. };
  226. const crashReportOnboarding: OnboardingConfig = {
  227. introduction: () => getCrashReportModalIntroduction(),
  228. install: (params: Params) => getCrashReportPHPInstallStep(params),
  229. configure: () => [
  230. {
  231. type: StepType.CONFIGURE,
  232. description: getCrashReportModalConfigDescription({
  233. link: 'https://docs.sentry.io/platforms/php/user-feedback/configuration/#crash-report-modal',
  234. }),
  235. },
  236. ],
  237. verify: () => [],
  238. nextSteps: () => [],
  239. };
  240. const docs: Docs = {
  241. onboarding,
  242. replayOnboardingJsLoader,
  243. customMetricsOnboarding,
  244. crashReportOnboarding,
  245. };
  246. export default docs;