Skip to content

Commit ce5f79a

Browse files
authored
feat(js): Document scope attributes on metrics (#15934)
Documents `scope.setAttribute(s)` which will be applied to metrics once getsentry/sentry-javascript#18738 is merged and released.
1 parent 598b9fd commit ce5f79a

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

platform-includes/metrics/usage/javascript.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@ Sentry.metrics.count(
4343
);
4444
```
4545

46+
With version `10.33.0` and above, you can use scope APIs to set attributes on the SDK's scopes which will be applied to all metrics as long as the respective scopes are active. For the time being, only `string`, `number` and `boolean` attribute values are supported.
47+
48+
49+
```js
50+
Sentry.getGlobalScope().setAttributes({ is_admin: true, auth_provider: 'google' });
51+
52+
Sentry.withScope(scope => {
53+
scope.setAttribute('step', 'authentication');
54+
55+
// scope attributes `is_admin`, `auth_provider` and `step` are added
56+
Sentry.metrics.count('clicks', 1, { attributes: { activeSince: 100 } });
57+
Sentry.metrics.gauge('time_since_refresh', 4, { unit: 'hour' });
58+
});
59+
60+
// scope attributes `is_admin` and `auth_provider` are added
61+
Sentry.metrics.distribution('response_time', 283.33, { unit: 'millisecond' });
62+
```
63+
4664
### Specifying Units
4765

4866
For `gauge` and `distribution` metrics, you can specify a unit using the `unit` option. This helps Sentry display the metric value in a human-readable format.

0 commit comments

Comments
 (0)