Closed denniszag closed 10 months ago
@denniszag thanks for reporting this. This exception should be handled so it is unlikely to cause harm to your application. To mitigate this you may set DD_PROFILING_ENABLE_CODE_PROVENANCE=0
in your environment.
May I get some more information about your setup, please? In particular we would be interested in
pip freeze
ddtrace-run
command being used?I see a mention to Profiler(...).start
and I was wondering why this method of starting the profiler is being used. Is there something forcing you to use this programmatic API over setting DD_PROFILING_ENABLED=1
with ddtrace-run
? Is Profiler(...).start
called as the very first thing during start up?
Hi @P403n1x87. I would be happy to provide you with the information you asked for.
The method used to start the application: is the ddtrace-run command being used? No. We start the profiler programatically.
The method used to start the profiler Snippet:
profiler = Profiler(env='service_version', service='service_name', version='service_version')
profiler.start()
We start the profiler programmatically because we have a flag in the configuration that allows us enabling/disabling the profiler easily (from remote environment). In addition we would like to omit changing the deployment method of the application, and avoid coupling with Datadog tracer at the Kubernetes/Docker level.
Let me know if you need any more details.
@denniszag thanks for the extra details. First of all, let me reiterate that the error you see should not be of concern. What it means is that the profiler is failing to build the mapping of sources to distributions, meaning that it won't be able to report code provenance information when that happens (on the UI level, this means that you won't be able to filter profiles for just your code, as opposed to stdlib/third-party code). Your application should not be impacted by this error. Code provenance is enabled by default on 1.14.0 but not on earlier versions. So one way to make this error disappear should be
import os
os.environ["DD_PROFILING_ENABLE_CODE_PROVENANCE"] = "false"
just before starting the profiler.
This said, I was not able to reproduce the issue so I would like to get some more details from you if that's ok. From your pip freeze I see gevent
and flask
. Am I right in thinking that we are talking about a Flask application running with gevent
workers? What command do you use to start the application. Is there any other interaction with the ddtrace
library, apart from programmatically starting the profiler? Our docs recommend importing ddtrace.auto
as early as possible, and before gevent
monkey-patching to ensure that the library works as expected when ddtrace-run
is not being used. Is ddtrace.auto
being imported at any point during the start up of your application? If possible, I'd recommend initialising ddtrace
inside a sitecustomize.py
script, e.g.
# in custom sitecustomize.py
import ddtrace.auto. # noqa
from ddtrace.profiling import Profiler
profiler = Profiler(env='service_version', service='service_name', version='service_version')
profiler.start()
This is to ensure that the import of ddtrace.auto
happens before gevent
monkey-patching.
Hi @P403n1x87, I would be happy to provide you with more details (but some of them maybe should be in a private conversation).
Actually, the application isn't a flask running with gevent. I think that those dependencies were there because they are dev-only dependencies (I run it on my local computer).
Regarding the monkey patching - it is possible that the import doesn't run as early as possible, especially because if requires to load the settings and more configuration related modules. But, it is one of the first imports. Notice that the import is a local import, that occurs only if the tracer is enabled in remote configuration.
Regarding ddtrace.auto
- No. It is not imported in the app, and the only Datadog-related import we have is from ddtrace.profiling import Profiler
.
Manually doing what the Github Action was supposed to do (fixed in https://github.com/DataDog/dd-trace-py/pull/7835):
This issue has been automatically closed after six months of inactivity. If it's a feature request, it has been added to the maintainers' internal backlog and will be included in an upcoming round of feature prioritization. Please comment or reopen if you think this issue was closed in error.
Summary of problem
When running
ddtrace
with latest version1.14.0
, after launching the app (usingProfiler(...).start
), I get the following error:TypeError: expected str, bytes or os.PathLike object, not Path
Notice that it does not happen on
ddtrace==1.13.4
Stack trace:
Which version of dd-trace-py are you using?
1.14.0
Which version of pip are you using?
pip 22.3.1 from /usr/local/lib/python3.11/packages.zip/pip (python 3.11)
Which libraries and their versions are you using?
`pip freeze`
> will be provided if neededHow can we reproduce your problem?
Run it on Python 3.11, on Kubernetes with Datadog agent
gcr.io/datadoghq/agent:7.42.1
with the following mount: