Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can you globally disable tracer via an environment variable? #1279

Closed
zhammer opened this issue Mar 16, 2020 · 7 comments
Closed

can you globally disable tracer via an environment variable? #1279

zhammer opened this issue Mar 16, 2020 · 7 comments

Comments

@zhammer
Copy link
Contributor

zhammer commented Mar 16, 2020

it'd be helpful for our local/test development environments if we could disable ddtrace globally via an environment variable.

i tried using DD_TRACE_ANALYTICS_ENABLED but that doesn't seem to do the trick

$ python -c "import ddtrace; print(ddtrace.tracer.enabled)"
True
$ DD_TRACE_ANALYTICS_ENABLED=false python -c "import ddtrace; print(ddtrace.tracer.enabled)"
True

also can't find any env var in the docs or from poking around the code here:

enabled=True,

if it helps, our main requirement is that the traces aren't actually sent over network once done. it's still fine if the traces are instrumented locally!

@brettlangdon
Copy link
Member

The only thing we have right now is DATADOG_TRACE_ENABLED but only available if you are using ddtrace-run.

DATADOG_TRACE_ENABLED=true|false : override the value of tracer.enabled (default: true)

It has been on my mental todo list to move this from ddtrace-run into ddtrace/tracer.py.

You could implement locally via something like:

import ddtrace
import os

ddtrace.tracer.enabled = bool(os.getenv("DATADOG_TRACE_ENABLED") != "false")

(ish)

@brettlangdon
Copy link
Member

I'll official add a card to our backlog for this.

@zhammer
Copy link
Contributor Author

zhammer commented Mar 16, 2020

great. yeah in these cases we're not running via ddtrace-run.

can help out with a PR if needed

@brettlangdon
Copy link
Member

cool, it could be as easy as changing this line:

enabled=True,

enabled=asbool(get_env("trace", "enabled', default=True))

@zhammer
Copy link
Contributor Author

zhammer commented Mar 16, 2020

ha yeah that's what i was thinking :)

@maximillianus
Copy link

Ah sweet thread. I am also wondering how to disable tracing since DATADOG_TRACE_ENABLED env var does not seem being used in ddtrace library.

This info below not available in the latest version of ddtrace

DATADOG_TRACE_ENABLED=true|false : override the value of tracer.enabled (default: true)

This is the latest version:

USAGE = """
Execute the given Python program after configuring it to emit Datadog traces.
Append command line arguments to your program as usual.
Usage: ddtrace-run <my_program>
""" # noqa: E501

Adding additional code below as mention by @brettlangdon above would be great for user who doesn't use ddtrace-run like me 🙂:

enabled=asbool(get_env("trace", "enabled', default=True))

@brettlangdon
Copy link
Member

This has been resolved by #1575. Apologizes for not closing this issue sooner.

https://github.com/DataDog/dd-trace-py/blob/master/ddtrace/tracer.py#L143

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

No branches or pull requests

3 participants