-
Notifications
You must be signed in to change notification settings - Fork 548
fix(grpc): Fix AttributeError when instrumenting with OTel #4405
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9868322
fix(grpc): Fix AttributeError when instrumenting with OTel
sentrivana b4e8599
add compat
sentrivana e83ab8c
.
sentrivana 8273ffd
Merge branch 'master' into ivana/fix-grpc
sentrivana 0f6585a
mypy
sentrivana 08385e2
Merge branch 'master' into ivana/fix-grpc
sentrivana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Going with a list instead of the
tuple
we have been using successfully so far seems like a potentially risky change to me. We could see unexpected consequences, especially if something other than our SDK and OTel, which expects a tuple, is patching gRPC as well.Other potential solution
I'd prefer instead that we keep the existing behavior by default. We could then wrap the call to the original function in a
try
/except
, calling it again with a list if there is anAttributeError
.There's a strong argument that we should not change anything in the SDK
There is a strong argument that we should not attempt to fix this bug in our SDK, as this problem seems to arise due to a bug in the OpenTelemetry instrumentation.
The reason I say this is that the
grpcio
library types theinterceptors
parameter asOptional[Sequence[Any]]
, andSequence
is the abstract base class for immutable sequences. The OpenTelemetry instrumentation, however, makes the mistake of assuming that theinterceptors
array is mutable.My conclusion
So, perhaps, we should keep our SDK as is. Tuples are instances of
collections.abc.Sequence
, so we are respecting gRPC's API; if something else is patching gRPC in a way that does not expect its API, then that other thing should get fixed. It should be an easy fix in Otel, perhaps we can just close this PR and contribute a fix over there?Although I guess we can also make a fix in our SDK – I'd just recommend we try a lower-risk way of fixing the problem then universally switching over to using an array.
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.
We're already using an array in the wrapper for the sync server which does essentially the same thing (compare the two). Yes, this is technically on OTel, but if we make folks' lives better with a small fix (and there's even precedent for it), why not do it.
I don't understand the typing argument -- a
list
is also aSequence
.Re: trying to call the original function and calling it again if there's an
AttributeError
: we'd be changing the behavior of the original program with that. Imagine if the original function changes the state of something at the beginning, and only runs into theAttributeError
at the end. We'd be re-executing everything before theAttributeError
with the second call.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.
Yes, a
list
is also aSequence
, so it is valid to pass alist
to a function which expects aSequence
. However, it is also valid to pass any other type ofSequence
to that function, including, for example, atuple
. So, the code in the function must restrict itself to APIs available onSequence
; it cannot assume that it is receiving alist
and call methods available onlist
and not onSequence
. This is why this is an Otel bug: Otel is making the assumption that it is receiving alist
, when the API has only guaranteed aSequence
(which can belist
objects, but can also be atuple
).Regarding this point:
I'd dispute the idea of precedent; the sync code path is a completely separate code path; we don't know whether some other library patches the async version in a way that would break with the changes here.
More fundamentally, my issue is that the Sentry SDK should not be in the business of maintaining compatibility with every different possible way a library can be patched. This would be impossible, since Python allows patching anything arbitrarily. Yes, it is our responsibility to ensure the SDK does not break a users app. But in this case, Otel has improperly patched something and therefore it is Otel which has broken the app.
It should be a very simple fix in Otel's side, I think we should just contribute there (regardless of whether we fix in the Sentry SDK), since we anyways want to be more involved in the Otel community.
Uh oh!
There was an error while loading. Please reload this page.
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'm aware that this is an OTel bug. :) And I'll also submit a PR there. That's not mutually exclusive to also making this change here.
If this was a huge diff, I'd be on board with you with fixing this in OTel only. But it's not, and the time we're spending discussing this is honestly already disproportionate to the size and scope of the change.
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.
@szokeasaurusrex please have a look at our SDK principles, especially this one https://develop.sentry.dev/sdk/philosophy/#prioritize-customer-convenience-over-correctness
While it's worth pointing out that this can and should (also) be fixed upstream, we need to make sure to unblock our users first and foremost. Same is true for unblocking other maintainers, by helping them with a review that focusses on what matters most.
Also, remember https://google.github.io/eng-practices/review/reviewer/standard.html
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.
Fair point, thanks @stephanie-anderson!