Skip to content

Add update_data to Span. #4666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 5, 2025
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,10 @@ def set_data(self, key, value):
# type: (str, Any) -> None
self._data[key] = value

def update_data(self, data):
# type: (Dict[str, Any]) -> None
self._data.update(data)

def set_flag(self, flag, result):
# type: (str, bool) -> None
if len(self._flags) < self._flags_capacity:
Expand Down Expand Up @@ -1275,6 +1279,10 @@ def set_data(self, key, value):
# type: (str, Any) -> None
pass

def update_data(self, data):
# type: (Dict[str, Any]) -> None
pass

def set_status(self, value):
# type: (str) -> None
pass
Expand Down
31 changes: 31 additions & 0 deletions tests/tracing/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,3 +509,34 @@ def test_transaction_not_started_warning(sentry_init):
"The transaction will not be sent to Sentry. To fix, start the transaction by"
"passing it to sentry_sdk.start_transaction."
)


def test_span_set_data_update_data(sentry_init, capture_events):
sentry_init(traces_sample_rate=1.0)

events = capture_events()

with sentry_sdk.start_transaction(name="test-transaction"):
with start_span(op="test-span") as span:
span.set_data("key0", "value0")
span.set_data("key1", "value1")

span.update_data(
{
"key1": "updated-value1",
"key2": "value2",
"key3": "value3",
}
)

(event,) = events
span = event["spans"][0]

assert span["data"] == {
"key0": "value0",
"key1": "updated-value1",
"key2": "value2",
"key3": "value3",
"thread.id": mock.ANY,
"thread.name": mock.ANY,
}