-
Notifications
You must be signed in to change notification settings - Fork 377
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
marcotc
reviewed
Aug 27, 2020
marcotc
reviewed
Aug 31, 2020
marcotc
reviewed
Aug 31, 2020
marcotc
reviewed
Aug 31, 2020
marcotc
reviewed
Aug 31, 2020
There was a problem hiding this 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.
marcotc
approved these changes
Sep 1, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
orLograge
. This option can also be enabled with the environment variableDD_LOGS_INJECTION=true
.Additionally, this PR updates the
GettingStarted
documentation to more effectively document the onboarding setup forTrace 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
orLograge
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.