refactor(esbuild): extract logging into module#7439
Conversation
Overall package sizeSelf size: 4.57 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 2.0.6 | 81.92 kB | 813.08 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7439 +/- ##
=======================================
Coverage 80.41% 80.41%
=======================================
Files 732 732
Lines 31051 31051
=======================================
Hits 24971 24971
Misses 6080 6080 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
BenchmarksBenchmark execution time: 2026-02-05 10:00:52 Comparing candidate commit a2c60c1 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 233 metrics, 27 unstable metrics. |
86646ea to
7d2637c
Compare
Extract console logging into a dedicated log module that: - Uses printf-style formatting for consistency - Conditionally logs based on DD_TRACE_DEBUG env var - Eliminates scattered DEBUG conditionals throughout code - Adds consistent prefixes for better log identification Also cleans up the `require` section of the code to modernizes imports with `node:` prefix.
7d2637c to
6c3e7ad
Compare
BridgeAR
left a comment
There was a problem hiding this comment.
I like the cleaner way for the logging and the env fix (while now less people will likely see the debug output)!
The behavior here is a bit different than other loggers though, since it does not depend on a log level but only on the debug env being defined. That is now just less obvious. I guess that is fine.
packages/datadog-esbuild/src/log.js
Outdated
| const { format } = require('util') | ||
|
|
||
| // eslint-disable-next-line eslint-rules/eslint-process-env | ||
| const DEBUG = process.env.DD_TRACE_DEBUG === 'true' || process.env.DD_TRACE_DEBUG === '1' |
| } else if (DEBUG) { | ||
| console.warn('Warning: No git metadata available - skipping injection') | ||
| log.debug( | ||
| 'Automatically injected git metadata (DD_GIT_REPOSITORY_URL: %s, DD_GIT_COMMIT_SHA: %s)', |
There was a problem hiding this comment.
Should we still keep these on new lines?
There was a problem hiding this comment.
I don't see any reason to 🤷 Unless there's a good reason not to, I think it's always better to make sure log lines can be "standalone". This makes any log parsing simpler, as you can view a single log line and still get the full context.
What do you mean? Because people who previously ran it with |
Extract console logging into a dedicated log module that: - Uses printf-style formatting for consistency - Conditionally logs based on DD_TRACE_DEBUG env var - Eliminates scattered DEBUG conditionals throughout code - Adds consistent prefixes for better log identification Also cleans up the `require` section of the code to modernizes imports with `node:` prefix.
Extract console logging into a dedicated log module that: - Uses printf-style formatting for consistency - Conditionally logs based on DD_TRACE_DEBUG env var - Eliminates scattered DEBUG conditionals throughout code - Adds consistent prefixes for better log identification Also cleans up the `require` section of the code to modernizes imports with `node:` prefix.
Extract console logging into a dedicated log module that: - Uses printf-style formatting for consistency - Conditionally logs based on DD_TRACE_DEBUG env var - Eliminates scattered DEBUG conditionals throughout code - Adds consistent prefixes for better log identification Also cleans up the `require` section of the code to modernizes imports with `node:` prefix.
Extract console logging into a dedicated log module that: - Uses printf-style formatting for consistency - Conditionally logs based on DD_TRACE_DEBUG env var - Eliminates scattered DEBUG conditionals throughout code - Adds consistent prefixes for better log identification Also cleans up the `require` section of the code to modernizes imports with `node:` prefix.

What does this PR do?
log.jsmodule with printf-style formatting and consistent prefixes.requirecalls.Motivation
The esbuild package had scattered
DEBUGconditionals and inconsistent logging patterns throughoutpackages/datadog-esbuild/index.js. This made the code harder to read and maintain.By extracting logging into a dedicated module and fixing the linting scope, the code becomes cleaner, more maintainable, and better adheres to the project's coding standards (printf-style formatting, proper use of the
node:prefix for core modules).