dynatrace-oss / OneAgent-SDK-Python-AutoInstrumentation

autodynatrace, a python library that implements automatic instrumentation using the OneAgent SDK for Python
Other
62 stars 28 forks source link

ensure string url is used for dynatrace sdk trace #93

Closed poojanp00 closed 11 months ago

poojanp00 commented 11 months ago

Describe the bug AIOHTTP can make a client session request with a str or class:yarl.URL instance.

The dynatrace sdk.trace_outgoing_web_request is expecting a string.

This fix just ensure that any class:yarl.URL objects are cast to a string before passing to the dynatrace sdk.

We've applied this fix to a service that was hitting this error condition and validated that it's working for us.

Original error stack trace: AIOHTTP can make a client session request with a str or class:yarl.URL instance.

The dynatrace sdk.trace_outgoing_web_request is expecting a string.

This fix just ensure that any class:yarl.URL objects are cast to a string before passing to the dynatrace sdk.

We've applied this fix to a service that was hitting this error condition and validated that it's working for us.

Original error stack trace:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiobotocore/httpsession.py", line 208, in send
   response = await self._session.request(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/autodynatrace/wrappers/aiohttp/wrapper.py", line 17, in dynatrace_request
   with sdk.trace_outgoing_web_request(url, method, headers) as tracer:
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/oneagent/sdk/__init__.py", line 260, in trace_outgoing_web_request

   self._nsdk, self._nsdk.outgoingwebrequesttracer_create(url, method))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ctypes.ArgumentError: argument 1: ValueError: Attempt to pass non-string type to SDK function expecting a string. Actual type: <class 'yarl.URL'>

To Reproduce Steps to reproduce the behavior:

  1. Go to (https://docs.aiohttp.org/en/stable/client_quickstart.html#make-a-request), which shows that a yarl.url is a valid type
  2. Go to (https://github.com/dynatrace-oss/OneAgent-SDK-Python-AutoInstrumentation/blob/master/autodynatrace/wrappers/aiohttp/wrapper.py), which shows the wrapper that is throwing the error shown above.

Additional context We have fixed this error by updating the wrapper to convert the yarl.url into a string before sending it along that way this error does not occur again. The link to the PR is: https://github.com/dynatrace-oss/OneAgent-SDK-Python-AutoInstrumentation/pull/92

please let us know if there is any other info we can provide

poojanp00 commented 11 months ago

The Pr has been merged