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

Return empty log correlation when tracing is disabled #3731

Merged
merged 3 commits into from
Jun 26, 2024

Conversation

marcotc
Copy link
Member

@marcotc marcotc commented Jun 21, 2024

If you completely disabled tracing, you will see no spans in the Datadog app, but your logs will still look like this:

2024-06-14 16:01:39 D, [2024-06-14T20:01:39.579237 #1] DEBUG -- : [dd.env=test dd.service=my-sev dd.version=1.0 dd.trace_id=123123443424 dd.span_id=0 ddsource=ruby]   Note Load (0.3ms)  SELECT  "tests".* FROM "tests" WHERE "tests"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
2024-06-14 16:01:39 D, [2024-06-14T20:01:39.579349 #1] DEBUG -- : [dd.env=test dd.service=my-sev dd.version=1.0 dd.trace_id=123123443424 dd.span_id=0 ddsource=ruby]   ↳ app/controllers/tests_controller.rb:123
2024-06-14 16:01:39 I, [2024-06-14T20:01:39.580459 #1]  INFO -- : [dd.env=test dd.service=my-sev dd.version=1.0 dd.trace_id=123123443424 dd.span_id=0 ddsource=ruby] Completed 500 Internal Server Error in 10ms (ActiveRecord: 3.1ms)
2024-06-14 16:01:39 F, [2024-06-14T20:01:39.580794 #1] FATAL -- : [dd.env=test dd.service=my-sev dd.version=1.0 dd.trace_id=123123443424 dd.span_id=0 ddsource=ruby]   
2024-06-14 16:01:39 F, [2024-06-14T20:01:39.580823 #1] FATAL -- : [dd.env=test dd.service=my-sev dd.version=1.0 dd.trace_id=123123443424 dd.span_id=0 ddsource=ruby] ActiveRecord::RecordNotFound (Couldn't find Note with 'id'=1):
2024-06-14 16:01:39 F, [2024-06-14T20:01:39.580857 #1] FATAL -- : [dd.env=test dd.service=my-sev dd.version=1.0 dd.trace_id=123123443424 dd.span_id=0 ddsource=ruby]   
2024-06-14 16:01:39 F, [2024-06-14T20:01:39.580872 #1] FATAL -- : [dd.env=test dd.service=my-sev dd.version=1.0 dd.trace_id=123123443424 dd.span_id=0 ddsource=ruby] app/controllers/test_controller.rb:123:in `show'

This information pollutes the logs, it is useless without tracing enabled.

In particular, it is common to disable tracing in development environments. This issue makes logs in such environments much less developer friendly.

This PR returns a fallback empty String for log_correlation when tracing is disabled.
Because the contract of the method is that it always returns a String, it is not an option to return nil without making it a breaking change. Also, an empty String concatenation should be harmless to log entries.

@marcotc marcotc self-assigned this Jun 21, 2024
@marcotc marcotc requested a review from a team as a code owner June 21, 2024 21:35
@marcotc marcotc enabled auto-merge June 26, 2024 18:53
@marcotc marcotc merged commit dea7ae9 into master Jun 26, 2024
163 of 165 checks passed
@marcotc marcotc deleted the trace-disabled-fix branch June 26, 2024 19:11
@github-actions github-actions bot added this to the 2.2.0 milestone Jun 26, 2024
@TonyCTHsu TonyCTHsu mentioned this pull request Jul 11, 2024
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

Successfully merging this pull request may close these issues.

2 participants