Skip to content

Commit a28a03a

Browse files
Lms24cleptric
andauthored
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]>
1 parent 323cbd1 commit a28a03a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

develop-docs/sdk/telemetry/scopes.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,18 @@ Data from all three scope types MUST be merged in a specific order before being
5858

5959
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).
6060

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:
6262

63-
- `type`: The data type (`"string"`, `"integer"`, `"double"`, `"boolean"`, `"string[]"`, `"integer[]"` and `"double[]"`)
6463
- `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.
6666

6767
#### Example Usage
6868

6969
```javascript
7070
Sentry.getGlobalScope().setAttributes({
7171
"app.feature_flag.enabled": true,
7272
"app.session_duration": {
73-
type: "integer",
7473
value: 3600,
7574
unit: "s"
7675
}
@@ -81,7 +80,6 @@ Sentry.getGlobalScope().setAttributes({
8180
sentry_sdk.get_global_scope().set_attributes({
8281
"app.feature_flag.enabled": True,
8382
"app.session_duration": {
84-
"type": "integer",
8583
"value": 3600,
8684
"unit": "s"
8785
}
@@ -92,7 +90,8 @@ sentry_sdk.get_global_scope().set_attributes({
9290

9391
The method SHOULD accept a dictionary/map/object where:
9492
- 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.
9695

9796
#### Behavior
9897

@@ -101,6 +100,7 @@ The method SHOULD accept a dictionary/map/object where:
101100
- Attributes set on the current scope MUST be applied only to the current log and current metric
102101
- When the same attribute key exists in multiple scopes, the more specific scope's value takes precedence (current > isolation > global)
103102
- 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.
104104

105105
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.
106106

0 commit comments

Comments
 (0)