Skip to content

Commit 6826f57

Browse files
authored
feat(metrics): move PHP to list of supported SDKs (#15712)
## DESCRIBE YOUR PR *Tell us what you're changing and why. If your PR **resolves an issue**, please link it so it closes automatically.* ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [ ] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent e4dddb1 commit 6826f57

File tree

1 file changed

+65
-14
lines changed
  • docs/product/explore/metrics/getting-started

1 file changed

+65
-14
lines changed

docs/product/explore/metrics/getting-started/index.mdx

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,25 @@ Minimum SDK version: **2.43.0**
217217
url="/platforms/python/guides/gcp-functions/metrics/"
218218
/>
219219

220+
### PHP
221+
222+
- <LinkWithPlatformIcon platform="php" label="PHP" url="/platforms/php/metrics/" />
223+
- <LinkWithPlatformIcon
224+
platform="php.symfony"
225+
label="Symfony"
226+
url="/platforms/php/guides/symfony/metrics/"
227+
/>
228+
- <LinkWithPlatformIcon
229+
platform="php.laravel"
230+
label="Laravel"
231+
url="/platforms/php/guides/laravel/metrics/"
232+
/>
233+
220234
## Upcoming SDKs
221235

222236
We're actively working on adding Metrics functionality to additional SDKs. Check out these GitHub issues for the latest updates:
223237

224238

225-
- <LinkWithPlatformIcon
226-
platform="php"
227-
label="PHP (incl. Laravel)"
228-
url="https://github.com/getsentry/sentry-php/issues/1966"
229-
/>
230-
231239
- <LinkWithPlatformIcon
232240
platform="ruby"
233241
label="Ruby (incl. Rails)"
@@ -295,8 +303,8 @@ import * as Sentry from "@sentry/node"; // or your specific framework
295303

296304
Sentry.init({
297305
dsn: '<your-dsn>',
298-
_experiments: {
299-
enableMetrics: true
306+
_experiments: {
307+
enableMetrics: true
300308
},
301309
});
302310
```
@@ -364,22 +372,22 @@ Then use the metrics API to send counters, gauges, and distributions:
364372
```python
365373
# Counter — increment a metric (defaults to +1)
366374
metrics.count(
367-
"checkout.failed",
368-
1,
375+
"checkout.failed",
376+
1,
369377
attributes={"route": "/checkout", "tenant": "acme"}
370378
)
371379

372380
# Gauge — set a current value
373381
metrics.gauge(
374-
"queue.depth",
375-
42,
382+
"queue.depth",
383+
42,
376384
attributes={"queue": "emails"}
377385
)
378386

379387
# Distribution — record numeric values to compute p95, avg, sum, etc.
380388
metrics.distribution(
381-
"cart.amount_usd",
382-
187.5,
389+
"cart.amount_usd",
390+
187.5,
383391
attributes={"currency": "USD", "tenant": "acme"}
384392
)
385393
```
@@ -394,6 +402,49 @@ Each metric event includes:
394402

395403
More details: [Python SDK Metrics Discussion](https://github.com/getsentry/sentry-python/discussions/5042)
396404

405+
### PHP Example
406+
407+
First, enable metrics in your Sentry initialization:
408+
409+
```php
410+
\Sentry\init([
411+
'dsn' => '___PUBLIC_DSN___'
412+
]);
413+
```
414+
415+
Then use the metrics API to send counters, gauges, and distributions:
416+
417+
```php
418+
# Counter — increment a metric
419+
\Sentry\trace_metrics()->count(
420+
'checkout.failed',
421+
1,
422+
['route' => '/checkout', 'tenant' => 'acme']
423+
);
424+
425+
# Gauge — set a current value
426+
\Sentry\trace_metrics()->gauge(
427+
'queue.depth',
428+
42,
429+
['queue' => 'emails']
430+
);
431+
432+
# Distribution — record numeric values to compute p95, avg, sum, etc.
433+
\Sentry\trace_metrics()->distribution(
434+
'cart.amount_usd',
435+
187.5,
436+
['currency' => 'USD', 'tenant' => 'acme']
437+
);
438+
```
439+
440+
Each metric event includes:
441+
- **name**: The metric identifier
442+
- **kind**: counter, gauge, or distribution
443+
- **value**: The numeric value
444+
- **attributes**: Custom key-value pairs for grouping and filtering
445+
- **trace_id, span_id**: Automatically attached to link with traces
446+
- **unit** (optional): Unit of measurement
447+
397448
## Best Practices
398449

399450
### Naming Conventions

0 commit comments

Comments
 (0)