From 3ab574d3471b1f7f3789a69f3d69ed5bd5769bff Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Tue, 17 Nov 2026 11:28:37 +0100 Subject: [PATCH] fix: Align type hints of set_attribute(s) --- MIGRATION_GUIDE.md | 1 + sentry_sdk/api.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index 4530d0a396..98b5468dd7 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -18,6 +18,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh - The `@trace` decorator accepts three optional arguments: `name`, `attributes`, `active` (default: `True`). - `sentry_sdk.continue_trace` accepts a single dictionary with the incoming headers or environment data. It is no longer a context manager and it does not return a span/transaction anymore. A span needs to be started manually afterwards. - `sentry_sdk.new_trace` resets the trace. +- The type hints of `sentry_sdk.set_attribute` and `sentry_sdk.set_attributes` now only accept primitives and lists of primitives, matching `Scope.set_attribute` and `Scope.set_attributes`. Unexpected values are still passed through `repr()` at runtime. ### Integrations diff --git a/sentry_sdk/api.py b/sentry_sdk/api.py index 88dc414bd4..04658aa5ea 100644 --- a/sentry_sdk/api.py +++ b/sentry_sdk/api.py @@ -20,6 +20,7 @@ ) from sentry_sdk._types import ( + AttributeValue, Breadcrumb, BreadcrumbHint, Event, @@ -188,7 +189,7 @@ def add_breadcrumb( @scopemethod -def set_attribute(attribute: str, value: "Any") -> None: +def set_attribute(attribute: str, value: "AttributeValue") -> None: """ Set an attribute. @@ -199,7 +200,7 @@ def set_attribute(attribute: str, value: "Any") -> None: @scopemethod -def set_attributes(attributes: "dict[str, Any]") -> None: +def set_attributes(attributes: "dict[str, AttributeValue]") -> None: """ Set multiple attributes.