census-instrumentation / opencensus-python

A stats collection and distributed tracing framework
Apache License 2.0
669 stars 250 forks source link

confusing error with integrations: `requests` integration errors out but claims it supports `requests` #142

Closed odeke-em closed 6 years ago

odeke-em commented 6 years ago

I was just finishing connecting a polyglot API over HTTP and tried to write a Python sample but on the first run it gives me a weird error that doesn't make sense because am trying to get the requests package traced, but the error interestingly is

Failed to integrate module: requests, supported integrations are httplib, mysql, postgresql, pymysql, requests, sqlalchemy, google_cloud_clientlibs

where the incomplete code is

#!/usr/bin/env python

import requests
from opencensus.trace import tracer as tracer_module
from opencensus.trace import config_integration

# Trace our HTTP requests module
integration = ['requests']
config_integration.trace_integrations(integration)

def main():
  while True:
    query = input('Content to search$ ')
    doSearch(query)

def doSearch(query):
  with tracer.span(name='py-search') as span:
    res = requests.post('http://localhost:9778/search', json={'keywords': query})

if __name__ == '__main__':
  main()
screen shot 2018-03-20 at 12 15 49 am

Thank you!

liyanhui1228 commented 6 years ago

Hi @odeke-em, please check whether you have installed the wrapt package with pip freeze, this is a known issue and I'll do a new release to add the wrapt package to the setup.py file.

odeke-em commented 6 years ago

Hello @liyanhui1228, thank you for that update. I'll make that update after work and see how it goes. Otherwise I implemented a polyglot demo at https://github.com/orijtech/opencensus-demos/tree/master/media-search whose purpose is to trace HTTP requests from various clients and export them to various backends such as Stackdriver, AWS X-Ray and so far it works. However, it is my side project in the evenings after work :)

odeke-em commented 6 years ago

Using wrapt worked, thank you @liyanhui1228! No more warnings :)

liyanhui1228 commented 6 years ago

@odeke-em The demo looks cool! I'm going to close this issue, feel free to reach out if you have any question.