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
Copy file name to clipboardExpand all lines: develop-docs/sdk/telemetry/scopes.mdx
+57Lines changed: 57 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,6 +51,63 @@ Data from all three scope types MUST be merged in a specific order before being
51
51
52
52

53
53
54
+
## Scope Methods
55
+
56
+
### Setting Attributes
57
+
58
+
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).
59
+
60
+
Attributes are key-value pairs where each value is an object containing:
61
+
62
+
-`type`: The data type (`"string"`, `"integer"`, `"double"`, or `"boolean"`)
63
+
-`value`: The actual attribute value, which MUST match the specified type
64
+
-`unit` (optional): The unit of measurement (e.g., `"ms"`, `"s"`, `"bytes"`, `"count"`, `"percent"`)
65
+
66
+
#### Example Usage
67
+
68
+
```javascript
69
+
Sentry.getGlobalScope().setAttributes({
70
+
"app.feature_flag.enabled": {
71
+
type:"boolean",
72
+
value:true
73
+
},
74
+
"app.session_duration": {
75
+
type:"integer",
76
+
value:3600,
77
+
unit:"s"
78
+
}
79
+
});
80
+
```
81
+
82
+
```python
83
+
sentry_sdk.get_global_scope().set_attributes({
84
+
"app.feature_flag.enabled": {
85
+
"type": "boolean",
86
+
"value": True
87
+
},
88
+
"app.session_duration": {
89
+
"type": "integer",
90
+
"value": 3600,
91
+
"unit": "s"
92
+
}
93
+
})
94
+
```
95
+
96
+
#### Method Signature
97
+
98
+
The method SHOULD accept a dictionary/map/object where:
99
+
- Keys are attribute names (strings)
100
+
- Values are attribute objects with `type`, `value`, and optionally `unit` properties
101
+
102
+
#### Behavior
103
+
104
+
- Attributes set on the global scope MUST be applied to all logs
105
+
- Attributes set on the isolation scope MUST be applied to all logs in that execution context
106
+
- Attributes set on the current scope MUST be applied only to the current log
107
+
- When the same attribute key exists in multiple scopes, the more specific scope's value takes precedence (current > isolation > global)
108
+
109
+
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.
110
+
54
111
## Related Documents
55
112
56
113
This document provides a concise summary of the [Hub & Scope Refactoring](/sdk/miscellaneous/hub_and_scope_refactoring/), focusing on implementation details and expected features. The original document remains unchanged, offering additional historical context and migration strategies.
0 commit comments