php.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. : []),
  73. ],
  74. },
  75. ],
  76. configure: params => [
  77. {
  78. type: StepType.CONFIGURE,
  79. description: t(
  80. 'To capture all errors, even the one during the startup of your application, you should initialize the Sentry PHP SDK as soon as possible.'
  81. ),
  82. configurations: [
  83. {
  84. language: 'php',
  85. code: getConfigureSnippet(params),
  86. additionalInfo: params.isPerformanceSelected && (
  87. <p>
  88. {tct(
  89. 'To instrument certain regions of your code, you can [instrumentationLink:create transactions to capture them].',
  90. {
  91. instrumentationLink: (
  92. <ExternalLink href="https://docs.sentry.io/platforms/php/performance/instrumentation/custom-instrumentation/" />
  93. ),
  94. }
  95. )}
  96. </p>
  97. ),
  98. },
  99. ],
  100. },
  101. ],
  102. verify: () => [
  103. {
  104. type: StepType.VERIFY,
  105. description: t(
  106. 'In PHP you can either capture a caught exception or capture the last error with captureLastError.'
  107. ),
  108. configurations: [
  109. {
  110. language: 'php',
  111. code: getVerifySnippet(),
  112. },
  113. ],
  114. },
  115. ],
  116. nextSteps: () => [],
  117. };
  118. const customMetricsOnboarding: OnboardingConfig = {
  119. install: () => [
  120. {
  121. type: StepType.INSTALL,
  122. description: tct(
  123. 'You need a minimum version [codeVersion:4.3.0] of the Sentry PHP SDK installed.',
  124. {
  125. codeVersion: <code />,
  126. }
  127. ),
  128. configurations: [
  129. {
  130. language: 'bash',
  131. code: 'composer install sentry/sentry',
  132. },
  133. ],
  134. },
  135. ],
  136. configure: () => [
  137. {
  138. type: StepType.CONFIGURE,
  139. description: t(
  140. 'Once the SDK is installed or updated, you can enable code locations being emitted with your metrics:'
  141. ),
  142. configurations: [
  143. {
  144. code: [
  145. {
  146. label: 'PHP',
  147. value: 'php',
  148. language: 'php',
  149. code: getMetricsConfigureSnippet(),
  150. },
  151. ],
  152. },
  153. ],
  154. },
  155. ],
  156. verify: () => [
  157. {
  158. type: StepType.VERIFY,
  159. description: tct(
  160. "Then you'll be able to add metrics as [codeCounters:counters], [codeSets:sets], [codeDistribution:distributions], and [codeGauge:gauges]. Try out this example:",
  161. {
  162. codeCounters: <code />,
  163. codeSets: <code />,
  164. codeDistribution: <code />,
  165. codeGauge: <code />,
  166. codeNamespace: <code />,
  167. }
  168. ),
  169. configurations: [
  170. {
  171. code: [
  172. {
  173. label: 'PHP',
  174. value: 'php',
  175. language: 'php',
  176. code: getMetricsVerifySnippet(),
  177. },
  178. ],
  179. },
  180. {
  181. description: t(
  182. 'With a bit of delay you can see the data appear in the Sentry UI.'
  183. ),
  184. },
  185. {
  186. description: tct(
  187. 'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
  188. {
  189. docsLink: (
  190. <ExternalLink href="https://docs.sentry.io/platforms/php/metrics/" />
  191. ),
  192. }
  193. ),
  194. },
  195. ],
  196. },
  197. ],
  198. };
  199. const crashReportOnboarding: OnboardingConfig = {
  200. introduction: () => getCrashReportModalIntroduction(),
  201. install: (params: Params) => getCrashReportPHPInstallStep(params),
  202. configure: () => [
  203. {
  204. type: StepType.CONFIGURE,
  205. description: getCrashReportModalConfigDescription({
  206. link: 'https://docs.sentry.io/platforms/php/user-feedback/configuration/#crash-report-modal',
  207. }),
  208. },
  209. ],
  210. verify: () => [],
  211. nextSteps: () => [],
  212. };
  213. const docs: Docs = {
  214. onboarding,
  215. replayOnboardingJsLoader,
  216. customMetricsOnboarding,
  217. crashReportOnboarding,
  218. };
  219. export default docs;