Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions develop-docs/sdk/telemetry/scopes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,18 @@ Data from all three scope types MUST be merged in a specific order before being

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

Attributes are key-value pairs where each value is an object containing:
Attributes are key-value pairs where each value is either a an attribute value or an object containing:

- `type`: The data type (`"string"`, `"integer"`, `"double"`, `"boolean"`, `"string[]"`, `"integer[]"` and `"double[]"`)
- `value`: The actual attribute value, which MUST match the specified type
- `unit` (optional): The unit of measurement (e.g., `"ms"`, `"s"`, `"bytes"`, `"count"`, `"percent"`)
- `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.
- `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.

#### Example Usage

```javascript
Sentry.getGlobalScope().setAttributes({
"app.feature_flag.enabled": true,
"app.session_duration": {
type: "integer",
value: 3600,
unit: "s"
}
Expand All @@ -81,7 +80,6 @@ Sentry.getGlobalScope().setAttributes({
sentry_sdk.get_global_scope().set_attributes({
"app.feature_flag.enabled": True,
"app.session_duration": {
"type": "integer",
"value": 3600,
"unit": "s"
}
Expand All @@ -92,7 +90,8 @@ sentry_sdk.get_global_scope().set_attributes({

The method SHOULD accept a dictionary/map/object where:
- Keys are attribute names (strings)
- Values are attribute objects with `type`, `value`, and optionally `unit` properties
- Values are either directly values or attribute objects/dictionaries with `value`, and optionally `unit` properties (see [example](#example-usage)).
- 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.

#### Behavior

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

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.

Comment on lines +103 to 106
Copy link

Choose a reason for hiding this comment

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

Bug: New requirement breaks existing before_send_log callbacks by changing expected attribute format, removing the type field.
Severity: CRITICAL | Confidence: 0.95

🔍 Detailed Analysis

The new requirement in scopes.mdx at line 103, stating that SDKs should maintain the user-set attribute format until before_send_log callbacks are called, introduces a breaking change. Existing user callbacks expect attributes to be in a typed object format, including a type field (e.g., { "attribute_name": { type: "string", value: "xyz" } }). However, the new requirement allows primitive values (e.g., { "attribute_name": true }) or typed objects without a type field (e.g., { "attribute_name": { value: 3600, unit: "s" } }) to be passed to these callbacks. This will cause existing callbacks to malfunction when attempting to access attribute.type or attribute.value, or when modifying attributes based on the previously expected structure.

💡 Suggested Fix

Revert the requirement at scopes.mdx:103 or clarify that SDKs must convert user-set attributes to the full typed object format (including type field) before passing them to before_send_log and similar callbacks to maintain compatibility.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: develop-docs/sdk/telemetry/scopes.mdx#L103-L106

Potential issue: The new requirement in `scopes.mdx` at line 103, stating that SDKs
should maintain the user-set attribute format until `before_send_log` callbacks are
called, introduces a breaking change. Existing user callbacks expect attributes to be in
a typed object format, including a `type` field (e.g., `{ "attribute_name": { type:
"string", value: "xyz" } }`). However, the new requirement allows primitive values
(e.g., `{ "attribute_name": true }`) or typed objects without a `type` field (e.g., `{
"attribute_name": { value: 3600, unit: "s" } }`) to be passed to these callbacks. This
will cause existing callbacks to malfunction when attempting to access `attribute.type`
or `attribute.value`, or when modifying attributes based on the previously expected
structure.

Did we get this right? 👍 / 👎 to inform future reviews.

Reference_id: 2689521

Copy link
Member Author

@Lms24 Lms24 Nov 14, 2025

Choose a reason for hiding this comment

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

that's exactly what I want to avoid :D Not sure how other languages built beforeSendLog. If JS is rather the exception than the norm here, that's fine. But we only serialize to the more complex, typed log object after beforeSendLog. So users generally expect to find the same key-value structure in beforeSendLong as the one they used to set attributes in the first place

Expand Down
Loading