Skip to content

Commit 5af3d41

Browse files
authored
feat: Add metric docs for Electron SDK (#15759)
Documents getsentry/sentry-electron#1274
1 parent 4204c79 commit 5af3d41

File tree

4 files changed

+55
-184
lines changed

4 files changed

+55
-184
lines changed

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

Lines changed: 24 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ description: "Learn how to set up Sentry's Metrics feature using our supported S
55
---
66

77
<Alert level="info">
8-
Metrics is currently in Open Beta for non-Enterprise plans running the JavaScript or Python SDKs. If you'd like access, please comment with your org slug on [this GitHub discussion](https://github.com/getsentry/sentry/discussions/102275) or contact us at [email protected].
8+
Metrics is currently in Open Beta for non-Enterprise plans running the
9+
JavaScript or Python SDKs. If you'd like access, please comment with your org
10+
slug on [this GitHub
11+
discussion](https://github.com/getsentry/sentry/discussions/102275) or contact
12+
913
</Alert>
1014

1115
To set up Sentry Metrics, use the links below for supported SDKs. After it's been set up, you'll be able to send counters, gauges, and distributions from your code and view them in Sentry with direct links to related traces.
@@ -14,8 +18,6 @@ To set up Sentry Metrics, use the links below for supported SDKs. After it's bee
1418

1519
### JavaScript
1620

17-
Minimum SDK version: **10.20.0**
18-
1921
- <LinkWithPlatformIcon
2022
platform="javascript.browser"
2123
label="Browser JavaScript"
@@ -174,8 +176,6 @@ Minimum SDK version: **10.20.0**
174176

175177
### Python
176178

177-
Minimum SDK version: **2.43.0**
178-
179179
- <LinkWithPlatformIcon
180180
platform="python"
181181
label="Python"
@@ -219,23 +219,26 @@ Minimum SDK version: **2.43.0**
219219

220220
### PHP
221221

222-
- <LinkWithPlatformIcon platform="php" label="PHP" url="/platforms/php/metrics/" />
223222
- <LinkWithPlatformIcon
224-
platform="php.symfony"
225-
label="Symfony"
226-
url="/platforms/php/guides/symfony/metrics/"
223+
platform="php"
224+
label="PHP"
225+
url="/platforms/php/metrics/"
226+
/>
227+
- <LinkWithPlatformIcon
228+
platform="php.symfony"
229+
label="Symfony"
230+
url="/platforms/php/guides/symfony/metrics/"
227231
/>
228232
- <LinkWithPlatformIcon
229-
platform="php.laravel"
230-
label="Laravel"
231-
url="/platforms/php/guides/laravel/metrics/"
233+
platform="php.laravel"
234+
label="Laravel"
235+
url="/platforms/php/guides/laravel/metrics/"
232236
/>
233237

234238
## Upcoming SDKs
235239

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

238-
239242
- <LinkWithPlatformIcon
240243
platform="ruby"
241244
label="Ruby (incl. Rails)"
@@ -292,159 +295,6 @@ We're actively working on adding Metrics functionality to additional SDKs. Check
292295

293296
If you don't see your platform listed above, please reach out to us on [GitHub](https://github.com/getsentry/sentry/discussions/102275), [Discord](https://discord.gg/sentry) or contact us at [[email protected]](mailto:[email protected]), we'll get it prioritized!
294297

295-
## Quick Start Examples
296-
297-
### JavaScript Example
298-
299-
First, enable metrics in your Sentry initialization:
300-
301-
```javascript
302-
import * as Sentry from "@sentry/node"; // or your specific framework
303-
304-
Sentry.init({
305-
dsn: '<your-dsn>',
306-
_experiments: {
307-
enableMetrics: true
308-
},
309-
});
310-
```
311-
312-
Then use the metrics API to send counters, gauges, and distributions:
313-
314-
```javascript
315-
// Counter — increment a metric (defaults to +1)
316-
Sentry.metrics.count('checkout.failed', 1, {
317-
attributes: {
318-
route: '/checkout',
319-
tenant: 'acme',
320-
provider: 'stripe',
321-
},
322-
});
323-
324-
// Gauge — set a current value
325-
Sentry.metrics.gauge('queue.depth', 42, {
326-
unit: 'items',
327-
attributes: {
328-
queue: 'emails',
329-
region: 'us-east-1',
330-
},
331-
});
332-
333-
// Distribution — record numeric values to compute p95, avg, sum, etc.
334-
Sentry.metrics.distribution('cart.amount_usd', 187.5, {
335-
unit: 'usd',
336-
attributes: {
337-
currency: 'USD',
338-
tenant: 'acme',
339-
},
340-
});
341-
```
342-
343-
Each metric event includes:
344-
- **name**: The metric identifier
345-
- **kind**: counter, gauge, or distribution
346-
- **value**: The numeric value
347-
- **attributes**: Custom key-value pairs for grouping and filtering
348-
- **trace_id, span_id**: Automatically attached to link with traces
349-
- **unit** (optional): Unit of measurement
350-
- **byte_size** (optional): Size information
351-
352-
More details: [JavaScript SDK Metrics Discussion](https://github.com/getsentry/sentry-javascript/discussions/18055)
353-
354-
### Python Example
355-
356-
First, enable metrics in your Sentry initialization:
357-
358-
```python
359-
import sentry_sdk
360-
from sentry_sdk import metrics
361-
362-
sentry_sdk.init(
363-
dsn="___PUBLIC_DSN___",
364-
_experiments={
365-
"enable_metrics": True,
366-
},
367-
)
368-
```
369-
370-
Then use the metrics API to send counters, gauges, and distributions:
371-
372-
```python
373-
# Counter — increment a metric (defaults to +1)
374-
metrics.count(
375-
"checkout.failed",
376-
1,
377-
attributes={"route": "/checkout", "tenant": "acme"}
378-
)
379-
380-
# Gauge — set a current value
381-
metrics.gauge(
382-
"queue.depth",
383-
42,
384-
attributes={"queue": "emails"}
385-
)
386-
387-
# Distribution — record numeric values to compute p95, avg, sum, etc.
388-
metrics.distribution(
389-
"cart.amount_usd",
390-
187.5,
391-
attributes={"currency": "USD", "tenant": "acme"}
392-
)
393-
```
394-
395-
Each metric event includes:
396-
- **name**: The metric identifier
397-
- **kind**: counter, gauge, or distribution
398-
- **value**: The numeric value
399-
- **attributes**: Custom key-value pairs for grouping and filtering
400-
- **trace_id, span_id**: Automatically attached to link with traces
401-
- **unit** (optional): Unit of measurement
402-
403-
More details: [Python SDK Metrics Discussion](https://github.com/getsentry/sentry-python/discussions/5042)
404-
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-
448298
## Best Practices
449299

450300
### Naming Conventions
@@ -459,17 +309,18 @@ Use descriptive, dot-separated names that indicate the metric's purpose:
459309
Add attributes for any dimension you want to group or filter by:
460310

461311
```javascript
462-
Sentry.metrics.count('api.request', 1, {
312+
Sentry.metrics.count("api.request", 1, {
463313
attributes: {
464-
endpoint: '/users',
465-
method: 'GET',
466-
status: '200',
467-
region: 'us-west',
314+
endpoint: "/users",
315+
method: "GET",
316+
status: "200",
317+
region: "us-west",
468318
},
469319
});
470320
```
471321

472322
This allows you to query metrics like:
323+
473324
- `sum(api.request)` grouped by `endpoint`
474325
- `sum(api.request)` where `status:500`
475326
- `sum(api.request)` grouped by `region` where `method:POST`
@@ -478,10 +329,8 @@ This allows you to query metrics like:
478329

479330
Always specify units for clarity:
480331

481-
- Time: `ms`, `seconds`
482-
- Size: `bytes`, `kb`, `mb`
483-
- Currency: `usd`, `eur`
484-
- Count: `items`, `requests`, `users`
332+
- Time: `millisecond`, `seconds`
333+
- Size: `byte`, `kilobyte`, `megabyte`
485334

486335
### When to Instrument
487336

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
By default the SDK will attach the following attributes to a metric:
2+
3+
- `environment`: The environment set in the SDK if defined. This is sent from the SDK as `sentry.environment`.
4+
- `release`: The release set in the SDK if defined. This is sent from the SDK as `sentry.release`.
5+
- `sdk.name`: The name of the SDK that sent the metric. This is sent from the SDK as `sentry.sdk.name`.
6+
- `sdk.version`: The version of the SDK that sent the metric. This is sent from the SDK as `sentry.sdk.version`.
7+
8+
### User Attributes
9+
10+
If user information is available in the current scope, the following attributes are added to the log:
11+
12+
- `user.id`: The user ID.
13+
- `user.name`: The username.
14+
- `user.email`: The email address.
15+
16+
### Renderer Process Attributes
17+
18+
The SDK will attach renderer process information as attributes:
19+
20+
- `browser.name` (added during ingestion)
21+
- `browser.version` (added during ingestion)
22+
- `sentry.replay_id`: The replay id of the session replay that was active when the metric was collected.

platform-includes/metrics/default-attributes/javascript.mdx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
By default the SDK will attach the following attributes to a metric:
22

3-
- `sentry.environment`: The environment set in the SDK if defined.
4-
- `sentry.release`: The release set in the SDK if defined.
5-
- `sentry.sdk.name`: The name of the SDK that sent the metric.
6-
- `sentry.sdk.version`: The version of the SDK that sent the metric.
3+
- `environment`: The environment set in the SDK if defined. This is sent from the SDK as `sentry.environment`.
4+
- `release`: The release set in the SDK if defined. This is sent from the SDK as `sentry.release`.
5+
- `sdk.name`: The name of the SDK that sent the metric. This is sent from the SDK as `sentry.sdk.name`.
6+
- `sdk.version`: The version of the SDK that sent the metric. This is sent from the SDK as `sentry.sdk.version`.
77

88
### User Attributes
99

10-
The SDK will optionally attach user information as attributes (guarded by [`sendDefaultPii`](/platforms/javascript/configuration/options/#sendDefaultPii)):
11-
12-
- `user.id`
13-
- `user.name`
14-
- `user.email`
10+
If user information is available in the current scope, the following attributes are added to the log:
1511

12+
- `user.id`: The user ID.
13+
- `user.name`: The username.
14+
- `user.email`: The email address.
1615

1716
### Browser Attributes
1817

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Metrics are supported in Electron SDK version `7.5.0` and above.

0 commit comments

Comments
 (0)