Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ strict_optional = true
warn_redundant_casts = true
warn_unused_configs = true
warn_unused_ignores = true
exclude = ["tests/"]

# Relaxations for code written before mypy was introduced
# Do not use wildcards in module paths, otherwise added modules will
Expand Down
4 changes: 4 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
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(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,
}