Skip to content

fix(debugger): limit and safely stringify template log message values - #9766

Open
watson wants to merge 1 commit into
masterfrom
watson/DEBUG-5974/limit-stringified-props-in-log-msgs
Open

fix(debugger): limit and safely stringify template log message values#9766
watson wants to merge 1 commit into
masterfrom
watson/DEBUG-5974/limit-stringified-props-in-log-msgs

Conversation

@watson

@watson watson commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Adds a dedicated inspectSegment helper for Debugger log template expressions. It limits enumerable object properties to five, omits values that could run user code during inspection, and renders direct proxies as [Proxy]. The devtools client now calls this helper via a dd-trace global instead of inlining util.inspect options.

Motivation

Template log messages could stringify objects with unbounded property counts. Inspection can also invoke user code when walking a prototype-chain proxy (getPrototypeOf traps) or formatting values with Symbol.toStringTag getters (notably class instances). Note that util.inspect on a direct Proxy value generally does not exercise ownKeys/get traps on current Node; the [Proxy] label is mainly for predictable, bounded output rather than trap avoidance alone. DEBUG-5974.

Additional Notes

  • Small objects with a Symbol.toStringTag getter are fully omitted rather than partially inspected; a TODO in inspect-segment.js tracks whether that trade-off should change.

@watson
watson requested a review from a team as a code owner August 11, 2026 08:36
@github-actions github-actions Bot added semver-patch debugger Dynamic Instrumentation & Live Debugger labels Aug 11, 2026
@dd-octo-sts

dd-octo-sts Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 8.09 MB
Deduped: 8.75 MB
No deduping: 8.75 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.3 | 125.43 kB | 441.68 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |

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

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Aug 11, 2026

Copy link
Copy Markdown

Pipelines  Tests

⚠️ Warnings

🚦 2 Pipeline jobs failed

Debugger | Debugger / ubuntu (node-oldest)   View in Datadog   GitHub Actions

🔧 Fix in code. This looks caused by changes in this PR. 2 failed tests. AssertionError: Expected values to be strictly equal: actual: 'Set(5) { 1, 2, 3, 4, 5 }', expected: 'Set(5) { 1, 2, 3, ... 2 more items }' at template.spec.js:81.

All Green | all-green   View in Datadog   GitHub Actions

📋 Copy prompt for your agent
CI on my pull request is failing. Help me find and fix the root cause of each failing job below — they were flagged as caused by changes in this PR, so focus on the diff. For each job, explain the failure and propose a fix.

Branch: watson/DEBUG-5974/limit-stringified-props-in-log-msgs

Debugger | Debugger / ubuntu (node-oldest)
Commit: 3be79a52b13680123888ac1e0fb6f0e19074f00a
Error (code / test):
2 failed tests. AssertionError: Expected values to be strictly equal: actual: 'Set(5) { 1, 2, 3, 4, 5 }', expected: 'Set(5) { 1, 2, 3, ... 2 more items }' at template.spec.js:81.
CI job: https://github.com/DataDog/dd-trace-js/actions/runs/31688123216/job/94409970882

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 97.39% (-1.14%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 4b3ad48 | Docs | Datadog PR Page | Give us feedback!

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Aug 11, 2026

Copy link
Copy Markdown

Bits has a CI fix ready

🟢 Investigated · 🟢 Fix prepared · ⚪ Validation skipped · 🟠 Ready

integration-tests/debugger/template.spec.js now preserves the Node 18-specific util.inspect output for five-item Set and Map values while retaining the newer-runtime truncation expectations.

Commit fix to this PR


View in Datadog | Reviewed commit 964bab5 · Any feedback? Reach out in #deveng-pr-agent

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.39%. Comparing base (0becef3) to head (4b3ad48).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9766      +/-   ##
==========================================
+ Coverage   93.41%   97.39%   +3.97%     
==========================================
  Files         950      970      +20     
  Lines      140420   141221     +801     
  Branches    11077    12007     +930     
==========================================
+ Hits       131170   137538    +6368     
+ Misses       9250     3683    -5567     
Flag Coverage Δ
aiguard 57.68% <40.00%> (-0.03%) ⬇️
aiguard-integration 55.87% <40.00%> (-0.01%) ⬇️
apm-bucket-0 57.17% <40.00%> (-0.03%) ⬇️
apm-bucket-1 63.30% <40.00%> (-0.03%) ⬇️
apm-bucket-2 62.15% <40.00%> (-0.03%) ⬇️
apm-bucket-3 59.74% <40.00%> (-0.03%) ⬇️
apm-capabilities-tracing 62.37% <40.00%> (-0.01%) ⬇️
apm-integrations-aerospike 56.21% <40.00%> (-0.03%) ⬇️
apm-integrations-confluentinc-kafka-javascript 61.10% <40.00%> (-0.06%) ⬇️
apm-integrations-couchbase 56.65% <40.00%> (-0.03%) ⬇️
apm-integrations-http 61.84% <40.00%> (-0.03%) ⬇️
apm-integrations-kafkajs 61.65% <40.00%> (-0.03%) ⬇️
apm-integrations-next 59.34% <40.00%> (-0.03%) ⬇️
apm-integrations-prisma 58.45% <40.00%> (-0.03%) ⬇️
appsec 72.07% <40.00%> (-0.03%) ⬇️
appsec-express_fastify_graphql 69.38% <40.00%> (-0.02%) ⬇️
appsec-integration 50.02% <40.00%> (-0.01%) ⬇️
appsec-kafka_ldapjs_lodash 63.35% <40.00%> (-0.03%) ⬇️
appsec-mongodb-core_mongoose_mysql 66.82% <40.00%> (-0.02%) ⬇️
appsec-next 56.60% <40.00%> (-0.02%) ⬇️
appsec-node-serialize_passport_postgres 66.23% <40.00%> (-0.02%) ⬇️
appsec-sourcing_stripe_template 64.66% <40.00%> (-0.03%) ⬇️
debugger 64.24% <100.00%> (+0.03%) ⬆️
instrumentations-bucket-0 51.61% <40.00%> (-0.03%) ⬇️
instrumentations-bucket-1 59.60% <40.00%> (-0.03%) ⬇️
instrumentations-bucket-10 60.83% <40.00%> (-0.03%) ⬇️
instrumentations-bucket-11 61.49% <40.00%> (-0.03%) ⬇️
instrumentations-bucket-12 51.52% <40.00%> (-0.03%) ⬇️
instrumentations-bucket-13 52.36% <40.00%> (-0.03%) ⬇️
instrumentations-bucket-14 51.63% <40.00%> (-0.03%) ⬇️
instrumentations-bucket-2 52.85% <40.00%> (-0.03%) ⬇️
instrumentations-bucket-3 53.50% <40.00%> (-0.03%) ⬇️
instrumentations-bucket-4 58.66% <40.00%> (-0.03%) ⬇️
instrumentations-bucket-5 49.34% <40.00%> (-0.03%) ⬇️
instrumentations-bucket-6 60.22% <40.00%> (-0.03%) ⬇️
instrumentations-bucket-7 51.81% <40.00%> (-0.03%) ⬇️
instrumentations-bucket-8 58.34% <40.00%> (-0.03%) ⬇️
instrumentations-bucket-9 57.19% <40.00%> (-0.03%) ⬇️
instrumentations-instrumentation-couchbase 50.86% <40.00%> (-0.03%) ⬇️
instrumentations-integration-esbuild 34.05% <40.00%> (-0.01%) ⬇️
llmobs-ai_anthropic_bedrock 62.81% <40.00%> (-0.02%) ⬇️
llmobs-bucket-1 61.29% <40.00%> (-0.02%) ⬇️
llmobs-openai 61.69% <40.00%> (?)
llmobs-openai-agents_vertex-ai 59.98% <40.00%> (-0.03%) ⬇️
llmobs-sdk 66.72% <40.00%> (-0.03%) ⬇️
master-coverage 97.39% <100.00%> (?)
openfeature 55.62% <40.00%> (-0.01%) ⬇️
openfeature-unit 53.23% <40.00%> (-0.03%) ⬇️
platform-core_esbuild_instrumentations-misc 41.08% <40.00%> (-0.02%) ⬇️
platform-integration 60.37% <40.00%> (-0.01%) ⬇️
platform-shimmer_unit-guardrails_webpack 38.67% <40.00%> (-0.02%) ⬇️
plugins-bucket-0 56.87% <40.00%> (-0.03%) ⬇️
plugins-bucket-1 53.96% <40.00%> (-0.01%) ⬇️
plugins-bucket-11 61.42% <40.00%> (-0.03%) ⬇️
plugins-bucket-17 61.24% <40.00%> (-0.03%) ⬇️
plugins-bucket-18 61.87% <40.00%> (-0.03%) ⬇️
plugins-bucket-19 61.25% <40.00%> (-0.03%) ⬇️
plugins-bucket-20 63.67% <40.00%> (-0.03%) ⬇️
plugins-bucket-4 58.25% <40.00%> (-0.03%) ⬇️
plugins-bullmq_cassandra_cookie 61.32% <40.00%> (-0.03%) ⬇️
plugins-cookie-parser_crypto_dd-trace-api 56.30% <40.00%> (-0.03%) ⬇️
plugins-fetch_fs_generic-pool 58.16% <40.00%> (-0.03%) ⬇️
plugins-google-cloud-pubsub_grpc_handlebars 64.09% <40.00%> (?)
plugins-hapi_hono_ioredis 59.84% <40.00%> (?)
plugins-knex_langgraph_ldapjs 55.01% <40.00%> (?)
plugins-light-my-request_limitd-client_lodash 58.31% <40.00%> (?)
plugins-mariadb_memcached_mercurius 61.23% <40.00%> (-0.03%) ⬇️
plugins-mongodb_mongodb-core_mongoose 59.20% <40.00%> (-0.03%) ⬇️
plugins-multer_mysql_mysql2 58.79% <40.00%> (-0.03%) ⬇️
plugins-nats_node-serialize_opensearch 60.34% <40.00%> (-0.03%) ⬇️
plugins-passport-http_pino_postgres 58.53% <40.00%> (-0.06%) ⬇️
plugins-process_pug_redis 57.33% <40.00%> (-0.03%) ⬇️
plugins-undici_url_valkey 57.97% <40.00%> (-0.03%) ⬇️
plugins-vm_winston_ws 59.54% <40.00%> (-0.03%) ⬇️
profiling 61.45% <40.00%> (?)
serverless-aws-sdk-aws-sdk 55.08% <40.00%> (-0.03%) ⬇️
serverless-aws-sdk-base-inject-field 50.84% <40.00%> (-0.03%) ⬇️
serverless-aws-sdk-bedrockruntime 54.61% <40.00%> (-0.03%) ⬇️
serverless-aws-sdk-client 56.17% <40.00%> (-0.03%) ⬇️
serverless-aws-sdk-dynamodb 55.45% <40.00%> (-0.02%) ⬇️
serverless-aws-sdk-eventbridge 49.65% <40.00%> (-0.03%) ⬇️
serverless-aws-sdk-kinesis 59.03% <40.00%> (-0.03%) ⬇️
serverless-aws-sdk-lambda 57.18% <40.00%> (-0.03%) ⬇️
serverless-aws-sdk-s3 55.54% <40.00%> (-0.03%) ⬇️
serverless-aws-sdk-serverless-peer-service 59.28% <40.00%> (-0.03%) ⬇️
serverless-aws-sdk-sns 59.83% <40.00%> (?)
serverless-aws-sdk-sqs 60.25% <40.00%> (-0.03%) ⬇️
serverless-aws-sdk-stepfunctions 55.37% <40.00%> (-0.03%) ⬇️
serverless-aws-sdk-util 51.37% <40.00%> (-0.03%) ⬇️
serverless-bucket-0 54.01% <40.00%> (?)
serverless-bucket-1 58.80% <40.00%> (?)
test-optimization-cucumber 71.26% <40.00%> (?)
test-optimization-cypress 64.93% <40.00%> (+0.05%) ⬆️
test-optimization-jest 72.63% <40.00%> (-0.01%) ⬇️
test-optimization-mocha 72.19% <40.00%> (+0.03%) ⬆️
test-optimization-playwright-playwright-atr 59.82% <40.00%> (-0.03%) ⬇️
test-optimization-playwright-playwright-efd 59.98% <40.00%> (-0.02%) ⬇️
test-optimization-playwright-playwright-final-status 60.14% <40.00%> (-0.05%) ⬇️
test-optimization-playwright-playwright-impacted-tests 59.69% <40.00%> (+0.13%) ⬆️
test-optimization-playwright-playwright-reporting 61.01% <40.00%> (-0.09%) ⬇️
test-optimization-playwright-playwright-test-management 60.65% <40.00%> (?)
test-optimization-playwright-playwright-test-span 59.87% <40.00%> (-0.08%) ⬇️
test-optimization-selenium 59.14% <40.00%> (-0.15%) ⬇️
test-optimization-testopt 57.74% <40.00%> (?)
test-optimization-vitest 73.34% <40.00%> (+0.02%) ⬆️
test-optimization-vitest-browser 59.05% <40.00%> (-0.02%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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.

@watson
watson force-pushed the watson/DEBUG-5974/limit-stringified-props-in-log-msgs branch from 00161cd to dfabaf8 Compare August 11, 2026 10:05
@pr-commenter

pr-commenter Bot commented Aug 11, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-13 10:04:06

Comparing candidate commit 4b3ad48 in PR branch watson/DEBUG-5974/limit-stringified-props-in-log-msgs with baseline commit 0becef3 in branch master.

📊 Benchmarking dashboard

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

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:appsec-appsec-enabled-24

  • unstable execution_time [-211.903ms; +201.919ms] or [-7.771%; +7.405%]

scenario:appsec-appsec-enabled-26

  • unstable execution_time [-243.074ms; +237.332ms] or [-9.325%; +9.105%]

scenario:appsec-appsec-enabled-with-attacks-24

  • unstable execution_time [-162.502ms; +172.042ms] or [-5.179%; +5.483%]

scenario:appsec-appsec-enabled-with-attacks-26

  • unstable execution_time [-198.919ms; +182.134ms] or [-6.731%; +6.163%]

scenario:appsec-control-20

  • unstable execution_time [-120353.775µs; +121469.875µs] or [-7.239%; +7.307%]

scenario:appsec-control-24

  • unstable execution_time [-118.759ms; +110.168ms] or [-9.418%; +8.736%]

scenario:appsec-control-26

  • unstable execution_time [-127.178ms; +129.497ms] or [-10.062%; +10.245%]

scenario:appsec-iast-no-vulnerability-control-20

  • unstable execution_time [-11.742ms; +14.815ms] or [-4.532%; +5.718%]

scenario:appsec-iast-no-vulnerability-iast-enabled-default-config-20

  • unstable execution_time [-18486.970µs; +20258.093µs] or [-7.158%; +7.844%]

scenario:appsec-iast-with-vulnerability-control-20

  • unstable execution_time [-24.453ms; +31.939ms] or [-4.445%; +5.806%]

scenario:appsec-iast-with-vulnerability-iast-enabled-default-config-20

  • unstable execution_time [-29.147ms; +35.252ms] or [-5.267%; +6.371%]

scenario:debugger-line-probe-with-snapshot-default-24

  • unstable cpu_user_time [-28.461s; +9.869s] or [-124.641%; +43.221%]
  • unstable execution_time [-37.818s; +12.931s] or [-140.658%; +48.094%]
  • unstable instructions [-74.6G instructions; +29.4G instructions] or [-57.781%; +22.812%]
  • unstable max_rss_usage [-67.330MB; +24.276MB] or [-32.197%; +11.608%]
  • unstable throughput [-339.731op/s; +551.597op/s] or [-16.078%; +26.105%]

scenario:debugger-line-probe-with-snapshot-default-26

  • unstable cpu_user_time [-2293.926ms; +2278.320ms] or [-16.947%; +16.832%]
  • unstable execution_time [-2405.613ms; +2368.923ms] or [-16.636%; +16.382%]
  • unstable instructions [-19461.1M instructions; +19488.2M instructions] or [-17.627%; +17.651%]
  • unstable throughput [-471.934op/s; +474.864op/s] or [-20.748%; +20.877%]

scenario:debugger-line-probe-with-snapshot-minimal-20

  • unstable cpu_user_time [-20002.672ms; +19977.295ms] or [-98.209%; +98.084%]
  • unstable execution_time [-25469.122ms; +25421.212ms] or [-108.649%; +108.445%]
  • unstable instructions [-47724.9M instructions; +47757.9M instructions] or [-39.226%; +39.253%]
  • unstable max_rss_usage [-51781.021KB; +52352.221KB] or [-29.653%; +29.981%]
  • unstable throughput [-969.924op/s; +973.943op/s] or [-45.556%; +45.745%]

scenario:debugger-line-probe-with-snapshot-minimal-24

  • unstable cpu_user_time [-13.199s; +21.181s] or [-78.899%; +126.616%]
  • unstable execution_time [-16.959s; +27.189s] or [-90.938%; +145.796%]
  • unstable instructions [-30.6G instructions; +50.4G instructions] or [-27.019%; +44.509%]
  • unstable max_rss_usage [-68.000MB; +108.787MB] or [-35.120%; +56.185%]
  • unstable throughput [-1006.327op/s; +610.645op/s] or [-46.371%; +28.138%]

scenario:debugger-line-probe-with-snapshot-minimal-26

  • unstable cpu_user_time [-17621.555ms; +17861.054ms] or [-82.159%; +83.276%]
  • unstable execution_time [-21690.978ms; +21934.762ms] or [-90.389%; +91.405%]
  • unstable instructions [-51477.0M instructions; +53455.6M instructions] or [-37.192%; +38.622%]
  • unstable max_rss_usage [-97697.433KB; +96811.833KB] or [-45.100%; +44.691%]
  • unstable throughput [-777.905op/s; +770.395op/s] or [-42.287%; +41.878%]

scenario:debugger-line-probe-without-snapshot-24

  • unstable instructions [-17.1G instructions; +23.3G instructions] or [-9.665%; +13.148%]
  • unstable max_rss_usage [-24.842MB; +17.406MB] or [-6.609%; +4.631%]

scenario:debugger-line-probe-without-snapshot-26

  • unstable instructions [-19652.5M instructions; +19738.2M instructions] or [-10.310%; +10.355%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-358.332ms; +341.457ms] or [-7.290%; +6.947%]
  • unstable execution_time [-354.667ms; +340.594ms] or [-7.103%; +6.821%]
  • unstable throughput [-111070.185op/s; +129972.393op/s] or [-6.632%; +7.760%]

scenario:plugin-graphql-long-with-depth-and-collapse-off-20

  • unstable max_rss_usage [-23.992MB; +17.326MB] or [-6.052%; +4.370%]

scenario:plugin-graphql-long-with-depth-off-26

  • unstable max_rss_usage [-32338.502KB; +33742.502KB] or [-17.079%; +17.820%]

scenario:plugin-pg-service-20

  • unstable throughput [-370121.263op/s; +237127.909op/s] or [-10.037%; +6.431%]

scenario:plugin-pg-service-26

  • unstable cpu_usage_percentage [-6.248%; +4.091%]
  • unstable execution_time [-67.134ms; +76.137ms] or [-7.448%; +8.447%]
  • unstable throughput [-440489.487op/s; +412468.134op/s] or [-6.521%; +6.106%]

Comment on lines +49 to +55
const symbols = Object.getOwnPropertySymbols(value)
for (let i = 0; i < symbols.length; i++) {
if (Object.getOwnPropertyDescriptor(value, symbols[i])?.enumerable === true) {
propertyCount++
if (keys.length < maxProperties) keys.push(symbols[i])
}
}

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.

If keys.length (propertyCount, while pulling out the length is not changing performance) is above maxProperties, this whole code will never add any keys and I think we should skip it (getting the symbols and descriptors is actually expensive)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I was originally thinking the same, but ended up with this implementation to ensure the n more properties was counted correctly... but it's a tough choice. Do we optimize for performance or correctness 🤷

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.

Hm, in new Node.js versions having objects with zero symbols is faster again. So it might not hurt that badly anymore.

Comment on lines +32 to +41
Array.isArray(value) ||
types.isTypedArray(value) ||
types.isAnyArrayBuffer(value) ||
types.isDataView(value) ||
types.isMap(value) ||
types.isSet(value) ||
types.isWeakMap(value) ||
types.isWeakSet(value) ||
types.isMapIterator(value) ||
types.isSetIterator(value)

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.

We could check for an iterable symbol. That is not perfect, since it could still be a regular object, while unlikely and it would allow to skip multiple checks.

@watson watson Aug 11, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I don't like this wall of checks either... but was hoping the V8 optimizer would find a way to make it performant.

I am working on a PR to support this directly in Node core though. If that lands, we can live with a slower polyfill.

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.

These are implemented in Node.js in C++ as fast calls. So they are inlined, while we still need to go through each.

Comment on lines +68 to +76
const descriptor = /** @type {PropertyDescriptor} */ (Object.getOwnPropertyDescriptor(value, keys[i]))
if (
(keys[i] === Symbol.toStringTag && descriptor.get !== undefined) ||
(descriptor.value !== value && inspectionCanRunUserCode(descriptor.value))
) {
return '[Value omitted: inspection may execute user code]'
}
if (descriptor.value === value) descriptor.value = truncated
Object.defineProperty(truncated, keys[i], descriptor)

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.

Since the object will likely be truncated and it is a different object anyway, is copying the descriptor crucial?

If not, we could just check for the presence of the toStringTag with e.g., in and get the descriptor directly.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We don't need all the descriptor flags, but I don't think we can get around having to use descriptor in some capacity. It all depends how many side effects you're willing to potentially trigger. Or maybe I'm misunderstanding your proposal?

@watson
watson force-pushed the watson/DEBUG-5974/limit-stringified-props-in-log-msgs branch from dfabaf8 to 964bab5 Compare August 13, 2026 06:03
Base automatically changed from watson/DEBUG-5974/reuse-loaded-ddtrace to master August 13, 2026 09:46
Debugger log templates previously used util.inspect directly, which
could stringify objects with unbounded property counts and invoke user
code via prototype-chain proxy traps and Symbol.toStringTag getters.

Add inspectSegment to cap enumerable object properties at five, omit
values whose inspection may execute user code, and render direct proxies
as [Proxy] for predictable output. Wire the helper into the devtools
client via a dd-trace global so template expressions use the safe
formatter.
@watson
watson force-pushed the watson/DEBUG-5974/limit-stringified-props-in-log-msgs branch from 964bab5 to 4b3ad48 Compare August 13, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

debugger Dynamic Instrumentation & Live Debugger semver-patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants