Skip to content

Conversation

@Lms24
Copy link
Member

@Lms24 Lms24 commented Nov 11, 2025

This PR adds scope.setAttribute, scope.setAttributes and scope.removeAttribute methods, as specified in our develop docs.

This intial PR only enables setting the attributes (including attributes with units) as well as the usual scope data operations (clone(), update(), clear(), getSpanData()). These attributes are not yet applied to any of the telemetry we eventually want them to apply to. I'll take care of this in a follow-up PR.

closes #18140

ref https://linear.app/getsentry/project/implement-global-attributes-api-javascript-02c3c74184fc/issues

Copy link
Member Author

@Lms24 Lms24 Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In contrast to logs and metrics attribute definitions and helper functions, this one already handles array attributes as well as attributes with units. My thinking is, we introduce this here then unify logs, metrics (+ spans eventually) to use the types and APIs here. While we'll have to change the used types for logs and metrics, I don't think this is breaking as theoretically logs and metrics support unknown for attribute values.

@Lms24 Lms24 force-pushed the lms/feat-core-scope-setAttributes branch from 3209923 to c94bcd6 Compare November 11, 2025 12:32
@Lms24 Lms24 self-assigned this Nov 11, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 11, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.78 kB +0.3% +74 B 🔺
@sentry/browser - with treeshaking flags 23.27 kB +0.34% +77 B 🔺
@sentry/browser (incl. Tracing) 41.51 kB +0.2% +79 B 🔺
@sentry/browser (incl. Tracing, Profiling) 45.83 kB +0.18% +80 B 🔺
@sentry/browser (incl. Tracing, Replay) 79.92 kB +0.09% +71 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.65 kB +0.11% +76 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 84.6 kB +0.07% +52 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 96.85 kB +0.08% +76 B 🔺
@sentry/browser (incl. Feedback) 41.45 kB +0.18% +73 B 🔺
@sentry/browser (incl. sendFeedback) 29.46 kB +0.26% +76 B 🔺
@sentry/browser (incl. FeedbackAsync) 34.4 kB +0.21% +72 B 🔺
@sentry/react 26.49 kB +0.29% +74 B 🔺
@sentry/react (incl. Tracing) 43.51 kB +0.17% +73 B 🔺
@sentry/vue 29.22 kB +0.24% +69 B 🔺
@sentry/vue (incl. Tracing) 43.31 kB +0.18% +77 B 🔺
@sentry/svelte 24.79 kB +0.3% +73 B 🔺
CDN Bundle 27.09 kB +0.27% +71 B 🔺
CDN Bundle (incl. Tracing) 42.07 kB +0.14% +58 B 🔺
CDN Bundle (incl. Tracing, Replay) 78.59 kB +0.08% +56 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 84.08 kB +0.07% +58 B 🔺
CDN Bundle - uncompressed 79.46 kB +0.36% +284 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 124.83 kB +0.23% +278 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 240.86 kB +0.12% +278 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 253.63 kB +0.11% +278 B 🔺
@sentry/nextjs (client) 45.93 kB +0.21% +92 B 🔺
@sentry/sveltekit (client) 41.87 kB +0.19% +79 B 🔺
@sentry/node-core 51.1 kB +0.16% +77 B 🔺
@sentry/node 159.41 kB +0.05% +78 B 🔺
@sentry/node - without tracing 92.98 kB +0.09% +82 B 🔺
@sentry/aws-serverless 106.72 kB +0.07% +73 B 🔺

View base workflow run

@github-actions
Copy link
Contributor

github-actions bot commented Nov 11, 2025

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,757 - 9,303 -6%
GET With Sentry 1,644 19% 1,624 +1%
GET With Sentry (error only) 6,097 70% 5,898 +3%
POST Baseline 1,194 - 1,209 -1%
POST With Sentry 585 49% 562 +4%
POST With Sentry (error only) 1,064 89% 1,044 +2%
MYSQL Baseline 3,360 - 3,274 +3%
MYSQL With Sentry 372 11% 432 -14%
MYSQL With Sentry (error only) 2,649 79% 2,689 -1%

View base workflow run

@Lms24 Lms24 changed the title feat(core): Add Scope::setAttribute(s) APIs feat(core): Add scope attribute APIs Nov 11, 2025
@Lms24 Lms24 marked this pull request as ready for review November 11, 2025 16:04
@Lms24 Lms24 force-pushed the lms/feat-core-scope-setAttributes branch 2 times, most recently from a3e204d to 205752c Compare November 18, 2025 16:51
@Lms24
Copy link
Member Author

Lms24 commented Nov 19, 2025

Converting to draft because we learned yesterday that Relay doesn't yet support array attributes. So either we wait for support in Relay or we strip out the Array-related code. Units seem to get passed through but are not yet shown in the UI.

@Lms24 Lms24 marked this pull request as draft November 19, 2025 08:59
@Lms24 Lms24 force-pushed the lms/feat-core-scope-setAttributes branch from 205752c to fbbd768 Compare November 20, 2025 10:47
@Lms24 Lms24 marked this pull request as ready for review November 20, 2025 12:10
@Lms24
Copy link
Member Author

Lms24 commented Nov 20, 2025

So for now, we decided to just ship this, despite Relay still filtering out array values. Units are accepted but not shown in the UI. Which is fine. We're just future-proofing at this point.

Lms24 and others added 17 commits November 21, 2025 15:23
…ype (#18201)

Uses a conditional type to infer whether an attribute object has the
type of an official attribute by checking if it has a `value` or a
`unit`:

```ts
export type ValidatedAttributes<T> = {
  [K in keyof T]: T[K] extends { value: any } | { unit: any } ? ValidAttributeObject : unknown;
};
```

That way, TS can show an error when people attempt to use the attribute
type while still allowing non-official types.

<img width="673" height="250" alt="image"
src="https://github.com/user-attachments/assets/f635f46d-6c3f-49cb-b31f-a02a6ebf91d3"
/>



---

I also added a small helper type to generate the very long attribute
type object, so it can generate a type like this:
```ts
/*
  | { value: string; type: 'string' }
  | { value: number; type: 'integer' }
  | { value: number; type: 'double' }
  */
  ```
@Lms24 Lms24 force-pushed the lms/feat-core-scope-setAttributes branch from fbbd768 to 04d75b1 Compare November 21, 2025 14:23
@Lms24 Lms24 merged commit 3375de0 into develop Nov 21, 2025
198 checks passed
@Lms24 Lms24 deleted the lms/feat-core-scope-setAttributes branch November 21, 2025 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add attribute APIs to Scope class

6 participants