Skip to content

Enable log injection by default for structured loggers #5859

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

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

ida613
Copy link
Collaborator

@ida613 ida613 commented Jun 9, 2025

What does this PR do?

Set config.logInjection default to structured, in which case log injection is enabled for structured loggers and disabled for unstructured loggers.
When config.logInjection=true, log injection is enabled for both structured and unstructured loggers
When config.logInjection=false, log injection is disabled for both structured and unstructured loggers

This change breaks the configuration default, so please let me know if there are any concerns regarding how this change is handled!

Motivation

Plugin Checklist

Additional Notes

Copy link

github-actions bot commented Jun 9, 2025

Overall package size

Self size: 9.71 MB
Deduped: 106.22 MB
No deduping: 106.74 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | @datadog/libdatadog | 0.7.0 | 35.02 MB | 35.02 MB | | @datadog/native-appsec | 8.5.2 | 19.33 MB | 19.34 MB | | @datadog/native-iast-taint-tracking | 4.0.0 | 11.72 MB | 11.73 MB | | @datadog/pprof | 5.8.2 | 9.56 MB | 9.93 MB | | @opentelemetry/core | 1.30.1 | 908.66 kB | 7.16 MB | | protobufjs | 7.5.3 | 2.95 MB | 5.6 MB | | @datadog/wasm-js-rewriter | 4.0.1 | 2.85 MB | 3.58 MB | | @datadog/native-metrics | 3.1.1 | 1.02 MB | 1.43 MB | | @opentelemetry/api | 1.8.0 | 1.21 MB | 1.21 MB | | import-in-the-middle | 1.14.0 | 120.58 kB | 841.68 kB | | source-map | 0.7.4 | 226 kB | 226 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | lru-cache | 7.18.3 | 133.92 kB | 133.92 kB | | pprof-format | 2.1.0 | 111.69 kB | 111.69 kB | | @datadog/sketches-js | 2.1.1 | 109.9 kB | 109.9 kB | | lodash.sortby | 4.7.0 | 75.76 kB | 75.76 kB | | ignore | 5.3.2 | 53.63 kB | 53.63 kB | | istanbul-lib-coverage | 3.2.2 | 34.37 kB | 34.37 kB | | rfdc | 1.4.1 | 27.15 kB | 27.15 kB | | @isaacs/ttlcache | 1.4.1 | 25.2 kB | 25.2 kB | | dc-polyfill | 0.1.9 | 25.11 kB | 25.11 kB | | tlhunter-sorted-set | 0.1.0 | 24.94 kB | 24.94 kB | | shell-quote | 1.8.2 | 23.54 kB | 23.54 kB | | limiter | 1.1.5 | 23.17 kB | 23.17 kB | | retry | 0.13.1 | 18.85 kB | 18.85 kB | | semifies | 1.0.0 | 15.84 kB | 15.84 kB | | jest-docblock | 29.7.0 | 8.99 kB | 12.76 kB | | crypto-randomuuid | 1.0.0 | 11.18 kB | 11.18 kB | | ttl-set | 1.0.0 | 4.61 kB | 9.69 kB | | mutexify | 1.4.0 | 5.71 kB | 8.74 kB | | path-to-regexp | 0.1.12 | 6.6 kB | 6.6 kB | | koalas | 1.0.2 | 6.47 kB | 6.47 kB | | module-details-from-path | 1.0.4 | 3.96 kB | 3.96 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

Copy link

codecov bot commented Jun 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.75%. Comparing base (778def8) to head (a6086f9).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5859   +/-   ##
=======================================
  Coverage   80.74%   80.75%           
=======================================
  Files         462      463    +1     
  Lines       19918    19926    +8     
=======================================
+ Hits        16083    16091    +8     
  Misses       3835     3835           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Jun 9, 2025

Datadog Report

Branch report: ida613/enable-log-injection
Commit report: a3b41c5
Test service: dd-trace-js-integration-tests

✅ 0 Failed, 1259 Passed, 0 Skipped, 21m 21.15s Total Time

@pr-commenter
Copy link

pr-commenter bot commented Jun 9, 2025

Benchmarks

Benchmark execution time: 2025-06-18 18:33:04

Comparing candidate commit a6086f9 in PR branch ida613/enable-log-injection with baseline commit 778def8 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 1264 metrics, 59 unstable metrics.

@ida613 ida613 changed the title set config.logInjection default to structured Enable log injection by default for structured loggers Jun 9, 2025
@ida613 ida613 marked this pull request as ready for review June 9, 2025 21:58
@ida613 ida613 requested a review from a team as a code owner June 9, 2025 21:58
@ida613 ida613 requested review from mabdinur, rochdev and BridgeAR June 9, 2025 22:02
@ida613 ida613 requested a review from a team as a code owner June 10, 2025 18:58
Copy link
Collaborator

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

Winston does not always produce structured logs. We need to check the configuration and decide upon that or check each individual message if it's an object or not.

@ida613
Copy link
Collaborator Author

ida613 commented Jun 12, 2025

Winston does not always produce structured logs. We need to check the configuration and decide upon that or check each individual message if it's an object or not.

Thank you Ruben! I added this commit to check if each message is structured for winston. This might cause some CI failures but you can treat it as a draft for now. Please let me know if you have any feedback!

@ida613
Copy link
Collaborator Author

ida613 commented Jun 13, 2025

I've removed winston for now for a separate PR

@ida613
Copy link
Collaborator Author

ida613 commented Jun 15, 2025

I've added this test to see what would happen if we try to inject trace and span ids when winston logs simple strings, it seems like the log gets converted to JSON by the log server and the IDs are still injected properly. I'm not sure if this log server mimics something downstream which receives the logs. If so, I guess it doesn't really matter if winston logs are structured or unstructured, everything becomes structured anyways along the way.

BridgeAR
BridgeAR previously approved these changes Jun 17, 2025
Copy link
Collaborator

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

So after looking into it again, it seems our instrumentation makes sure it is always structured. That in itself is probably theoretically an issue but I am not aware of a bug report about that. It would just fail at an earlier stage, so we do not have to worry about the code here.

In case we use inheritance as suggested here, we have to either make the method public or use the semi public way of using the underscore. I personally would just use composition instead, to prevent the need for that. Inheritance is mostly not easy to follow makes makes things more complicated, not easier.

Should it block this PR? Probably not, I think we have to generally look into it closer soon.

@@ -174,7 +174,7 @@ describe('test visibility automatic log submission', () => {
)
childProcess.on('exit', () => {
assert.include(testOutput, 'Hello simple log!')
assert.notInclude(testOutput, 'span_id')
assert.include(testOutput, 'span_id')
Copy link
Collaborator

Choose a reason for hiding this comment

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

The test message is now a bit confusing, since this is actually the part that should verify that the logs are not submitted.
The test uses winston, so that's why it is now automatically enabled and for the test to behave as expected, we'd have to use a different logger instead.

It is the logger being used in automatic-log-submission-test.js. That requires ./logger and that instruments winston. That would have to change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

if this PR is merged as is, without changes to the test optimization logic, this test would not make sense, so it'd have to be removed

Copy link
Collaborator

@juan-fernandez juan-fernandez left a comment

Choose a reason for hiding this comment

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

I'm blocking until I check with my team what test optimization should do in this case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants