DataDog / dd-trace-py

Datadog Python APM Client
https://ddtrace.readthedocs.io/
Other
553 stars 415 forks source link

Unable to export events due to invalid path value from events. #9717

Open MukulSoul opened 4 months ago

MukulSoul commented 4 months ago

Summary of problem

While integrating DataDog library in FastAPI Application, the events are not exported to the dd-agent. The exception occurs for different values of module path, where the value is not a valid path rather string representation of type/object. The exception is as:

Unexpected error while exporting events. Please report this bug to https://github.com/DataDog/dd-trace-py/issues
Traceback (most recent call last):
  File "xxxxxxxxxxxxxxx\AppData\Local\pypoetry\Cache\virtualenvs\fast-app-5lyE2VXk-py3.9\lib\site-packages\ddtrace\profiling\scheduler.py", line 63, in flush
    exp.export(events, start, self._last_export)
  File "xxxxxxxxxxxxxxx\AppData\Local\pypoetry\Cache\virtualenvs\fast-app-5lyE2VXk-py3.9\lib\site-packages\ddtrace\profiling\exporter\http.py", line 179, in export
    profile, libs = super(PprofHTTPExporter, self).export(events, start_time_ns, end_time_ns)
  File "ddtrace\\profiling\\exporter\\pprof.pyx", line 840, in ddtrace.profiling.exporter.pprof.PprofExporter.export
  File "ddtrace\\profiling\\exporter\\pprof.pyx", line 462, in ddtrace.profiling.exporter.pprof._PprofConverter._build_libraries
  File "ddtrace\\profiling\\exporter\\pprof.pyx", line 463, in genexpr
  File "xxxxxxxxxxxxxxx\AppData\Local\pypoetry\Cache\virtualenvs\fast-app-5lyE2VXk-py3.9\lib\site-packages\ddtrace\internal\utils\cache.py", line 81, in cached_f
    return cache.get(key, f)
  File "xxxxxxxxxxxxxxx\AppData\Local\pypoetry\Cache\virtualenvs\fast-app-5lyE2VXk-py3.9\lib\site-packages\ddtrace\internal\utils\cache.py", line 64, in get
    value = f(key)
  File "xxxxxxxxxxxxxxx\AppData\Local\pypoetry\Cache\virtualenvs\fast-app-5lyE2VXk-py3.9\lib\site-packages\ddtrace\internal\packages.py", line 205, in filename_to_package
    return mapping.get(_root_module(path.resolve()))
  File "C:\Python39\lib\pathlib.py", line 1215, in resolve
    s = self._flavour.resolve(self, strict=strict)
  File "C:\Python39\lib\pathlib.py", line 215, in resolve
    s = self._ext_to_normal(_getfinalpathname(s))
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '<frozen importlib._bootstrap_external>'
ERROR:    2024-07-04 21:48:29,860 ddtrace.profiling.scheduler:67 request_id=None Unexpected error while exporting events. Please report this bug to https://github.com/DataDog/dd-trace-py/issues
Traceback (most recent call last):
  File "xxxxxxxxxxxxxxx\AppData\Local\pypoetry\Cache\virtualenvs\fast-app-5lyE2VXk-py3.9\lib\site-packages\ddtrace\profiling\scheduler.py", line 63, in flush
    exp.export(events, start, self._last_export)
  File "xxxxxxxxxxxxxxx\AppData\Local\pypoetry\Cache\virtualenvs\fast-app-5lyE2VXk-py3.9\lib\site-packages\ddtrace\profiling\exporter\http.py", line 179, in export
    profile, libs = super(PprofHTTPExporter, self).export(events, start_time_ns, end_time_ns)
  File "ddtrace\\profiling\\exporter\\pprof.pyx", line 840, in ddtrace.profiling.exporter.pprof.PprofExporter.export
  File "ddtrace\\profiling\\exporter\\pprof.pyx", line 462, in ddtrace.profiling.exporter.pprof._PprofConverter._build_libraries
  File "ddtrace\\profiling\\exporter\\pprof.pyx", line 463, in genexpr
  File "xxxxxxxxxxxxxxx\AppData\Local\pypoetry\Cache\virtualenvs\fast-app-5lyE2VXk-py3.9\lib\site-packages\ddtrace\internal\utils\cache.py", line 81, in cached_f
    return cache.get(key, f)
  File "xxxxxxxxxxxxxxx\AppData\Local\pypoetry\Cache\virtualenvs\fast-app-5lyE2VXk-py3.9\lib\site-packages\ddtrace\internal\utils\cache.py", line 64, in get
    value = f(key)
  File "xxxxxxxxxxxxxxx\AppData\Local\pypoetry\Cache\virtualenvs\fast-app-5lyE2VXk-py3.9\lib\site-packages\ddtrace\internal\packages.py", line 205, in filename_to_package
    return mapping.get(_root_module(path.resolve()))
  File "C:\Python39\lib\pathlib.py", line 1215, in resolve
    s = self._flavour.resolve(self, strict=strict)
  File "C:\Python39\lib\pathlib.py", line 215, in resolve
    s = self._ext_to_normal(_getfinalpathname(s))
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '<frozen importlib._bootstrap_external>'

Which version of dd-trace-py are you using?

Python - 3.9 ddtrace - 2.9.2 poetry - 3.9.13

Which libraries and their versions are you using?

`pip freeze`
build==1.2.1
CacheControl==0.14.0
certifi==2024.6.2
charset-normalizer==3.3.2
cleo==2.1.0
colorama==0.4.6
crashtest==0.4.1
distlib==0.3.8
dulwich==0.21.7
fastjsonschema==2.20.0
filelock==3.15.3
idna==3.7
importlib_metadata==7.2.0
installer==0.7.0
jaraco.classes==3.4.0
keyring==24.3.1
more-itertools==10.3.0
msgpack==1.0.8
packaging==24.1
pexpect==4.9.0
pkginfo==1.11.1
platformdirs==4.2.2
poetry==1.8.3
poetry-core==1.9.0
poetry-plugin-export==1.8.0
ptyprocess==0.7.0
pyproject_hooks==1.1.0
pywin32-ctypes==0.2.2
rapidfuzz==3.9.3
requests==2.32.3
requests-toolbelt==1.0.0
shellingham==1.5.4
tomli==2.0.1
tomlkit==0.12.5
trove-classifiers==2024.5.22
urllib3==2.2.2
virtualenv==20.26.2
zipp==3.19.2
sanchda commented 4 months ago

Thanks for the report. Looks like there are some differences in the Windows implementation of Pathlib we didn't account for. Will report back when we have a fixup PR.

In the meantime, you should be able to avoid these errors by setting the DD_PROFILING_ENABLE_CODE_PROVENANCE environment variable to "false". This feature is used to implement "My code" in the Profiling UX, which allows users to filter out stuff like framework and library code in order to better focus on the parts of the system that they control.

sanchda commented 4 months ago

OK, I think this will be fixed by #9720.