php.tsx 7.0 KB

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