Skip to content

fix(config): extract relevant env vars from pm2_env JSON before tracer init#8863

Merged
tlhunter merged 1 commit into
masterfrom
tlhunter/apms-19774-pm2-cluster-env
Jul 21, 2026
Merged

fix(config): extract relevant env vars from pm2_env JSON before tracer init#8863
tlhunter merged 1 commit into
masterfrom
tlhunter/apms-19774-pm2-cluster-env

Conversation

@tlhunter

@tlhunter tlhunter commented Jun 10, 2026

Copy link
Copy Markdown
Member

What does this PR do?

This allows the tracer to run in pm2 cluster mode. Notably pm2 passes in a JSON-encoded env var that is merges into process.env after --require runs, so this change extracts any tracer-relevant entries first.

Motivation

This is from a user-reported error.

@dd-octo-sts

dd-octo-sts Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 6.77 MB
Deduped: 7.43 MB
No deduping: 7.43 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.1 | 122.62 kB | 438.86 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

@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.34%. Comparing base (57d5f96) to head (74f2de8).

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #8863    +/-   ##
========================================
  Coverage   98.34%   98.34%            
========================================
  Files         924      924            
  Lines      123056   123074    +18     
  Branches    10924    10481   -443     
========================================
+ Hits       121016   121042    +26     
+ Misses       2040     2032     -8     
Flag Coverage Δ
aiguard 58.24% <100.00%> (-0.01%) ⬇️
aiguard-integration 57.08% <ø> (ø)
apm-bucket-0 58.50% <100.00%> (-0.01%) ⬇️
apm-bucket-1 64.61% <100.00%> (-0.01%) ⬇️
apm-bucket-2 63.66% <100.00%> (-0.01%) ⬇️
apm-bucket-3 60.95% <100.00%> (-0.01%) ⬇️
apm-capabilities-tracing 62.32% <100.00%> (+<0.01%) ⬆️
apm-integrations-aerospike 57.63% <100.00%> (-0.01%) ⬇️
apm-integrations-confluentinc-kafka-javascript 62.51% <100.00%> (-0.01%) ⬇️
apm-integrations-couchbase 57.91% <100.00%> (-0.01%) ⬇️
apm-integrations-http 63.65% <100.00%> (-0.01%) ⬇️
apm-integrations-kafkajs 63.11% <100.00%> (-0.01%) ⬇️
apm-integrations-next 60.04% <100.00%> (-0.01%) ⬇️
apm-integrations-prisma 59.46% <100.00%> (-0.01%) ⬇️
appsec 73.96% <100.00%> (+0.01%) ⬆️
appsec-express_fastify_graphql 71.54% <100.00%> (-0.01%) ⬇️
appsec-integration 51.89% <33.33%> (+0.14%) ⬆️
appsec-kafka_ldapjs_lodash 64.83% <100.00%> (-0.01%) ⬇️
appsec-mongodb-core_mongoose_mysql 68.56% <100.00%> (-0.01%) ⬇️
appsec-next 58.20% <100.00%> (-0.01%) ⬇️
appsec-node-serialize_passport_postgres 68.25% <100.00%> (-0.01%) ⬇️
appsec-sourcing_stripe_template 66.56% <100.00%> (-0.01%) ⬇️
debugger 65.90% <100.00%> (+0.01%) ⬆️
instrumentations-bucket-0 52.42% <100.00%> (-0.01%) ⬇️
instrumentations-bucket-1 61.14% <100.00%> (-0.01%) ⬇️
instrumentations-bucket-10 62.99% <100.00%> (-0.01%) ⬇️
instrumentations-bucket-11 52.43% <100.00%> (-0.01%) ⬇️
instrumentations-bucket-12 52.87% <100.00%> (-0.01%) ⬇️
instrumentations-bucket-13 52.37% <100.00%> (-0.01%) ⬇️
instrumentations-bucket-2 54.35% <100.00%> (-0.01%) ⬇️
instrumentations-bucket-3 60.11% <100.00%> (-0.01%) ⬇️
instrumentations-bucket-4 53.01% <100.00%> (-0.01%) ⬇️
instrumentations-bucket-5 58.34% <100.00%> (-0.01%) ⬇️
instrumentations-bucket-6 61.70% <100.00%> (-0.01%) ⬇️
instrumentations-bucket-7 59.24% <100.00%> (-0.01%) ⬇️
instrumentations-bucket-8 60.51% <100.00%> (-0.01%) ⬇️
instrumentations-bucket-9 62.37% <100.00%> (-0.01%) ⬇️
instrumentations-instrumentation-couchbase 51.94% <100.00%> (-0.01%) ⬇️
instrumentations-integration-esbuild 34.05% <ø> (ø)
llmobs-ai_anthropic_bedrock 63.33% <100.00%> (-0.01%) ⬇️
llmobs-bucket-1 62.63% <100.00%> (-0.01%) ⬇️
llmobs-openai 63.31% <100.00%> (-0.01%) ⬇️
llmobs-sdk 65.42% <100.00%> (-0.01%) ⬇️
llmobs-vertex-ai 59.99% <100.00%> (-0.01%) ⬇️
master-coverage 98.34% <100.00%> (?)
openfeature 54.69% <ø> (ø)
openfeature-unit 53.45% <100.00%> (-0.01%) ⬇️
platform-core_esbuild_instrumentations-misc 40.68% <100.00%> (+<0.01%) ⬆️
platform-integration 62.33% <100.00%> (+0.01%) ⬆️
platform-shimmer_unit-guardrails_webpack 39.36% <100.00%> (+<0.01%) ⬆️
plugins-bucket-0 57.77% <100.00%> (-0.01%) ⬇️
plugins-bucket-1 55.16% <33.33%> (-0.02%) ⬇️
plugins-bucket-11 63.11% <100.00%> (+0.36%) ⬆️
plugins-bucket-17 ?
plugins-bucket-18 62.92% <100.00%> (-0.53%) ⬇️
plugins-bucket-19 60.97% <100.00%> (-1.58%) ⬇️
plugins-bucket-20 62.91% <100.00%> (-2.38%) ⬇️
plugins-bucket-4 59.41% <100.00%> (-0.01%) ⬇️
plugins-bullmq_cassandra_cookie 62.70% <100.00%> (-0.01%) ⬇️
plugins-cookie-parser_crypto_dd-trace-api 57.58% <100.00%> (-0.01%) ⬇️
plugins-fetch_fs_generic-pool 59.64% <100.00%> (-0.01%) ⬇️
plugins-google-cloud-pubsub_grpc_handlebars 65.68% <100.00%> (-0.01%) ⬇️
plugins-hapi_hono_ioredis 61.12% <100.00%> (-0.01%) ⬇️
plugins-jest_knex_langgraph 56.39% <100.00%> (?)
plugins-jest_langgraph_ldapjs ?
plugins-ldapjs_light-my-request_limitd-client 59.37% <100.00%> (?)
plugins-light-my-request_limitd-client_lodash ?
plugins-lodash_mariadb_memcached 58.87% <100.00%> (?)
plugins-mariadb_memcached_mercurius ?
plugins-moleculer_mongodb_mongodb-core 62.86% <100.00%> (?)
plugins-mongodb_mongodb-core_mongoose ?
plugins-mongoose_multer_mysql 59.87% <100.00%> (?)
plugins-multer_mysql_mysql2 ?
plugins-mysql2_nats_node-serialize 61.65% <100.00%> (?)
plugins-nats_node-serialize_opensearch ?
plugins-opensearch_passport-http_pino 60.43% <100.00%> (?)
plugins-passport-http_pino_postgres ?
plugins-postgres_process_pug 59.15% <100.00%> (?)
plugins-process_pug_redis ?
plugins-redis_router_sequelize 62.99% <100.00%> (?)
plugins-test-and-upstream-rhea_undici_url 62.55% <100.00%> (?)
plugins-undici_url_valkey ?
plugins-valkey_vm_winston 58.85% <100.00%> (?)
plugins-vm_winston_ws ?
plugins-ws 60.48% <100.00%> (?)
profiling 63.09% <100.00%> (-0.01%) ⬇️
serverless-aws-sdk-aws-sdk 55.73% <100.00%> (-0.01%) ⬇️
serverless-aws-sdk-bedrockruntime 55.45% <100.00%> (-0.01%) ⬇️
serverless-aws-sdk-client 57.19% <100.00%> (-0.01%) ⬇️
serverless-aws-sdk-dynamodb 56.38% <100.00%> (-0.02%) ⬇️
serverless-aws-sdk-eventbridge 49.95% <100.00%> (+<0.01%) ⬆️
serverless-aws-sdk-kinesis 60.16% <100.00%> (-0.01%) ⬇️
serverless-aws-sdk-lambda 58.15% <100.00%> (-0.01%) ⬇️
serverless-aws-sdk-s3 56.32% <100.00%> (-0.01%) ⬇️
serverless-aws-sdk-serverless-peer-service 60.58% <100.00%> (-0.01%) ⬇️
serverless-aws-sdk-sns 60.98% <100.00%> (-0.01%) ⬇️
serverless-aws-sdk-sqs 61.41% <100.00%> (-0.01%) ⬇️
serverless-aws-sdk-stepfunctions 56.30% <100.00%> (-0.01%) ⬇️
serverless-aws-sdk-util 52.21% <100.00%> (-0.01%) ⬇️
serverless-bucket-0 55.21% <33.33%> (-0.02%) ⬇️
serverless-bucket-1 60.11% <100.00%> (-0.01%) ⬇️
test-optimization-cucumber 73.04% <ø> (+0.02%) ⬆️
test-optimization-cypress 66.42% <ø> (+0.08%) ⬆️
test-optimization-jest 74.42% <33.33%> (-0.02%) ⬇️
test-optimization-mocha 74.71% <33.33%> (+0.02%) ⬆️
test-optimization-playwright-playwright-atr 61.49% <ø> (+0.06%) ⬆️
test-optimization-playwright-playwright-efd 61.62% <ø> (ø)
test-optimization-playwright-playwright-final-status 61.59% <ø> (-0.01%) ⬇️
test-optimization-playwright-playwright-impacted-tests 61.31% <ø> (+0.16%) ⬆️
test-optimization-playwright-playwright-reporting 61.21% <ø> (-0.01%) ⬇️
test-optimization-playwright-playwright-test-management 62.15% <ø> (+<0.01%) ⬆️
test-optimization-playwright-playwright-test-span 61.34% <ø> (-0.06%) ⬇️
test-optimization-selenium 60.71% <ø> (-0.16%) ⬇️
test-optimization-testopt 59.20% <33.33%> (+0.07%) ⬆️
test-optimization-vitest 71.33% <ø> (+0.01%) ⬆️

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.

@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Jun 10, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 98.34% (+0.01%)

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

@pr-commenter

pr-commenter Bot commented Jun 10, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-07-17 23:33:16

Comparing candidate commit 74f2de8 in PR branch tlhunter/apms-19774-pm2-cluster-env with baseline commit 57d5f96 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2322 metrics, 36 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 [-208.250ms; +211.127ms] or [-7.850%; +7.958%]

scenario:appsec-appsec-enabled-26

  • unstable execution_time [-225.087ms; +229.140ms] or [-8.849%; +9.009%]

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

  • unstable execution_time [-166.426ms; +158.075ms] or [-5.397%; +5.126%]

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

  • unstable execution_time [-189608.851µs; +188541.951µs] or [-6.551%; +6.514%]

scenario:appsec-control-20

  • unstable execution_time [-110.198ms; +122.963ms] or [-6.723%; +7.502%]

scenario:appsec-control-24

  • unstable execution_time [-119.865ms; +106.174ms] or [-9.693%; +8.586%]

scenario:appsec-control-26

  • unstable execution_time [-127005.579µs; +125635.812µs] or [-10.250%; +10.140%]

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

  • unstable execution_time [-18.621ms; +8.445ms] or [-7.349%; +3.333%]

scenario:appsec-iast-no-vulnerability-iast-enabled-always-active-20

  • unstable execution_time [-7.740ms; +17.925ms] or [-3.045%; +7.051%]

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

  • unstable execution_time [-28531.676µs; +27579.511µs] or [-5.231%; +5.056%]

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

  • unstable cpu_user_time [-3473.218ms; +2350.494ms] or [-36.814%; +24.914%]
  • unstable execution_time [-3539.707ms; +2361.995ms] or [-34.883%; +23.277%]
  • unstable instructions [-29.7G instructions; +20.0G instructions] or [-38.316%; +25.848%]
  • unstable max_rss_usage [-14.246MB; +9.573MB] or [-8.811%; +5.921%]
  • unstable throughput [-636.814op/s; +942.369op/s] or [-18.929%; +28.011%]

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

  • unstable cpu_user_time [-2301.498ms; +721.879ms] or [-24.100%; +7.559%]
  • unstable execution_time [-2286.669ms; +769.262ms] or [-22.245%; +7.483%]
  • unstable instructions [-20.3G instructions; +6.6G instructions] or [-25.470%; +8.249%]
  • unstable throughput [-158.502op/s; +452.777op/s] or [-4.917%; +14.045%]

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

  • unstable cpu_user_time [-2288.145ms; +745.725ms] or [-24.009%; +7.825%]
  • unstable execution_time [-2313.034ms; +742.905ms] or [-22.574%; +7.250%]
  • unstable instructions [-20.4G instructions; +6.5G instructions] or [-25.657%; +8.123%]
  • unstable throughput [-146.503op/s; +457.426op/s] or [-4.528%; +14.137%]

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

  • unstable cpu_user_time [-2277.455ms; +740.888ms] or [-23.930%; +7.785%]
  • unstable execution_time [-2293.234ms; +752.121ms] or [-22.366%; +7.335%]
  • unstable instructions [-20.3G instructions; +6.6G instructions] or [-25.567%; +8.239%]
  • unstable throughput [-152.988op/s; +455.417op/s] or [-4.733%; +14.089%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-272.141ms; +278.343ms] or [-5.421%; +5.545%]
  • unstable execution_time [-270.062ms; +278.157ms] or [-5.299%; +5.458%]
  • unstable throughput [-98455.528op/s; +93578.620op/s] or [-5.996%; +5.699%]

scenario:plugin-claude-agent-sdk-compact-hook-indexed-26

  • unstable cpu_usage_percentage [-7.322%; +4.870%]
  • unstable execution_time [-3.146ms; +5.749ms] or [-3.715%; +6.788%]

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

  • unstable max_rss_usage [-26.071MB; +38.438MB] or [-6.943%; +10.236%]

scenario:plugin-pg-service-26

  • unstable cpu_user_time [-32.128ms; +58.522ms] or [-3.622%; +6.597%]
  • unstable execution_time [-32.138ms; +60.296ms] or [-3.603%; +6.760%]

scenario:test-optimization-large-suite-20

  • unstable max_rss_usage [-6361.718KB; +4898.718KB] or [-7.778%; +5.989%]

Comment thread packages/dd-trace/src/config/helper.js
@tlhunter
tlhunter marked this pull request as ready for review June 11, 2026 17:01
@tlhunter
tlhunter requested a review from a team as a code owner June 11, 2026 17:01
@tlhunter
tlhunter requested review from BridgeAR and removed request for a team June 11, 2026 17:01

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 41e1117416

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/dd-trace/src/config/index.js Outdated
@tlhunter

Copy link
Copy Markdown
Member Author

The codecov check is buggy. It passes and fails between different runs even when code hasn't changed.

@tlhunter tlhunter changed the title fix(config): apply DD_*/OTEL_* vars from pm2_env blob before tracer init fix(config): extract relevant env vars from pm2_env JSON before tracer init Jun 11, 2026
@tlhunter
tlhunter marked this pull request as draft June 11, 2026 17:24
@tlhunter
tlhunter marked this pull request as ready for review June 11, 2026 18:20

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 83370aa0cf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/dd-trace/src/config/helper.js Outdated
Comment thread packages/dd-trace/src/config/helper.js Outdated

@BridgeAR BridgeAR left a comment

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.

This will likely fix the overall problem for most users, while our guardrails will not know about DD_INJECT_FORCE and DD_INJECTION_ENABLED.

I am unsure if that is an issue. Next to that: we currently also access process.env using webpack, esbuild, and cypress and I guess they could also be called, while unlikely?

Comment thread packages/dd-trace/src/config/helper.js Outdated
Comment thread packages/dd-trace/src/config/helper.js Outdated
/**
* In PM2 cluster mode, per-app env vars (DD_SERVICE, DD_ENV, etc.) are not
* passed as individual environment variables. Instead PM2 serializes the entire
* process config into a single `pm2_env` JSON string and passes only that to

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 potentially open a PR against PM2 to stop this and instead just sets the envs when starting the child accordingly?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Comment thread packages/dd-trace/src/config/helper.js Outdated
@tlhunter

Copy link
Copy Markdown
Member Author

I'm converting this into a draft while we wait on PM2 to reply to the PR.

@tlhunter
tlhunter marked this pull request as draft June 24, 2026 17:44

@BridgeAR BridgeAR left a comment

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.

Looking at this again: I believe we have to land something like it because the upstream fix will likely take long.

To fix it, I think we should expand the envs inside of init.js before the guardrails and just unconditially accept the values and override any other ones.

@tlhunter
tlhunter force-pushed the tlhunter/apms-19774-pm2-cluster-env branch from 83370aa to 4107ce2 Compare July 14, 2026 22:16
@tlhunter
tlhunter marked this pull request as ready for review July 15, 2026 18:22
@tlhunter
tlhunter requested a review from a team as a code owner July 15, 2026 18:22
Comment thread init.js Outdated
Comment thread packages/dd-trace/src/config/helper.js Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 95a38a180a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/dd-trace/src/config/helper.js Outdated
Comment thread packages/dd-trace/src/config/helper.js Outdated
BridgeAR
BridgeAR previously approved these changes Jul 16, 2026
Comment thread init.js
if (typeof pm2EnvStr === 'string') {
try {
var pm2Config = JSON.parse(pm2EnvStr)
var pm2Keys = Object.keys(pm2Config)

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.

It would be nicer to ignore the Object.keys warning locally instead of globally, while it likely does not matter much

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If the linter complains that Object.keys() doesn't exist in Node.js v0.8.0, but it actually does (I confirmed on v0.8.6), then wouldn't it be more correct to globally configure the linter to always allow Object.keys() everywhere (specifically when evaluating from a v0.8.0 perspective) instead of in a single location?

Adding a single eslint ignore line feel wrong since it's superfluous at best and at worst masks (admittedly unlikely) issues where Object.keys() becomes deprecated in the future.

Comment thread packages/dd-trace/src/config/helper.js Outdated
@tlhunter
tlhunter force-pushed the tlhunter/apms-19774-pm2-cluster-env branch from fac5c7d to d926665 Compare July 16, 2026 18:52
Comment thread eslint.config.mjs Outdated
},
},
{
name: 'dd-trace/defaults/v0.8-oldest/init',

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.

That... is not what I had in mind 😅

I meant a local eslint disable next line comment to deactivate a single rule.

@tlhunter
tlhunter marked this pull request as draft July 17, 2026 16:59
@tlhunter
tlhunter force-pushed the tlhunter/apms-19774-pm2-cluster-env branch 2 times, most recently from 1ec3cd9 to 653441a Compare July 17, 2026 17:20
Comment thread init.js
process.env[k] = String(v)
}
}
} catch (e) {}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Should this log an error? It's so early in the bootstrapping process that I don't think we can do so cleanly.

I could cache the error and then log it later once the logger is ready. There is some precedent for that.

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.

I think it is fine as a best effort approach here. Throwing would be very confusing anyway (none of the operations should be possible to throw)

@tlhunter
tlhunter force-pushed the tlhunter/apms-19774-pm2-cluster-env branch from 653441a to 74f2de8 Compare July 17, 2026 23:18
@tlhunter
tlhunter marked this pull request as ready for review July 17, 2026 23:45
@tlhunter
tlhunter enabled auto-merge (squash) July 17, 2026 23:45

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 74f2de857b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread init.js
var k = pm2Keys[i]
var v = pm2Config[k]
if (v != null) {
process.env[k] = String(v)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle PM2 file configs relative to the app cwd

When pm2_env contains a relative file-backed config such as DD_SPAN_SAMPLING_RULES_FILE or the AppSec blocked-template paths and pm2_env.pm_cwd differs from the PM2 daemon cwd, this assignment makes dd-trace consume the value during require('.').init() before PM2's wrapper later runs process.chdir(pm2_env.pm_cwd || ...) (PM2 ProcessContainer). The config readFilePath transformer reads fs.readFileSync(raw) relative to the current cwd, so the tracer drops or misreads a valid per-app PM2 config that would work once PM2 starts the app.

Useful? React with 👍 / 👎.

Comment thread init.js
var k = pm2Keys[i]
var v = pm2Config[k]
if (v != null) {
process.env[k] = String(v)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve the PM2 app before the clobber guard

When SSI puts DD_INJECTION_ENABLED in the PM2 app env and that app also has its own dd-trace, copying the PM2 blob here makes the guardrails run the app-dir clobber check immediately, but at this point process.argv[1] is still PM2's wrapper while the real script is only in pm2Config.pm_exec_path. The guard in packages/dd-trace/src/guardrails/index.js resolves dd-trace from process.argv[1], so PM2 cluster workers won't detect the app-local tracer and will initialize the injected tracer anyway.

Useful? React with 👍 / 👎.

@BridgeAR BridgeAR left a comment

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.

No matter that the AI is complaining: this is improving our current status quo a lot, so we should include this as is in my opinion. Thank you for the fix!

@tlhunter
tlhunter merged commit 86366de into master Jul 21, 2026
657 checks passed
@tlhunter
tlhunter deleted the tlhunter/apms-19774-pm2-cluster-env branch July 21, 2026 22:10
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Jul 21, 2026
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