-
Notifications
You must be signed in to change notification settings - Fork 250
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
Requests library spec fidelity #746
Requests library spec fidelity #746
Conversation
contrib/opencensus-ext-requests/opencensus/ext/requests/trace.py
Outdated
Show resolved
Hide resolved
else: | ||
# Add the status code to attributes | ||
_tracer.add_attribute_to_current_span( | ||
HTTP_STATUS_CODE, str(result.status_code) |
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.
According to the spec, status_code
is an int64. https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/HTTP.md#mapping-from-http-status-codes-to-trace-status-codes
This again seems to be a spec bug in the test-cases section, where status_code
is put as a string.
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 it is better to leave as int64, following specs. But open for discussion!
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.
According to the spec,
status_code
is an int64. https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/HTTP.md#mapping-from-http-status-codes-to-trace-status-codes
Right now AzureExporter
for tracer is broken because Flask
, Django
and Pyramid
integrations set status_code
as string, and azures expect int, we can typecast on azure or change the other integrations, which way is preferred?
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.
My understanding is that we'll still get the right status_code
, but the success
flag will be wrong.
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.
My understanding is that we'll still get the right
status_code
, but thesuccess
flag will be wrong.
Yes, and with this we have both options described above. I can take any of them, I prefer to put the status_code
as int, it makes more sense to me.
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 agree with you that we should use int. Converting int to string and then parse it to int sounds like crazy :)
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 will open a new PR to fix this into Flask
, Django
and Pyramid
integrations.
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.
Did it here.
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.
Looks good in general. I've left a few comments.
I'm a bit surprised to see the bugs in specs. Wish we will do a better job in OpenTelemetry.
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.
LGTM.
Thanks @victoraugustolls! Let's wait for one day before merge, see if @c24t has comments.
|
||
CANCELLED = Status(code_pb2.CANCELLED) | ||
INVALID_URL = Status(code_pb2.INVALID_ARGUMENT, message='invalid URL') | ||
TIMEOUT = Status(code_pb2.DEADLINE_EXCEEDED, message='request timed out') |
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.
@victoraugustolls there's an ongoing discussion about using grpc error codes in OpenTelemetry, if you've got an opinion here you may want to tune into the SIG meeting or follow the OT specs repo.
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.
Code and tests look excellent, and this is a clear improvement.
try: | ||
result = wrapped(*args, **kwargs) | ||
except requests.Timeout: | ||
_span.set_status(exceptions_status.TIMEOUT) |
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.
@reyang Isn't this except
clause and the ones following going to eat the raised exception and returns None
in case of any requests
error? Unless I'm missing something this change is going to break many things.
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, but wont requests
return None
in case it raises an Exception
? If so, the returned value is the same
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.
Raising an exception should not "return" at all.
try:
requests.get("http://not-a-host")
unreacheable() #actually reached with this PR
except Exception:
reached() # actually unreachable with this PR
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.
What can be changed, and is a good idea actually, is to threat the Exception
and raise it again, and let the user do whatever it wants. That's what you meant?
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 should be fixed by adding a raise
statement in every except
block.
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.
The main goal here is to keep this hook transparent and keep 1:1 interface as requests
(Exceptions are part of that interface).
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.
What can be changed, and is a good idea actually, is to threat the Exception and raise it again, and let the user do whatever it wants. That's what you meant?
So you agreed with this, right? Just to be clear. If so, I do agree with you and I will open a PR to change this.
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 👍 !
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.
@isra17 You're right, we've missed this. It is a bug.
url = 'http://localhost:8080/test' | ||
|
||
with patch, patch_thread: | ||
wrapped(url) |
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.
To be clearer, given mock_func
raise an exception, this test case should fail gith here and never go further. The test should actually assert the requests.TooManyRedirects
exception is raised from wrapped(url)
.
Updated
requests
integration for better fidelity, adding attributes:Updated
span status
created byrequests
integration.Updated
span name
to follow specs.Added
http status code
togrpc status code
mapping as an utility.