-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(core): Add scope attribute APIs #18165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
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.
3209923 to
c94bcd6
Compare
size-limit report 📦
|
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.
|
Scope::setAttribute(s) APIsa3e204d to
205752c
Compare
|
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. |
205752c to
fbbd768
Compare
|
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. |
…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' } */ ```
fbbd768 to
04d75b1
Compare
This PR adds
scope.setAttribute,scope.setAttributesandscope.removeAttributemethods, 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