DataDog / dd-trace-rb

Datadog Tracing Ruby Client
https://docs.datadoghq.com/tracing/
Other
304 stars 370 forks source link

suppress logs by default when running minitest tests #3807

Closed waymondo closed 1 month ago

waymondo commented 1 month ago

when running tests, we get a lot of startup diagnostic logging that is unimportant/noisy. because the gem gets required before rails initializers are loaded, we can't seem to set Datadog.configuration.diagnostics.startup_logs.enabled to false in time before the output occurs.

when looking at the source, it seems what i'm desiring happens when running a program name ending in rspec.

checking $PROGRAM_NAME doesn't exactly work though for running rails tests the built-in way. when running bin/rails t, the program name is bin/rails. but you can also run an individual minitest with bundle exec ruby ..., in which case program name would be ruby.

would there be any gotchas in just checking ENV["RAILS_ENV"] == "test"?

ivoanjo commented 1 month ago

Hey! Thanks for reaching out on this.

I actually think we started down this path but at that time there was some concurrent work ongoing and we ended up not finishing it completely...

Specifically in #3036 we added a better detection for development environments and in #3062 we extended it to check RAILS_ENV for test. At the time we discussed using this new detection code for the environment logger: https://github.com/DataDog/dd-trace-rb/pull/3036#issuecomment-1672268140 and didn't touch it to avoid other conflicts.

@marcotc any concerns on doing it now?


Btw @waymondo as a temporary workaround, you should be able to use the DD_TRACE_STARTUP_LOGS environment variable to "shut up" the logs, and this setting is (as other environment variables) picked up right from the first second the library gets loaded.

marcotc commented 1 month ago

I think merging both the development environment detection from telemetry and startup logs is indeed the solution here. We'll work on that.

TonyCTHsu commented 2 weeks ago

👋 @waymondo 2.3.0 is just released. Give it a try.

waymondo commented 2 weeks ago

👋 @waymondo 2.3.0 is just released. Give it a try.

sweet, will do!