Skip to content

Commit 554e6cf

Browse files
committed
feat: Add set_attribute, remove_attribute to global API
1 parent a4e4c57 commit 554e6cf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

sentry_sdk/api.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def overload(x: "T") -> "T":
7070
"last_event_id",
7171
"new_scope",
7272
"push_scope",
73+
"remove_attribute",
74+
"set_attribute",
7375
"set_context",
7476
"set_extra",
7577
"set_level",
@@ -287,6 +289,28 @@ def push_scope( # noqa: F811
287289
return _ScopeManager()
288290

289291

292+
@scopemethod
293+
def set_attribute(key: str, value: "Any") -> None:
294+
"""
295+
Set an attribute.
296+
297+
Any attributes-based telemetry (logs, metrics) captured in this scope will
298+
include this attribute.
299+
"""
300+
return get_isolation_scope().set_attribute(key, value)
301+
302+
303+
@scopemethod
304+
def remove_attribute(key: str) -> None:
305+
"""
306+
Remove an attribute.
307+
308+
If the attribute doesn't exist, this function will not have any effect and
309+
it will also not raise an exception.
310+
"""
311+
return get_isolation_scope().remove_attribute(key)
312+
313+
290314
@scopemethod
291315
def set_tag(key: str, value: "Any") -> None:
292316
return get_isolation_scope().set_tag(key, value)

0 commit comments

Comments
 (0)