You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ref(develop/scopes): Remove attribute type as a user-provided property (#15522)
This is a proposal after working on scope attributes for JS. We don't
have to merge this but IMHO it makes sense.
This PR makes a slight change to the scope attributes specification:
When users want to set a scope attribute with a unit, the previous spec
currently required them to also pass `type` explicitly.
```ts
// previously
scope.setAttribute({
simpleAttr: 'hi',
attrWithUnit: {value: 120, type: 'integer', unit: 'ms'}
})
// now
scope.setAttribute({
simpleAttr: 'hi',
attrWithUnit: {value: 120, unit: 'ms'}, // serilized to integer attribute with value 120, unit ms
attrWithoutUnit: {value: 120}, // serialized to integer attribute with value 120
attrWithObject: {foo: 'bar'} // serialized to stringified string attribute
})
```
This PR changes to spec to preferrably remove the `type` property from
the attribute object in favour of letting the SDK internally check and
set the correct type. Two advantages:
1. Less overhead for users
2. No/less room for error for languages where we can't type strictly
This is a SHOULD, so if SDKs are constrained in some way, they can still
require the user to pass the type explicitly.
Furthermore, this PR also updates a recommendation to leave set
attribute format as-is, so that users can consume the attributes in
`beforeSendLog` and other callbacks, in the same structure as they are
initially set. This again is a SHOULD because most importantly, it must
be compatible with how attributes are consumed in said callbacks today
already.
---------
Co-authored-by: Michi Hoffmann <[email protected]>
Copy file name to clipboardExpand all lines: develop-docs/sdk/telemetry/scopes.mdx
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,19 +58,18 @@ Data from all three scope types MUST be merged in a specific order before being
58
58
59
59
Users MUST be able to attach attributes to any scope using a dedicated method (e.g., `scope.setAttributes()` or `scope.setAttribute()`). These attributes follow the structure defined in the [Span Protocol](/sdk/telemetry/spans/span-protocol/#attribute-object-properties).
60
60
61
-
Attributes are key-value pairs where each value is an object containing:
61
+
Attributes are key-value pairs where each value is either a an attribute value or an object containing:
62
62
63
-
-`type`: The data type (`"string"`, `"integer"`, `"double"`, `"boolean"`, `"string[]"`, `"integer[]"` and `"double[]"`)
64
63
-`value`: The actual attribute value, which MUST match the specified type
65
-
-`unit` (optional): The unit of measurement (e.g., `"ms"`, `"s"`, `"bytes"`, `"count"`, `"percent"`)
64
+
-`unit` (optional): The unit of measurement (e.g., `"ms"`, `"s"`, `"bytes"`, `"count"`, `"percent"` or any other string value). SDKs MAY NOT add support for units for the moment, but MUST be able to do so at a later date without a breaking change.
65
+
-`type` (optional): The type of the attribute. SDKs SHOULD NOT expose this to users if they can reliably infer the type from the value. If not, SDKs MAY allow or require users to set the `type` explicitly.
The method SHOULD accept a dictionary/map/object where:
94
92
- Keys are attribute names (strings)
95
-
- Values are attribute objects with `type`, `value`, and optionally `unit` properties
93
+
- Values are either directly values or attribute objects/dictionaries with `value`, and optionally `unit` properties (see [example](#example-usage)).
94
+
- The SDK SHOULD infer the `type` of the attribute at serialization time to spare users from setting a (potentially incorrect) `type`. Depending on platform or constraints, the SDK MAY instead also allow or require users to set the `type` explicitly.
96
95
97
96
#### Behavior
98
97
@@ -101,6 +100,7 @@ The method SHOULD accept a dictionary/map/object where:
101
100
- Attributes set on the current scope MUST be applied only to the current log and current metric
102
101
- When the same attribute key exists in multiple scopes, the more specific scope's value takes precedence (current > isolation > global)
103
102
- When the same attribute key exists on the current log or metric, it MUST take precedence over an attribute with the same key set on any scope (log/metric > current > isolation > global)
103
+
- The SDK SHOULD keep the attribute format consistent with the user-set format until user-provided processing callbacks like `before_send_log` have been called. This ensures compatibility with already existing callbacks and avoids unexpected changes to the attribute format.
104
104
105
105
See [Span Protocol - Common Attribute Keys](/sdk/telemetry/spans/span-protocol/#common-attribute-keys) for a list of standard attributes and [Sentry Conventions](https://github.com/getsentry/sentry-conventions/) for the complete attribute registry.
0 commit comments