Skip to content

refactor(esbuild): extract logging into module#7439

Merged
BridgeAR merged 2 commits intomasterfrom
watson/DEBUG-5156/esbuild-refactor-logging
Feb 5, 2026
Merged

refactor(esbuild): extract logging into module#7439
BridgeAR merged 2 commits intomasterfrom
watson/DEBUG-5156/esbuild-refactor-logging

Conversation

@watson
Copy link
Copy Markdown
Collaborator

@watson watson commented Feb 5, 2026

What does this PR do?

  • Extract logging logic into a dedicated log.js module with printf-style formatting and consistent prefixes.
  • Clean up require calls.

Motivation

The esbuild package had scattered DEBUG conditionals and inconsistent logging patterns throughout packages/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).

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 5, 2026

Overall package size

Self size: 4.57 MB
Deduped: 5.41 MB
No deduping: 5.41 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

Copy link
Copy Markdown
Collaborator Author

watson commented Feb 5, 2026

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.41%. Comparing base (33297e0) to head (a2c60c1).
⚠️ Report is 2 commits behind head on master.

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           
Flag Coverage Δ
aiguard-macos 39.07% <ø> (-0.11%) ⬇️
aiguard-ubuntu 39.11% <ø> (-0.11%) ⬇️
aiguard-windows 38.96% <ø> (-0.11%) ⬇️
apm-capabilities-tracing-macos 48.89% <ø> (ø)
apm-capabilities-tracing-ubuntu 48.89% <ø> (ø)
apm-capabilities-tracing-windows 48.62% <ø> (ø)
apm-integrations-child-process 38.57% <ø> (-0.11%) ⬇️
apm-integrations-couchbase-18 37.32% <ø> (-0.10%) ⬇️
apm-integrations-couchbase-eol 37.81% <ø> (-0.10%) ⬇️
apm-integrations-oracledb 38.00% <ø> (-0.10%) ⬇️
appsec-express 55.37% <ø> (-0.08%) ⬇️
appsec-fastify 51.99% <ø> (-0.08%) ⬇️
appsec-graphql 52.32% <ø> (-0.07%) ⬇️
appsec-kafka 44.64% <ø> (-0.09%) ⬇️
appsec-ldapjs 44.31% <ø> (-0.09%) ⬇️
appsec-lodash 43.99% <ø> (-0.09%) ⬇️
appsec-macos 58.48% <ø> (-0.07%) ⬇️
appsec-mongodb-core 49.20% <ø> (-0.07%) ⬇️
appsec-mongoose 49.88% <ø> (-0.07%) ⬇️
appsec-mysql 51.26% <ø> (-0.08%) ⬇️
appsec-node-serialize 43.50% <ø> (-0.09%) ⬇️
appsec-passport 48.10% <ø> (-0.09%) ⬇️
appsec-postgres 51.05% <ø> (-0.06%) ⬇️
appsec-sourcing 42.84% <ø> (-0.09%) ⬇️
appsec-template 43.67% <ø> (-0.09%) ⬇️
appsec-ubuntu 58.51% <ø> (-0.07%) ⬇️
appsec-windows 58.35% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-bluebird 32.24% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-body-parser 40.73% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-child_process 37.88% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-cookie-parser 34.50% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-express 34.85% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 34.64% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-express-session 40.41% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-fs 31.84% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-generic-pool 29.79% <ø> (ø)
instrumentations-instrumentation-http 39.62% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-knex 32.24% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-mongoose 33.61% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-multer 40.47% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-mysql2 38.26% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-passport 40.77% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-passport-http 40.74% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-passport-local 40.74% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-pg 37.78% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-promise 32.17% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-promise-js 32.18% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-q 32.22% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-url 32.14% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-when 32.19% <ø> (-0.11%) ⬇️
llmobs-ai 41.41% <ø> (-0.10%) ⬇️
llmobs-anthropic 40.63% <ø> (-0.10%) ⬇️
llmobs-bedrock 39.51% <ø> (-0.09%) ⬇️
llmobs-google-genai 40.11% <ø> (-0.09%) ⬇️
llmobs-langchain 39.66% <ø> (-0.08%) ⬇️
llmobs-openai 44.46% <ø> (-0.09%) ⬇️
llmobs-vertex-ai 40.35% <ø> (-0.08%) ⬇️
platform-core 28.09% <ø> (ø)
platform-esbuild 31.49% <ø> (ø)
platform-instrumentations-misc 39.62% <ø> (ø)
platform-shimmer 34.83% <ø> (ø)
platform-unit-guardrails 30.37% <ø> (ø)
plugins-azure-event-hubs 22.64% <ø> (ø)
plugins-azure-service-bus 22.08% <ø> (ø)
plugins-bullmq 43.56% <ø> (-0.10%) ⬇️
plugins-cassandra 38.04% <ø> (-0.10%) ⬇️
plugins-cookie 23.69% <ø> (ø)
plugins-cookie-parser 23.50% <ø> (ø)
plugins-crypto 22.88% <ø> (ø)
plugins-dd-trace-api 38.39% <ø> (-0.11%) ⬇️
plugins-express-mongo-sanitize 23.67% <ø> (ø)
plugins-express-session 23.46% <ø> (ø)
plugins-fastify 42.53% <ø> (-0.10%) ⬇️
plugins-fetch 38.60% <ø> (-0.10%) ⬇️
plugins-fs 38.67% <ø> (-0.11%) ⬇️
plugins-generic-pool 22.68% <ø> (ø)
plugins-google-cloud-pubsub 45.73% <ø> (-0.09%) ⬇️
plugins-grpc 41.29% <ø> (-0.10%) ⬇️
plugins-handlebars 23.71% <ø> (ø)
plugins-hapi 40.43% <ø> (-0.10%) ⬇️
plugins-hono 40.63% <ø> (-0.10%) ⬇️
plugins-ioredis 38.47% <ø> (-0.11%) ⬇️
plugins-knex 23.51% <ø> (ø)
plugins-ldapjs 21.28% <ø> (ø)
plugins-light-my-request 23.15% <ø> (ø)
plugins-limitd-client 32.54% <ø> (-0.11%) ⬇️
plugins-lodash 22.74% <ø> (ø)
plugins-mariadb 39.60% <ø> (-0.10%) ⬇️
plugins-memcached 38.20% <ø> (-0.11%) ⬇️
plugins-microgateway-core 39.44% <ø> (-0.10%) ⬇️
plugins-moleculer 40.84% <ø> (-0.10%) ⬇️
plugins-mongodb 39.55% <ø> (-0.18%) ⬇️
plugins-mongodb-core 39.12% <ø> (-0.10%) ⬇️
plugins-mongoose 39.18% <ø> (-0.10%) ⬇️
plugins-multer 23.46% <ø> (ø)
plugins-mysql 39.25% <ø> (-0.11%) ⬇️
plugins-mysql2 39.30% <ø> (-0.10%) ⬇️
plugins-node-serialize 23.73% <ø> (ø)
plugins-opensearch 37.87% <ø> (-0.10%) ⬇️
plugins-passport-http 23.56% <ø> (ø)
plugins-postgres 35.71% <ø> (-0.09%) ⬇️
plugins-process 22.88% <ø> (ø)
plugins-pug 23.69% <ø> (ø)
plugins-redis 38.79% <ø> (-0.11%) ⬇️
plugins-router 43.38% <ø> (+0.04%) ⬆️
plugins-sequelize 22.27% <ø> (ø)
plugins-test-and-upstream-amqp10 38.54% <ø> (+0.05%) ⬆️
plugins-test-and-upstream-amqplib 43.90% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-apollo 39.32% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-avsc 38.81% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-bunyan 33.85% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-connect 41.04% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-graphql 40.22% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-koa 40.69% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-protobufjs 39.04% <ø> (-0.11%) ⬇️
plugins-test-and-upstream-rhea 44.15% <ø> (-0.10%) ⬇️
plugins-undici 39.39% <ø> (-0.10%) ⬇️
plugins-url 22.88% <ø> (ø)
plugins-valkey 38.12% <ø> (-0.08%) ⬇️
plugins-vm 22.88% <ø> (ø)
plugins-winston 34.26% <ø> (-0.10%) ⬇️
plugins-ws 40.75% <ø> (-0.10%) ⬇️
profiling-macos 40.06% <ø> (-0.10%) ⬇️
profiling-ubuntu 40.11% <ø> (-0.10%) ⬇️
profiling-windows 41.46% <ø> (-0.10%) ⬇️
serverless-azure-functions-client 22.38% <ø> (ø)
serverless-azure-functions-eventhubs 22.38% <ø> (ø)
serverless-azure-functions-servicebus 22.38% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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
Copy Markdown

datadog-datadog-prod-us1 bot commented Feb 5, 2026

⚠️ Tests

Fix all issues with Cursor

⚠️ Warnings

❄️ 1 New flaky test detected

tests.debugger.test_debugger_inproduct_enablement.Test_Debugger_InProduct_Enablement_Code_Origin.test_inproduct_enablement_code_origin[express4] from system_tests_suite (Datadog) (Fix with Cursor)
AssertionError: Expected code origin enabled by default
assert False
 +  where False = <tests.debugger.test_debugger_inproduct_enablement.Test_Debugger_InProduct_Enablement_Code_Origin object at 0x7f0e931ab4a0>.co_initial_state

self = <tests.debugger.test_debugger_inproduct_enablement.Test_Debugger_InProduct_Enablement_Code_Origin object at 0x7f0e931ab4a0>

    def test_inproduct_enablement_code_origin(self):
        self.assert_rc_state_not_error()
        self.assert_all_weblog_responses_ok()
    
...

ℹ️ Info

🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: a2c60c1 | Docs | Datadog PR Page | Was this helpful? Give us feedback!

@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Feb 5, 2026

Benchmarks

Benchmark execution time: 2026-02-05 10:00:52

Comparing candidate commit a2c60c1 in PR branch watson/DEBUG-5156/esbuild-refactor-logging with baseline commit 33297e0 in branch master.

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

@watson watson force-pushed the watson/DEBUG-5156/esbuild-refactor-logging branch 2 times, most recently from 86646ea to 7d2637c Compare February 5, 2026 08:16
Base automatically changed from watson/DEBUG-5156/lint-root-package-folders to master February 5, 2026 09:21
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.
@watson watson force-pushed the watson/DEBUG-5156/esbuild-refactor-logging branch from 7d2637c to 6c3e7ad Compare February 5, 2026 09:22
@watson watson marked this pull request as ready for review February 5, 2026 09:23
@watson watson requested a review from a team as a code owner February 5, 2026 09:23
BridgeAR
BridgeAR previously approved these changes Feb 5, 2026
Copy link
Copy Markdown
Member

@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.

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.

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'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

} 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)',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we still keep these on new lines?

Copy link
Copy Markdown
Collaborator Author

@watson watson Feb 5, 2026

Choose a reason for hiding this comment

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

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.

@watson
Copy link
Copy Markdown
Collaborator Author

watson commented Feb 5, 2026

while now less people will likely see the debug output

What do you mean? Because people who previously ran it with DD_TRACE_DEBUG=false will no longer see it?

@BridgeAR BridgeAR enabled auto-merge (squash) February 5, 2026 09:53
@BridgeAR BridgeAR merged commit fe7175a into master Feb 5, 2026
1063 of 1065 checks passed
@BridgeAR BridgeAR deleted the watson/DEBUG-5156/esbuild-refactor-logging branch February 5, 2026 10:16
dd-octo-sts bot pushed a commit that referenced this pull request Feb 5, 2026
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.
@dd-octo-sts dd-octo-sts bot mentioned this pull request Feb 5, 2026
BridgeAR pushed a commit that referenced this pull request Feb 5, 2026
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.
bm1549 pushed a commit that referenced this pull request Feb 10, 2026
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.
BridgeAR pushed a commit that referenced this pull request Feb 22, 2026
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.
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.

2 participants