Skip to content

Http metrics example file name "http.py" leads to error while importing requests library #1268#1269

Closed
pavankrish123 wants to merge 3 commits intoopen-telemetry:masterfrom
cisco:master
Closed

Http metrics example file name "http.py" leads to error while importing requests library #1268#1269
pavankrish123 wants to merge 3 commits intoopen-telemetry:masterfrom
cisco:master

Conversation

@pavankrish123
Copy link
Copy Markdown
Contributor

Description

This is a minor fix for a small issue from PR #1116. The example file for demonstrating http metrics is named as http.py. This leads to a shadow import with another file in requests causing the import scream.


(env) basic_meter $ python http.py 
Traceback (most recent call last):
  File "http.py", line 19, in <module>
    import requests
  File "/Users/pavankri/ot/opentelemetry-python/env/lib/python3.8/site-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/Users/pavankri/ot/opentelemetry-python/env/lib/python3.8/site-packages/urllib3/__init__.py", line 7, in <module>
    from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
  File "/Users/pavankri/ot/opentelemetry-python/env/lib/python3.8/site-packages/urllib3/connectionpool.py", line 11, in <module>
    from .exceptions import (
  File "/Users/pavankri/ot/opentelemetry-python/env/lib/python3.8/site-packages/urllib3/exceptions.py", line 2, in <module>
    from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
  File "/Users/pavankri/ot/opentelemetry-python/env/lib/python3.8/site-packages/urllib3/packages/six.py", line 199, in load_module
    mod = mod._resolve()
  File "/Users/pavankri/ot/opentelemetry-python/env/lib/python3.8/site-packages/urllib3/packages/six.py", line 113, in _resolve
    return _import_module(self.mod)
  File "/Users/pavankri/ot/opentelemetry-python/env/lib/python3.8/site-packages/urllib3/packages/six.py", line 82, in _import_module
    __import__(name)
  File "/Users/pavankri/ot/opentelemetry-python/docs/examples/basic_meter/http.py", line 22, in <module>
    from opentelemetry.instrumentation.requests import RequestsInstrumentor
  File "/Users/pavankri/ot/opentelemetry-python/env/lib/python3.8/site-packages/opentelemetry/instrumentation/requests/__init__.py", line 39, in <module>
    from requests import Timeout, URLRequired
ImportError: cannot import name 'Timeout' from partially initialized module 'requests' (most likely due to a circular import) (/Users/pavankri/ot/opentelemetry-python/env/lib/python3.8/site-packages/requests/__init__.py)

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Renamed the file to something appropriate http_metrics.py and that resolved the issue. Verified the example is working as expected

  • [ X] Test A

(env) basic_meter   $ mv http.py http_metrics.py
(env) basic_meter   $ python http_metrics.py 
...
ConsoleMetricsExporter(data="ValueRecorder(name="http.client.duration", description="measures the duration of the outbound HTTP request")", labels="(('http.flavor', '1.1'), ('http.method', 'GET'), ('http.status_code', '200'), ('http.url', 'http://example.com'))", value=minmaxsumcount(min=77.86989212036133, max=77.86989212036133, sum=77.86989212036133, count=1), resource={'telemetry.sdk.language': 'python', 'telemetry.sdk.name': 'opentelemetry', 'telemetry.sdk.version': '0.15.dev0'})

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated (N/A)
  • Unit tests have been added (N/A)
  • Documentation has been updated

Pavan Krishna and others added 2 commits October 21, 2020 12:29
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Oct 21, 2020

CLA Check

@pavankrish123
Copy link
Copy Markdown
Contributor Author

Signed the CLA's from Cisco

srikanthccv pushed a commit to srikanthccv/opentelemetry-python that referenced this pull request Nov 1, 2020
…telemetry#1269)

Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants