Skip to content

feat: Add set_attribute, remove_attribute to global API #16332

feat: Add set_attribute, remove_attribute to global API

feat: Add set_attribute, remove_attribute to global API #16332

Triggered via pull request February 27, 2026 08:58
Status Success
Total duration 1m 33s
Artifacts

codeql-analysis.yml

on: pull_request
Matrix: Analyze
Fit to window
Zoom out
Zoom in

Annotations

1 error and 4 warnings
Test assertion will fail due to key mismatch between set and remove operations: tests/test_attributes.py#L13
The test sets an attribute with key `"remove"` on line 12, then calls `remove_attribute("removed")` on line 13 (note the different key). The assertion on line 24 expects `"remove" not in metric["attributes"]`, but since `"remove"` was set and never removed (only `"removed"` was removed), this assertion will fail. The test likely intended to remove the same key that was set.
__init__.py __all__ list not updated despite explicit comment requirement: sentry_sdk/api.py#L73
The comment on line 50 of api.py explicitly states 'When changing this, update __all__ in __init__.py too'. The PR adds `set_attribute` and `remove_attribute` to api.py's __all__ (lines 73-74) but does not update __init__.py's __all__ list. While the functions are technically accessible via `sentry_sdk.set_attribute()` due to the `from sentry_sdk.api import *` statement, they won't be included when users do `from sentry_sdk import *` because __init__.py's explicit __all__ takes precedence. This creates inconsistent API surface and violates the project's own documented convention.
Test removes wrong attribute key - 'removed' instead of 'remove': tests/test_attributes.py#L13
The test sets an attribute named 'remove' (line 12) but then attempts to remove an attribute named 'removed' (line 13). This typo means the test doesn't actually validate that `remove_attribute` works correctly. The assertion at line 24 expects 'remove' is not in attributes, but since 'remove' was never removed (only the non-existent 'removed' was), this test will fail.
Missing __init__.py export for set_attribute and remove_attribute: sentry_sdk/api.py#L73
The code adds `set_attribute` and `remove_attribute` to `api.py`'s `__all__` list, but the comment at line 50 explicitly states 'When changing this, update __all__ in __init__.py too'. Looking at `sentry_sdk/__init__.py`, neither function is added to its `__all__` list. While the functions will still be importable (via `from sentry_sdk.api import *`), this violates the project's documented convention and may cause inconsistency in IDE autocompletion and documentation generation.
[476-ZY2] Missing __init__.py export for set_attribute and remove_attribute (additional location): sentry_sdk/api.py#L292
The code adds `set_attribute` and `remove_attribute` to `api.py`'s `__all__` list, but the comment at line 50 explicitly states 'When changing this, update __all__ in __init__.py too'. Looking at `sentry_sdk/__init__.py`, neither function is added to its `__all__` list. While the functions will still be importable (via `from sentry_sdk.api import *`), this violates the project's documented convention and may cause inconsistency in IDE autocompletion and documentation generation.