php.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  3. import {
  4. Docs,
  5. DocsParams,
  6. OnboardingConfig,
  7. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  8. import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  9. import {t, tct} from 'sentry/locale';
  10. type Params = DocsParams;
  11. const getConfigureSnippet = (params: Params) => `\\Sentry\\init([
  12. 'dsn' => '${params.dsn}',${
  13. params.isPerformanceSelected
  14. ? `
  15. // Specify a fixed sample rate
  16. 'traces_sample_rate' => 1.0,`
  17. : ''
  18. }${
  19. params.isProfilingSelected
  20. ? `
  21. // Set a sampling rate for profiling - this is relative to traces_sample_rate
  22. 'profiles_sample_rate' => 1.0,`
  23. : ''
  24. }
  25. ]);`;
  26. const getMetricsConfigureSnippet = () => `
  27. use function \\Sentry\\init;
  28. \\Sentry\\init([
  29. 'metric_code_locations' => true,
  30. ]);`;
  31. const getVerifySnippet = () => `
  32. try {
  33. $this->functionFailsForSure();
  34. } catch (\\Throwable $exception) {
  35. \\Sentry\\captureException($exception);
  36. }`;
  37. const getMetricsVerifySnippet = () => `
  38. use function \\Sentry\\metrics;
  39. // Add 4 to a counter named 'hits'
  40. metrics()->increment('hits', 4);
  41. metrics()->flush();
  42. // We recommend registering the flushing in a shutdownhandler
  43. register_shutdown_function(static fn () => metrics()->flush());`;
  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. : []),
  68. ],
  69. },
  70. ],
  71. configure: params => [
  72. {
  73. type: StepType.CONFIGURE,
  74. description: t(
  75. 'To capture all errors, even the one during the startup of your application, you should initialize the Sentry PHP SDK as soon as possible.'
  76. ),
  77. configurations: [
  78. {
  79. language: 'php',
  80. code: getConfigureSnippet(params),
  81. additionalInfo: params.isPerformanceSelected && (
  82. <p>
  83. {tct(
  84. 'To instrument certain regions of your code, you can [instrumentationLink:create transactions to capture them].',
  85. {
  86. instrumentationLink: (
  87. <ExternalLink href="https://docs.sentry.io/platforms/php/performance/instrumentation/custom-instrumentation/" />
  88. ),
  89. }
  90. )}
  91. </p>
  92. ),
  93. },
  94. ],
  95. },
  96. ],
  97. verify: () => [
  98. {
  99. type: StepType.VERIFY,
  100. description: t(
  101. 'In PHP you can either capture a caught exception or capture the last error with captureLastError.'
  102. ),
  103. configurations: [
  104. {
  105. language: 'php',
  106. code: getVerifySnippet(),
  107. },
  108. ],
  109. },
  110. ],
  111. nextSteps: () => [],
  112. };
  113. const customMetricsOnboarding: OnboardingConfig = {
  114. install: () => [
  115. {
  116. type: StepType.INSTALL,
  117. description: tct(
  118. 'You need a minimum version [codeVersion:4.3.0] of the Sentry PHP SDK installed.',
  119. {
  120. codeVersion: <code />,
  121. }
  122. ),
  123. configurations: [
  124. {
  125. language: 'bash',
  126. code: 'composer install sentry/sentry',
  127. },
  128. ],
  129. },
  130. ],
  131. configure: () => [
  132. {
  133. type: StepType.CONFIGURE,
  134. description: t(
  135. 'Once the SDK is installed or updated, you can enable code locations being emitted with your metrics:'
  136. ),
  137. configurations: [
  138. {
  139. code: [
  140. {
  141. label: 'PHP',
  142. value: 'php',
  143. language: 'php',
  144. code: getMetricsConfigureSnippet(),
  145. },
  146. ],
  147. },
  148. ],
  149. },
  150. ],
  151. verify: () => [
  152. {
  153. type: StepType.VERIFY,
  154. description: tct(
  155. "Then you'll be able to add metrics as [codeCounters:counters], [codeSets:sets], [codeDistribution:distributions], and [codeGauge:gauges]. Try out this example:",
  156. {
  157. codeCounters: <code />,
  158. codeSets: <code />,
  159. codeDistribution: <code />,
  160. codeGauge: <code />,
  161. codeNamespace: <code />,
  162. }
  163. ),
  164. configurations: [
  165. {
  166. code: [
  167. {
  168. label: 'PHP',
  169. value: 'php',
  170. language: 'php',
  171. code: getMetricsVerifySnippet(),
  172. },
  173. ],
  174. },
  175. {
  176. description: t(
  177. 'With a bit of delay you can see the data appear in the Sentry UI.'
  178. ),
  179. },
  180. {
  181. description: tct(
  182. 'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
  183. {
  184. docsLink: (
  185. <ExternalLink href="https://github.com/getsentry/sentry-php/discussions/1666" />
  186. ),
  187. }
  188. ),
  189. },
  190. ],
  191. },
  192. ],
  193. };
  194. const docs: Docs = {
  195. onboarding,
  196. replayOnboardingJsLoader,
  197. customMetricsOnboarding,
  198. };
  199. export default docs;