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

Add log_injection option to auto enable rails trace/log correlation #1157

Merged
merged 16 commits into from
Sep 2, 2020

Conversation

ericmustin
Copy link
Contributor

@ericmustin ericmustin commented Aug 27, 2020

Summary

This PR adds an option to the rails instrumentation, log_injection that, when enabled automatically adds trace correlation information to Rails logs when using one of the Datadog supported loggers, ActiveSupport::TaggedLogging or Lograge. This option can also be enabled with the environment variable DD_LOGS_INJECTION=true.

Additionally, this PR updates the GettingStarted documentation to more effectively document the onboarding setup for Trace Correlation with logs, by changing the order of our suggested approaches and also incorporating automatic injection.

Notes

  • The work here attempts to ensure that any current configuration of ActiveSupport::TaggedLogging or Lograge is maintained and merged in with our trace correlation information.

  • In the event of an active_trace not existing, we still inject the relevant keys but leave the values blank. This is a standard practice across our other language Log Injection Implementation at Datadog.

  • I tried to document this clearly but definitely could use a second opinion.

  • Testing wise It was a huge hassle to test log output effectively, the approach I took is a little hacky (originally i was logging to a file but there was leakage between tests), but i think it should work and be robust enough to not leak across tests. I borrowed this approach from the actual Lograge testing setup, https://github.com/roidrage/lograge/blob/1729eab7956bb95c5992e4adab251e4f93ff9280/spec/log_subscribers/action_controller_spec.rb#L9-L35

  • I added the gem in all the appraisals, i'm not 100% sure how far back Lograge and ActiveSupport::TaggedLogging go in terms of rails, looks like https://www.rubydoc.info/docs/rails/3.2.8/ActiveSupport/TaggedLogging 3.2.8 for Tagged Logging but not sure about Lograge.

@ericmustin ericmustin requested a review from a team August 27, 2020 12:38
docs/GettingStarted.md Outdated Show resolved Hide resolved
docs/GettingStarted.md Outdated Show resolved Hide resolved
docs/GettingStarted.md Outdated Show resolved Hide resolved
lib/ddtrace/contrib/rails/configuration/settings.rb Outdated Show resolved Hide resolved
lib/ddtrace/contrib/rails/log_injection.rb Outdated Show resolved Hide resolved
lib/ddtrace/contrib/rails/log_injection.rb Outdated Show resolved Hide resolved
lib/ddtrace/contrib/rails/patcher.rb Outdated Show resolved Hide resolved
spec/ddtrace/contrib/rails/support/rails4.rb Outdated Show resolved Hide resolved
Appraisals Outdated Show resolved Hide resolved
Copy link
Member

@marcotc marcotc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a few changes to the documentation as well, please feel free to modify them if you think there's something that needs to be changed in it.

Copy link
Member

@marcotc marcotc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@ericmustin ericmustin merged commit 0e06522 into master Sep 2, 2020
@marcotc marcotc deleted the update_log_correlation branch September 4, 2020 19:29
@marcotc marcotc added this to the 0.40.0 milestone Sep 8, 2020
@marcotc marcotc added the integrations Involves tracing integrations label Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrations Involves tracing integrations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants