question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

issue in httplib and requests

See original GitHub issue

The following code would generate 5 spans, which seems to be confusing:

import requests
from opencensus.trace import config_integration
from opencensus.trace.tracer import Tracer
config_integration.trace_integrations(['httplib', 'requests'])
tracer = Tracer()
with tracer.span(name='parent'):
    response = requests.get('https://www.wikipedia.org/wiki/Rabbit')

Expected:

  1. Probably we only want 4 spans, need to dig out more:
parent span
    requests span
        httplib span, which returned HTTP 301 (redirection)
        httplib span, which returned HTTP 200
  1. The httplib span attribute http.url should be full URL, current it is /wiki/Rabbit.
[SpanData(name='[httplib]request', context=SpanContext(trace_id=56b691b1c448a80bfd21455d1e3916ac, span_id=21a6c4871e00d227, trace_options=TraceOptions(enabled=True), tracestate=None), span_id='b0cd26aa762e72c5', parent_span_id='21a6c4871e00d227', attributes={'http.url': '/wiki/Rabbit', 'http.method': 'GET', 'http.status_code': '301'}, start_time='2019-04-23T00:46:40.566298Z', end_time='2019-04-23T00:46:40.587506Z', child_span_count=0, stack_trace=None, time_events=[], links=[], status=None, same_process_as_parent_span=None, span_kind=2)]
[SpanData(name='[httplib]request', context=SpanContext(trace_id=56b691b1c448a80bfd21455d1e3916ac, span_id=21a6c4871e00d227, trace_options=TraceOptions(enabled=True), tracestate=None), span_id='9099cb62a56c5910', parent_span_id='21a6c4871e00d227', attributes={'http.url': '/wiki/Rabbit', 'http.method': 'GET', 'http.status_code': '200'}, start_time='2019-04-23T00:46:40.703073Z', end_time='2019-04-23T00:46:40.718689Z', child_span_count=0, stack_trace=None, time_events=[], links=[], status=None, same_process_as_parent_span=None, span_kind=2)]
[SpanData(name='[requests]get', context=SpanContext(trace_id=56b691b1c448a80bfd21455d1e3916ac, span_id=f240885e8fcd8866, trace_options=TraceOptions(enabled=True), tracestate=None), span_id='21a6c4871e00d227', parent_span_id='f240885e8fcd8866', attributes={'http.url': 'https://www.wikipedia.org/wiki/Rabbit', 'http.status_code': '200'}, start_time='2019-04-23T00:46:40.433738Z', end_time='2019-04-23T00:46:40.770006Z', child_span_count=0, stack_trace=None, time_events=[], links=[], status=None, same_process_as_parent_span=None, span_kind=2)]
[SpanData(name='[requests]get', context=SpanContext(trace_id=56b691b1c448a80bfd21455d1e3916ac, span_id=f9b3b7a04c993de9, trace_options=TraceOptions(enabled=True), tracestate=None), span_id='f240885e8fcd8866', parent_span_id='f9b3b7a04c993de9', attributes={'http.url': 'https://www.wikipedia.org/wiki/Rabbit', 'http.status_code': '200'}, start_time='2019-04-23T00:46:40.433738Z', end_time='2019-04-23T00:46:40.776972Z', child_span_count=0, stack_trace=None, time_events=[], links=[], status=None, same_process_as_parent_span=None, span_kind=2)]
[SpanData(name='parent', context=SpanContext(trace_id=56b691b1c448a80bfd21455d1e3916ac, span_id=None, trace_options=TraceOptions(enabled=True), tracestate=None), span_id='f9b3b7a04c993de9', parent_span_id=None, attributes={}, start_time='2019-04-23T00:46:40.433738Z', end_time='2019-04-23T00:46:40.778972Z', child_span_count=0, stack_trace=None, time_events=[], links=[], status=None, same_process_as_parent_span=None, span_kind=0)]

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
reyangcommented, Jul 31, 2019

@lzchen FYI.

@victoraugustolls Thanks for bringing it up. We haven’t worked on this issue.

Here goes my current thinking:

  1. We need to track the actual underlying HTTP operation (which has a strict 1:1 mapping for the actual HTTP outbound request).
  2. It would be helpful to track the high level HTTP operation, which is the logical layer thing. For example, if someone is trying to HTTP GET http://non.existing.domain/, we expect the logical operation to fail, with no actual physical HTTP call (since DNS resolution failure will trigger exception on the HTTP client).
  3. For metrics, we want to use 1) for the actual HTTP requests/second and latency (as counting invalid DNS or URL for average latency does not make sense). We can use 2) for logical operations, similar like how people would use metrics for local spans.

We can discuss more at https://github.com/open-telemetry/opentelemetry-specification/issues/110.

With this, I would expect the result to be:

parent span
    requests span
        httplib span, which returned HTTP 301 (redirection)
        httplib span, which returned HTTP 200

metrics:
    number of HTTP request: 2
    number of spans from requests library: 1
0reactions
lzchencommented, Jun 23, 2020

@NoutieH If you would like to contribute this part, go for it! I can assign the task to you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python: Issues with httplib & requests; https seems to cause a ...
I'm currently trying to use BeautifulSoup to scrape some information from the discogs website which isn't available through their API.
Read more >
Python Module Httplib GET request issue - Orion SDK
In a nutshell, I'm attempting to query my organizations SolarWinds DB using this library but I'm running into some issues with my GET...
Read more >
http.client — HTTP protocol client — Python 3.11.1 ...
This module defines classes that implement the client side of the HTTP and HTTPS protocols. It is normally not used directly — the...
Read more >
Get & Post HTTP & JSON Requests - Learn Python - DataCamp
There are many libraries to make an HTTP request in Python, which are httplib, urllib, httplib2 , treq, etc., but requests are the...
Read more >
Python's urllib.request for HTTP Requests - Real Python
To understand some of the issues that you may encounter when using urllib.request , you'll need to examine how a response is represented...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found