Skip to content

Commit 33586d5

Browse files
authored
feat: Document global scope attributes for logs (#15868)
Documents getsentry/sentry-javascript#18184 released in https://github.com/getsentry/sentry-javascript/releases/tag/10.32.0
1 parent e5e373f commit 33586d5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

includes/logs/javascript-usage.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,23 @@ Sentry.logger.fatal("Database connection pool exhausted", {
3636
```
3737

3838
Setting a log message is required for the Sentry SDK to send the log to Sentry.
39+
40+
With version `10.32.0` and above, you can use scope APIs to set attributes on the SDK's scopes which will be applied to all logs as long as the respective scopes are active. For the time being, only `string`, `number` and `boolean` attribute values are supported.
41+
42+
```js
43+
Sentry.geGlobalScope().setAttributes({
44+
is_admin: true,
45+
auth_provider: "sentry",
46+
});
47+
48+
Sentry.withScope((scope) => {
49+
scope.setAttribute("step", "authentication");
50+
51+
// scope attributes `is_admin`, `auth_provider` and `step` are added
52+
Sentry.logger.info(`user ${user.id} logged in`, { activeSince: 100 });
53+
Sentry.logger.info(`updated ${user.id} last activity`);
54+
});
55+
56+
// scope attributes `is_admin` and `auth_provider` are added
57+
Sentry.logger.warn("stale website version, reloading page");
58+
```

0 commit comments

Comments
 (0)