-
Notifications
You must be signed in to change notification settings - Fork 555
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
base: master
Are you sure you want to change the base?
Add update_data
to Span
.
#4666
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API is a bit confusing, imo, as it is unclear what should happen if a user calls set_data
with a dict as the first parameter, and something else as the second parameter.
I would prefer we instead introduce a separate function to enable setting data as a dict
, rather than supporting two distinct signatures for set_data
.
Although if others are okay with having set_data
support both ways, we can go with it – just sharing my two cents here. In that case, though, I would define both APIs with @overload
.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4666 +/- ##
==========================================
- Coverage 85.09% 85.05% -0.04%
==========================================
Files 156 156
Lines 15797 15799 +2
Branches 2671 2671
==========================================
- Hits 13442 13438 -4
- Misses 1578 1585 +7
+ Partials 777 776 -1
|
True @szokeasaurusrex i have now changed it to have a |
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: NoOpSpan Method Inheritance Issue
The update_data
method, newly added to the Span
class, is not overridden in NoOpSpan
. This allows NoOpSpan.update_data()
to inherit the real implementation and modify internal data, breaking its no-operation contract. This is inconsistent with NoOpSpan.set_data()
and similar methods, which are correctly overridden as no-ops.
@@ -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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also add update_data
to the name of the test. And, perhaps add a test which only checks update_data
in isolation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the Cursor bug bot might have found something. Besides that, looks good
This allows users to set multiple
span.data
attributes at once.In 3.x this then will become
set_attributes
(plural).