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

Log Correlation:change ddsource to a scalar value #2022

Merged
merged 5 commits into from
May 18, 2022
Merged

Conversation

marcotc
Copy link
Member

@marcotc marcotc commented May 13, 2022

After making some changes to our internal demo environment, we noticed the Ruby tracer is setting incorrect values for trace correlation: ddsource should be the language name 'ruby', but it was an array with a single string element ddsource: ['ruby'].
This caused our logging pipeline to not be able to process rich Ruby log entries, instead defaulting to plain text.

This PR addresses this issue.

I also added unit tests for Lograge and SemanticLogger, as those were only tests in an integration setting before.

@marcotc marcotc added the logging Log Management product label May 13, 2022
@marcotc marcotc requested a review from a team May 13, 2022 23:19
@marcotc marcotc self-assigned this May 13, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #2022 (f2a68f7) into master (7367ecf) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##           master    #2022    +/-   ##
========================================
  Coverage   97.45%   97.45%            
========================================
  Files        1016     1022     +6     
  Lines       51476    51649   +173     
========================================
+ Hits        50164    50335   +171     
- Misses       1312     1314     +2     
Impacted Files Coverage Δ
...datadog/tracing/contrib/lograge/instrumentation.rb 100.00% <ø> (ø)
lib/datadog/tracing/contrib/rails/log_injection.rb 85.71% <ø> (-0.96%) ⬇️
...tracing/contrib/semantic_logger/instrumentation.rb 100.00% <ø> (ø)
lib/datadog/core/configuration/settings.rb 100.00% <100.00%> (ø)
lib/datadog/core/environment/variable_helpers.rb 100.00% <100.00%> (ø)
lib/datadog/kit/enable_core_dumps.rb 100.00% <100.00%> (ø)
lib/datadog/logging.rb 100.00% <100.00%> (ø)
lib/datadog/logging/ext.rb 100.00% <100.00%> (ø)
lib/ddtrace.rb 100.00% <100.00%> (ø)
.../datadog/core/environment/variable_helpers_spec.rb 100.00% <100.00%> (ø)
... and 4 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

Copy link
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

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

Thanks for the fix and the added test coverage.

I'm not convinced by the addition of the logging top-level module (as noted in the comment), but I'll leave the final decision up to you.

Comment on lines -30 to -44

def datadog_trace_log_hash(correlation)
{
# Adds IDs as tags to log output
dd: {
# To preserve precision during JSON serialization, use strings for large numbers
trace_id: correlation.trace_id.to_s,
span_id: correlation.span_id.to_s,
env: correlation.env.to_s,
service: correlation.service.to_s,
version: correlation.version.to_s
},
ddsource: ['ruby']
}
end
Copy link
Member

Choose a reason for hiding this comment

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

This left me scratching my head a bit so I went digging to understand why this was still here and unused and here's what I learned using git log -p -S datadog_trace_log_hash (aka "git pickaxe"):

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds correct, I did the same git history digging, should have left a comment, sorry.

lib/ddtrace.rb Outdated
Comment on lines 3 to 7
# Load logging before tracing as trace <> log correlation,
# implemented in the tracing component, depends on logging
# data structures.
# Logging is also does not depend on other products.
require 'datadog/logging'
Copy link
Member

Choose a reason for hiding this comment

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

I'm... not entirely convinced by this:

  1. Creating a whole new top-level module just to contain a single ext with a single string saying "ruby" seems a lot of complexity for such a simple thing
  2. If tracing depends on this, shouldn't it be required in datadog/tracing? This seems like it'll break for customers that use require 'datadog/tracing' instead of require 'ddtrace'.

I would suggest instead having this inside lib/datadog/core/logging/ext.rb or something similar. We can always move it out once a bigger "logging" thing starts taking shape, but I think it's a bit too early to do so.

Copy link
Member Author

@marcotc marcotc May 17, 2022

Choose a reason for hiding this comment

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

I can live with lib/datadog/tracing/ext.rb.

Comment on lines 33 to 37
service: correlation.service.to_s,
version: correlation.version.to_s
},
ddsource: ['ruby']
ddsource: Logging::Ext::DD_SOURCE
}
Copy link
Member

Choose a reason for hiding this comment

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

I guess maybe not for this PR, but /me spots something that looks like it should be inside a Correlation#to_log_hash_format and not repeated twice :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, it wasn't super clean to do it in this PR, so I didn't refactor that part.

Comment on lines 39 to 47
is_expected.to eq({ original: 'option',
dd: {
env: 'env',
service: 'service',
span_id: 'span_id',
trace_id: 'trace_id',
version: 'version'
},
ddsource: 'ruby' })
Copy link
Member

Choose a reason for hiding this comment

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

Really
       really 
                minor:
                         to avoid things advancing towards the right
                                                                      as they get indented
                                                                      I usually break
                                                                      the line to avoid
                                                                      the awkward right-
                                                                      aligned thing.
Suggested change
is_expected.to eq({ original: 'option',
dd: {
env: 'env',
service: 'service',
span_id: 'span_id',
trace_id: 'trace_id',
version: 'version'
},
ddsource: 'ruby' })
is_expected.to eq({
original: 'option',
dd: {
env: 'env',
service: 'service',
span_id: 'span_id',
trace_id: 'trace_id',
version: 'version',
},
ddsource: 'ruby',
})

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree... I think my threshold for "too much to the right" is probably different then yours :p

Comment on lines 47 to 55
expect(event.named_tags).to eq({ original: 'tag',
dd: {
env: 'env',
service: 'service',
span_id: 'span_id',
trace_id: 'trace_id',
version: 'version'
},
ddsource: 'ruby' })
Copy link
Member

Choose a reason for hiding this comment

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

Minor: Same suggestion as above

Suggested change
expect(event.named_tags).to eq({ original: 'tag',
dd: {
env: 'env',
service: 'service',
span_id: 'span_id',
trace_id: 'trace_id',
version: 'version'
},
ddsource: 'ruby' })
expect(event.named_tags).to eq({
original: 'tag',
dd: {
env: 'env',
service: 'service',
span_id: 'span_id',
trace_id: 'trace_id',
version: 'version',
},
ddsource: 'ruby',
})

Copy link
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@marcotc marcotc merged commit 9653c62 into master May 18, 2022
@marcotc marcotc deleted the ddsource-fix branch May 18, 2022 23:08
@github-actions github-actions bot added this to the 1.1.0 milestone May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logging Log Management product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants