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.
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.
I think it is better to leave as int64, following specs. But open for discussion!
There was a problem hiding this comment.
According to the spec,
status_codeis 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.
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.
My understanding is that we'll still get the right
status_code, but thesuccessflag 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.
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.
I will open a new PR to fix this into Flask, Django and Pyramid integrations.
reyang
left a comment
There was a problem hiding this comment.
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.
reyang
left a comment
There was a problem hiding this comment.
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.
@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.
c24t
left a comment
There was a problem hiding this comment.
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.
@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.
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.
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 PRThere was a problem hiding this comment.
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.
This should be fixed by adding a raise statement in every except block.
There was a problem hiding this comment.
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.
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.
@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.
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
requestsintegration for better fidelity, adding attributes:Updated
span statuscreated byrequestsintegration.Updated
span nameto follow specs.Added
http status codetogrpc status codemapping as an utility.