php.tsx 6.7 KB

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