Skip to content

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

Draft
tlhunter wants to merge 6 commits into
masterfrom
tlhunter/apms-19774-pm2-cluster-env
Draft

fix(config): extract relevant env vars from pm2_env JSON before tracer init#8863
tlhunter wants to merge 6 commits 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.

In PM2 cluster mode, per-app env vars are serialized into a single
`pm2_env` JSON string via `cluster.fork()`. PM2's ProcessContainer.js
unpacks them into process.env, but only after NODE_OPTIONS `--require`
preloads have already run — so dd-trace initialized with DD_SERVICE
undefined and fell back to "node".

`applyPm2ClusterEnv()` is called once at the top of `getConfig()` before
`new Config()` reads process.env. It parses the pm2_env blob and copies
any DD_*/OTEL_* keys that are not already set, so host-level overrides
still take precedence.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dd-octo-sts

dd-octo-sts Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 6.2 MB
Deduped: 7.24 MB
No deduping: 7.24 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.2 | 85.93 kB | 825.11 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 92.73%. Comparing base (3df1dc2) to head (83370aa).
⚠️ Report is 28 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8863      +/-   ##
==========================================
- Coverage   93.30%   92.73%   -0.57%     
==========================================
  Files         861      862       +1     
  Lines       49475    49636     +161     
  Branches     9359     9406      +47     
==========================================
- Hits        46162    46031     -131     
- Misses       3313     3605     +292     
Flag Coverage Δ
aiguard-integration-active 41.38% <33.33%> (+0.13%) ⬆️
aiguard-integration-latest 41.39% <33.33%> (-0.01%) ⬇️
aiguard-integration-maintenance 41.47% <33.33%> (-0.01%) ⬇️
aiguard-macos 33.29% <33.33%> (-0.11%) ⬇️
aiguard-ubuntu 33.45% <33.33%> (-0.12%) ⬇️
aiguard-windows 33.11% <33.33%> (-0.11%) ⬇️
apm-capabilities-tracing-macos 48.40% <100.00%> (-0.04%) ⬇️
apm-capabilities-tracing-ubuntu-active 48.58% <100.00%> (+0.14%) ⬆️
apm-capabilities-tracing-ubuntu-latest 48.39% <100.00%> (-0.05%) ⬇️
apm-capabilities-tracing-ubuntu-maintenance 48.63% <100.00%> (-0.04%) ⬇️
apm-capabilities-tracing-ubuntu-oldest 48.64% <100.00%> (+0.14%) ⬆️
apm-capabilities-tracing-windows 48.36% <100.00%> (-0.05%) ⬇️
apm-integrations-aerospike-18-gte.5.2.0 33.02% <33.33%> (-0.14%) ⬇️
apm-integrations-aerospike-20-gte.5.5.0 33.04% <33.33%> (-0.14%) ⬇️
apm-integrations-aerospike-22-gte.5.12.1 33.05% <33.33%> (-0.14%) ⬇️
apm-integrations-aerospike-22-gte.6.0.0 33.05% <33.33%> (-0.14%) ⬇️
apm-integrations-aerospike-eol- 32.95% <33.33%> (-0.14%) ⬇️
apm-integrations-child-process 33.96% <33.33%> (-0.14%) ⬇️
apm-integrations-confluentinc-kafka-javascript-18 40.05% <33.33%> (-0.16%) ⬇️
apm-integrations-confluentinc-kafka-javascript-20 40.07% <33.33%> (-0.16%) ⬇️
apm-integrations-confluentinc-kafka-javascript-22 40.07% <33.33%> (-0.16%) ⬇️
apm-integrations-confluentinc-kafka-javascript-24 39.96% <33.33%> (-0.16%) ⬇️
apm-integrations-couchbase-18 33.04% <33.33%> (-0.30%) ⬇️
apm-integrations-couchbase-eol 33.08% <33.33%> (-0.14%) ⬇️
apm-integrations-dns 32.96% <33.33%> (-0.14%) ⬇️
apm-integrations-elasticsearch 33.99% <33.33%> (-0.13%) ⬇️
apm-integrations-http-latest 41.22% <33.33%> (-0.14%) ⬇️
apm-integrations-http-maintenance 41.31% <33.33%> (-0.14%) ⬇️
apm-integrations-http-oldest 41.25% <33.33%> (-0.12%) ⬇️
apm-integrations-http2 38.51% <33.33%> (+0.01%) ⬆️
apm-integrations-kafkajs-latest 40.06% <33.33%> (-0.16%) ⬇️
apm-integrations-kafkajs-oldest ?
apm-integrations-net 33.66% <33.33%> (-0.14%) ⬇️
apm-integrations-next-11.1.4 36.55% <33.33%> (+0.18%) ⬆️
apm-integrations-next-12.3.7 36.55% <33.33%> (+0.18%) ⬆️
apm-integrations-next-13.0.0 28.99% <33.33%> (-0.12%) ⬇️
apm-integrations-next-13.2.0 29.00% <33.33%> (-0.11%) ⬇️
apm-integrations-next-13.5.11 29.17% <33.33%> (-0.12%) ⬇️
apm-integrations-next-14.0.0 29.06% <33.33%> (-0.16%) ⬇️
apm-integrations-next-14.2.35 29.06% <33.33%> (-0.12%) ⬇️
apm-integrations-next-14.2.6 29.06% <33.33%> (-0.12%) ⬇️
apm-integrations-next-14.2.7 29.06% <33.33%> (-0.12%) ⬇️
apm-integrations-next-15.0.0 29.06% <33.33%> (-0.12%) ⬇️
apm-integrations-next-15.4.0 29.13% <33.33%> (-0.12%) ⬇️
apm-integrations-next-latest 29.13% <33.33%> (-0.12%) ⬇️
apm-integrations-oracledb 33.88% <33.33%> (-0.13%) ⬇️
apm-integrations-prisma-18-gte.6.16.0.and.lt.7.0.0 34.38% <33.33%> (-0.14%) ⬇️
apm-integrations-prisma-latest-all 34.16% <33.33%> (-0.13%) ⬇️
apm-integrations-restify 35.07% <33.33%> (-0.14%) ⬇️
apm-integrations-sharedb 32.37% <33.33%> (-0.13%) ⬇️
apm-integrations-tedious 33.29% <33.33%> (-0.13%) ⬇️
appsec-express 51.12% <33.33%> (-0.15%) ⬇️
appsec-fastify ?
appsec-graphql 47.86% <33.33%> (-0.13%) ⬇️
appsec-integration-active 35.91% <33.33%> (-0.08%) ⬇️
appsec-integration-latest 35.91% <33.33%> (-0.08%) ⬇️
appsec-integration-maintenance 35.97% <33.33%> (-0.08%) ⬇️
appsec-integration-oldest 35.97% <33.33%> (-0.08%) ⬇️
appsec-kafka 40.32% <33.33%> (-0.14%) ⬇️
appsec-ldapjs 39.74% <33.33%> (-0.12%) ⬇️
appsec-lodash 39.77% <33.33%> (-0.12%) ⬇️
appsec-macos 57.04% <33.33%> (-0.25%) ⬇️
appsec-mongodb-core 43.97% <33.33%> (-0.13%) ⬇️
appsec-mongoose 44.81% <33.33%> (-0.13%) ⬇️
appsec-mysql 47.09% <33.33%> (-0.10%) ⬇️
appsec-next-latest-11.1.4 27.26% <33.33%> (-0.14%) ⬇️
appsec-next-latest-12.3.7 27.60% <33.33%> (+0.08%) ⬆️
appsec-next-latest-13.0.0 29.07% <33.33%> (-0.12%) ⬇️
appsec-next-latest-13.2.0 29.09% <33.33%> (-0.12%) ⬇️
appsec-next-latest-13.5.11 29.19% <33.33%> (-0.12%) ⬇️
appsec-next-latest-14.0.0 29.11% <33.33%> (-0.12%) ⬇️
appsec-next-latest-14.2.35 29.11% <33.33%> (-0.12%) ⬇️
appsec-next-latest-14.2.6 29.11% <33.33%> (-0.12%) ⬇️
appsec-next-latest-14.2.7 29.11% <33.33%> (-0.12%) ⬇️
appsec-next-latest-15.0.0 29.13% <33.33%> (-0.11%) ⬇️
appsec-next-latest-latest 29.12% <33.33%> (-0.12%) ⬇️
appsec-next-oldest-11.1.4 27.32% <33.33%> (-0.14%) ⬇️
appsec-next-oldest-12.3.7 29.13% <33.33%> (-0.12%) ⬇️
appsec-next-oldest-13.0.0 29.13% <33.33%> (-0.12%) ⬇️
appsec-next-oldest-13.2.0 29.39% <33.33%> (-0.12%) ⬇️
appsec-next-oldest-13.5.11 29.49% <33.33%> (-0.12%) ⬇️
appsec-next-oldest-14.0.0 ?
appsec-next-oldest-14.2.35 29.43% <33.33%> (-0.12%) ⬇️
appsec-next-oldest-14.2.6 29.43% <33.33%> (-0.12%) ⬇️
appsec-next-oldest-14.2.7 29.43% <33.33%> (-0.12%) ⬇️
appsec-next-oldest-15.0.0 ?
appsec-next-oldest-latest 27.81% <33.33%> (+0.07%) ⬆️
appsec-node-serialize 39.07% <33.33%> (-0.11%) ⬇️
appsec-passport 42.64% <33.33%> (-0.15%) ⬇️
appsec-postgres 46.81% <33.33%> (-0.14%) ⬇️
appsec-sourcing ?
appsec-stripe 40.41% <33.33%> (-0.14%) ⬇️
appsec-template 39.31% <33.33%> (-0.12%) ⬇️
appsec-ubuntu 57.16% <33.33%> (-0.17%) ⬇️
appsec-windows ?
debugger-ubuntu-active ?
debugger-ubuntu-latest ?
debugger-ubuntu-maintenance 43.96% <33.33%> (+0.20%) ⬆️
debugger-ubuntu-oldest 43.97% <33.33%> (+0.20%) ⬆️
instrumentations-instrumentation-ai 42.43% <33.33%> (+0.12%) ⬆️
instrumentations-instrumentation-aws-sdk 44.58% <33.33%> (+0.12%) ⬆️
instrumentations-instrumentation-bluebird 27.41% <33.33%> (-0.12%) ⬇️
instrumentations-instrumentation-body-parser 35.58% <33.33%> (-0.14%) ⬇️
instrumentations-instrumentation-child_process 33.34% <33.33%> (-0.14%) ⬇️
instrumentations-instrumentation-cookie-parser 29.31% <33.33%> (-0.12%) ⬇️
instrumentations-instrumentation-couchbase-18 45.69% <33.33%> (+0.11%) ⬆️
instrumentations-instrumentation-couchbase-eol 45.69% <33.33%> (+0.11%) ⬆️
instrumentations-instrumentation-crypto 27.46% <33.33%> (-0.12%) ⬇️
instrumentations-instrumentation-express 29.52% <33.33%> (-0.12%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize 29.42% <33.33%> (-0.12%) ⬇️
instrumentations-instrumentation-express-multi-version 41.48% <33.33%> (+0.17%) ⬆️
instrumentations-instrumentation-express-session 35.35% <33.33%> (-0.14%) ⬇️
instrumentations-instrumentation-fastify 47.56% <33.33%> (+0.09%) ⬆️
instrumentations-instrumentation-fetch 44.75% <33.33%> (+0.14%) ⬆️
instrumentations-instrumentation-fs 27.11% <33.33%> (-0.12%) ⬇️
instrumentations-instrumentation-generic-pool 26.96% <33.33%> (+0.03%) ⬆️
instrumentations-instrumentation-hono 28.63% <33.33%> (-0.12%) ⬇️
instrumentations-instrumentation-http 35.01% <33.33%> (-0.14%) ⬇️
instrumentations-instrumentation-http-client-options 37.53% <33.33%> (-0.15%) ⬇️
instrumentations-instrumentation-kafkajs 48.65% <33.33%> (+0.07%) ⬆️
instrumentations-instrumentation-knex 27.40% <33.33%> (-0.12%) ⬇️
instrumentations-instrumentation-light-my-request 35.21% <33.33%> (-0.14%) ⬇️
instrumentations-instrumentation-mongoose 28.51% <33.33%> (-0.12%) ⬇️
instrumentations-instrumentation-multer 35.25% <33.33%> (-0.14%) ⬇️
instrumentations-instrumentation-mysql2 33.37% <33.33%> (-0.07%) ⬇️
instrumentations-instrumentation-openai-aiguard 47.58% <33.33%> (+0.27%) ⬆️
instrumentations-instrumentation-otel-sdk-trace 25.21% <33.33%> (+0.04%) ⬆️
instrumentations-instrumentation-passport 39.13% <33.33%> (-0.13%) ⬇️
instrumentations-instrumentation-passport-http 38.82% <33.33%> (-0.13%) ⬇️
instrumentations-instrumentation-passport-local 39.28% <33.33%> (-0.13%) ⬇️
instrumentations-instrumentation-pg 33.09% <33.33%> (-0.14%) ⬇️
instrumentations-instrumentation-promise 27.36% <33.33%> (-0.12%) ⬇️
instrumentations-instrumentation-promise-js 27.36% <33.33%> (-0.12%) ⬇️
instrumentations-instrumentation-q 27.39% <33.33%> (-0.12%) ⬇️
instrumentations-instrumentation-router 42.81% <33.33%> (+0.11%) ⬆️
instrumentations-instrumentation-stripe 27.89% <33.33%> (-0.12%) ⬇️
instrumentations-instrumentation-url 27.29% <33.33%> (-0.12%) ⬇️
instrumentations-instrumentation-when 27.37% <33.33%> (-0.12%) ⬇️
instrumentations-instrumentation-zlib 27.34% <33.33%> (-0.12%) ⬇️
instrumentations-integration-esbuild-0.16.12-active 18.33% <33.33%> (-0.01%) ⬇️
instrumentations-integration-esbuild-0.16.12-latest 18.33% <33.33%> (-0.01%) ⬇️
instrumentations-integration-esbuild-0.16.12-maintenance 18.36% <33.33%> (-0.01%) ⬇️
instrumentations-integration-esbuild-0.16.12-oldest 18.35% <33.33%> (-0.01%) ⬇️
instrumentations-integration-esbuild-latest-active 18.33% <33.33%> (-0.01%) ⬇️
instrumentations-integration-esbuild-latest-latest 18.33% <33.33%> (-0.01%) ⬇️
instrumentations-integration-esbuild-latest-maintenance 18.36% <33.33%> (-0.01%) ⬇️
instrumentations-integration-esbuild-latest-oldest ?
llmobs-ai 34.76% <33.33%> (-0.12%) ⬇️
llmobs-anthropic 36.48% <33.33%> (-0.14%) ⬇️
llmobs-bedrock 36.03% <33.33%> (-0.02%) ⬇️
llmobs-google-genai 35.76% <33.33%> (+0.09%) ⬆️
llmobs-langchain ?
llmobs-openai-latest 38.90% <33.33%> (-0.14%) ⬇️
llmobs-openai-oldest 38.98% <33.33%> (-0.14%) ⬇️
llmobs-sdk-active 43.47% <33.33%> (+0.06%) ⬆️
llmobs-sdk-latest 43.47% <33.33%> (+0.06%) ⬆️
llmobs-sdk-maintenance 43.58% <33.33%> (+0.06%) ⬆️
llmobs-sdk-oldest 43.56% <33.33%> (+0.06%) ⬆️
llmobs-vertex-ai 35.53% <33.33%> (-0.14%) ⬇️
master-coverage 92.73% <100.00%> (?)
openfeature-macos 37.35% <33.33%> (-0.12%) ⬇️
openfeature-ubuntu 37.54% <33.33%> (-0.07%) ⬇️
openfeature-unit-active 49.91% <33.33%> (-0.13%) ⬇️
openfeature-unit-latest 49.91% <33.33%> (-0.13%) ⬇️
openfeature-unit-maintenance 50.28% <33.33%> (-0.13%) ⬇️
openfeature-unit-oldest 50.28% <33.33%> (-0.13%) ⬇️
openfeature-windows 37.28% <33.33%> (-0.07%) ⬇️
platform-core 45.97% <33.33%> (+0.13%) ⬆️
platform-esbuild 46.60% <33.33%> (+0.12%) ⬆️
platform-instrumentations-misc 30.46% <33.33%> (-0.05%) ⬇️
platform-integration-active ?
platform-integration-latest 46.56% <33.33%> (-0.16%) ⬇️
platform-integration-maintenance 46.72% <33.33%> (-0.10%) ⬇️
platform-integration-oldest 46.87% <33.33%> (-0.10%) ⬇️
platform-shimmer 47.03% <33.33%> (+0.10%) ⬆️
platform-unit-guardrails 44.03% <33.33%> (+0.14%) ⬆️
platform-webpack 17.89% <33.33%> (+<0.01%) ⬆️
plugins-axios 35.33% <33.33%> (-0.07%) ⬇️
plugins-azure-cosmos 35.81% <33.33%> (-0.14%) ⬇️
plugins-azure-event-hubs 34.66% <33.33%> (-0.07%) ⬇️
plugins-azure-service-bus 35.14% <33.33%> (-0.07%) ⬇️
plugins-body-parser 36.33% <33.33%> (-0.07%) ⬇️
plugins-bullmq 38.83% <33.33%> (-0.16%) ⬇️
plugins-cassandra 33.50% <33.33%> (-0.29%) ⬇️
plugins-cookie 40.30% <33.33%> (+0.16%) ⬆️
plugins-cookie-parser 40.13% <33.33%> (+0.16%) ⬆️
plugins-crypto 42.36% <33.33%> (+0.16%) ⬆️
plugins-dd-trace-api 33.19% <33.33%> (-0.14%) ⬇️
plugins-express-mongo-sanitize 40.19% <33.33%> (+0.16%) ⬆️
plugins-express-session 40.05% <33.33%> (+0.16%) ⬆️
plugins-fastify 37.66% <33.33%> (-0.14%) ⬇️
plugins-fetch 33.93% <33.33%> (-0.13%) ⬇️
plugins-fs 33.58% <33.33%> (-0.14%) ⬇️
plugins-generic-pool 39.62% <33.33%> (+0.17%) ⬆️
plugins-google-cloud-pubsub 41.34% <33.33%> (-0.15%) ⬇️
plugins-grpc 36.42% <33.33%> (-0.14%) ⬇️
plugins-handlebars 40.19% <33.33%> (+0.16%) ⬆️
plugins-hapi 35.48% <33.33%> (-0.14%) ⬇️
plugins-hono 35.82% <33.33%> (-0.14%) ⬇️
plugins-ioredis 34.05% <33.33%> (-0.14%) ⬇️
plugins-jest 27.13% <33.33%> (+0.06%) ⬆️
plugins-knex 39.67% <33.33%> (+0.16%) ⬆️
plugins-langgraph 32.22% <33.33%> (-0.13%) ⬇️
plugins-ldapjs 38.64% <33.33%> (+0.17%) ⬆️
plugins-light-my-request 39.76% <33.33%> (+0.16%) ⬆️
plugins-limitd-client 27.78% <33.33%> (-0.06%) ⬇️
plugins-lodash 39.80% <33.33%> (+0.17%) ⬆️
plugins-mariadb 35.02% <33.33%> (-0.14%) ⬇️
plugins-memcached 33.57% <33.33%> (-0.14%) ⬇️
plugins-microgateway-core 34.58% <33.33%> (-0.14%) ⬇️
plugins-modelcontextprotocol-sdk 32.17% <33.33%> (-0.13%) ⬇️
plugins-moleculer 36.48% <33.33%> (-0.14%) ⬇️
plugins-mongodb 35.73% <33.33%> (-0.04%) ⬇️
plugins-mongodb-core 35.31% <33.33%> (-0.14%) ⬇️
plugins-mongoose 34.20% <33.33%> (-0.13%) ⬇️
plugins-multer 40.11% <33.33%> (+0.16%) ⬆️
plugins-mysql 34.49% <33.33%> (+<0.01%) ⬆️
plugins-mysql2 34.83% <33.33%> (-0.08%) ⬇️
plugins-nats 36.22% <33.33%> (-0.15%) ⬇️
plugins-node-serialize 40.33% <33.33%> (+0.16%) ⬆️
plugins-opensearch 33.44% <33.33%> (-0.13%) ⬇️
plugins-passport-http 39.93% <33.33%> (+0.16%) ⬆️
plugins-pino 29.66% <33.33%> (-0.11%) ⬇️
plugins-postgres 34.54% <33.33%> (-0.14%) ⬇️
plugins-process 42.36% <33.33%> (+0.16%) ⬆️
plugins-pug 40.30% <33.33%> (+0.16%) ⬆️
plugins-redis 34.16% <33.33%> (-0.08%) ⬇️
plugins-router 38.06% <33.33%> (-0.15%) ⬇️
plugins-sequelize 39.58% <33.33%> (+0.17%) ⬆️
plugins-test-and-upstream-amqp10 33.71% <33.33%> (-0.14%) ⬇️
plugins-test-and-upstream-amqplib 39.08% <33.33%> (+0.01%) ⬆️
plugins-test-and-upstream-apollo 34.67% <33.33%> (-0.13%) ⬇️
plugins-test-and-upstream-avsc 33.59% <33.33%> (-0.14%) ⬇️
plugins-test-and-upstream-bunyan 28.87% <33.33%> (-0.11%) ⬇️
plugins-test-and-upstream-connect 36.16% <33.33%> (-0.14%) ⬇️
plugins-test-and-upstream-graphql 35.91% <33.33%> (-0.12%) ⬇️
plugins-test-and-upstream-koa 35.66% <33.33%> (-0.14%) ⬇️
plugins-test-and-upstream-protobufjs 33.82% <33.33%> (-0.14%) ⬇️
plugins-test-and-upstream-rhea 39.04% <33.33%> (-0.16%) ⬇️
plugins-undici 34.43% <33.33%> (-0.13%) ⬇️
plugins-url 42.36% <33.33%> (+0.16%) ⬆️
plugins-valkey 33.66% <33.33%> (-0.15%) ⬇️
plugins-vm 42.36% <33.33%> (+0.16%) ⬆️
plugins-winston 29.52% <33.33%> (-0.10%) ⬇️
plugins-ws 36.96% <33.33%> (-0.15%) ⬇️
profiling-macos 43.02% <33.33%> (-0.15%) ⬇️
profiling-ubuntu 43.46% <33.33%> (-0.15%) ⬇️
profiling-windows 40.79% <33.33%> (-0.15%) ⬇️
serverless-aws-sdk-latest-aws-sdk 32.96% <33.33%> (-0.12%) ⬇️
serverless-aws-sdk-latest-bedrockruntime 31.64% <33.33%> (-0.11%) ⬇️
serverless-aws-sdk-latest-client 36.05% <33.33%> (+0.18%) ⬆️
serverless-aws-sdk-latest-dynamodb ?
serverless-aws-sdk-latest-eventbridge 26.80% <33.33%> (-0.10%) ⬇️
serverless-aws-sdk-latest-kinesis 36.92% <33.33%> (-0.13%) ⬇️
serverless-aws-sdk-latest-lambda 34.30% <33.33%> (-0.12%) ⬇️
serverless-aws-sdk-latest-s3 32.20% <33.33%> (-0.11%) ⬇️
serverless-aws-sdk-latest-serverless-peer-service 39.19% <33.33%> (-0.16%) ⬇️
serverless-aws-sdk-latest-sns 38.11% <33.33%> (-0.14%) ⬇️
serverless-aws-sdk-latest-sqs 37.65% <33.33%> (-0.13%) ⬇️
serverless-aws-sdk-latest-stepfunctions 32.87% <33.33%> (-0.12%) ⬇️
serverless-aws-sdk-latest-util 46.36% <33.33%> (+0.12%) ⬆️
serverless-aws-sdk-oldest-aws-sdk 33.07% <33.33%> (-0.11%) ⬇️
serverless-aws-sdk-oldest-bedrockruntime 31.94% <33.33%> (-0.11%) ⬇️
serverless-aws-sdk-oldest-client 36.62% <33.33%> (+0.18%) ⬆️
serverless-aws-sdk-oldest-dynamodb 33.93% <33.33%> (-0.07%) ⬇️
serverless-aws-sdk-oldest-eventbridge 26.88% <33.33%> (-0.10%) ⬇️
serverless-aws-sdk-oldest-kinesis 37.10% <33.33%> (-0.13%) ⬇️
serverless-aws-sdk-oldest-lambda 34.40% <33.33%> (-0.12%) ⬇️
serverless-aws-sdk-oldest-s3 32.34% <33.33%> (-0.12%) ⬇️
serverless-aws-sdk-oldest-serverless-peer-service 39.28% <33.33%> (-0.16%) ⬇️
serverless-aws-sdk-oldest-sns ?
serverless-aws-sdk-oldest-sqs 37.53% <33.33%> (-0.13%) ⬇️
serverless-aws-sdk-oldest-stepfunctions 32.97% <33.33%> (-0.12%) ⬇️
serverless-aws-sdk-oldest-util 47.11% <33.33%> (+0.11%) ⬆️
serverless-azure-durable-functions 36.61% <33.33%> (-0.07%) ⬇️
serverless-azure-functions-eventhubs 38.25% <33.33%> (-0.08%) ⬇️
serverless-azure-functions-servicebus 38.31% <33.33%> (-0.08%) ⬇️
serverless-lambda 34.24% <33.33%> (-0.27%) ⬇️
test-optimization-cucumber-latest-7.0.0 49.97% <33.33%> (-0.08%) ⬇️
test-optimization-cucumber-latest-latest 52.72% <33.33%> (+0.09%) ⬆️
test-optimization-cucumber-oldest-7.0.0 50.05% <33.33%> (+0.03%) ⬆️
test-optimization-cypress-latest-12.0.0-commonJS 49.32% <33.33%> (-0.01%) ⬇️
test-optimization-cypress-latest-12.0.0-esm 49.21% <33.33%> (-0.15%) ⬇️
test-optimization-cypress-latest-14.5.4-commonJS 48.41% <33.33%> (-0.77%) ⬇️
test-optimization-cypress-latest-14.5.4-esm 48.44% <33.33%> (-0.77%) ⬇️
test-optimization-cypress-latest-latest-commonJS 49.15% <33.33%> (-0.52%) ⬇️
test-optimization-cypress-latest-latest-esm 49.69% <33.33%> (-0.02%) ⬇️
test-optimization-cypress-oldest-12.0.0-commonJS 49.41% <33.33%> (-0.02%) ⬇️
test-optimization-cypress-oldest-12.0.0-esm 49.44% <33.33%> (-0.02%) ⬇️
test-optimization-cypress-oldest-14.5.4-commonJS 48.86% <33.33%> (-0.41%) ⬇️
test-optimization-cypress-oldest-14.5.4-esm 49.28% <33.33%> (-0.01%) ⬇️
test-optimization-jest-latest-latest 52.95% <33.33%> (-2.36%) ⬇️
test-optimization-jest-latest-oldest 54.34% <33.33%> (+0.08%) ⬆️
test-optimization-jest-oldest-latest 55.47% <33.33%> (+0.11%) ⬆️
test-optimization-jest-oldest-oldest 54.35% <33.33%> (+0.11%) ⬆️
test-optimization-mocha-latest-latest 53.66% <33.33%> (+<0.01%) ⬆️
test-optimization-mocha-latest-oldest 51.21% <33.33%> (+<0.01%) ⬆️
test-optimization-mocha-oldest-latest 53.77% <33.33%> (-0.02%) ⬇️
test-optimization-mocha-oldest-oldest ?
test-optimization-playwright-latest-latest-playwright-active-test-span 44.26% <33.33%> (+0.23%) ⬆️
test-optimization-playwright-latest-latest-playwright-atr 42.88% <33.33%> (+0.04%) ⬆️
test-optimization-playwright-latest-latest-playwright-efd 43.33% <33.33%> (+0.05%) ⬆️
test-optimization-playwright-latest-latest-playwright-final-status 43.40% <33.33%> (+0.07%) ⬆️
test-optimization-playwright-latest-latest-playwright-impacted-tests 42.86% <33.33%> (-0.06%) ⬇️
test-optimization-playwright-latest-latest-playwright-reporting 42.92% <33.33%> (+0.05%) ⬆️
test-optimization-playwright-latest-latest-playwright-test-management 44.53% <33.33%> (+0.03%) ⬆️
test-optimization-playwright-latest-oldest-playwright-active-test-span 44.08% <33.33%> (+0.21%) ⬆️
test-optimization-playwright-latest-oldest-playwright-atr 42.96% <33.33%> (+0.05%) ⬆️
test-optimization-playwright-latest-oldest-playwright-efd 43.24% <33.33%> (+<0.01%) ⬆️
test-optimization-playwright-latest-oldest-playwright-final-status 43.30% <33.33%> (+0.04%) ⬆️
test-optimization-playwright-latest-oldest-playwright-impacted-tests 42.78% <33.33%> (-0.06%) ⬇️
test-optimization-playwright-latest-oldest-playwright-reporting 42.74% <33.33%> (+0.05%) ⬆️
test-optimization-playwright-latest-oldest-playwright-test-management 44.48% <33.33%> (+0.03%) ⬆️
test-optimization-playwright-oldest-latest-playwright-active-test-span 44.34% <33.33%> (+0.02%) ⬆️
test-optimization-playwright-oldest-latest-playwright-atr 42.96% <33.33%> (+0.03%) ⬆️
test-optimization-playwright-oldest-latest-playwright-efd 43.39% <33.33%> (+0.02%) ⬆️
test-optimization-playwright-oldest-latest-playwright-final-status 43.48% <33.33%> (+0.02%) ⬆️
test-optimization-playwright-oldest-latest-playwright-impacted-tests ?
test-optimization-playwright-oldest-latest-playwright-reporting ?
test-optimization-playwright-oldest-latest-playwright-test-management 44.59% <33.33%> (+<0.01%) ⬆️
test-optimization-playwright-oldest-oldest-playwright-active-test-span 44.16% <33.33%> (+0.21%) ⬆️
test-optimization-playwright-oldest-oldest-playwright-atr ?
test-optimization-playwright-oldest-oldest-playwright-efd 43.32% <33.33%> (+0.03%) ⬆️
test-optimization-playwright-oldest-oldest-playwright-final-status 43.41% <33.33%> (+0.07%) ⬆️
test-optimization-playwright-oldest-oldest-playwright-impacted-tests 42.87% <33.33%> (-0.06%) ⬇️
test-optimization-playwright-oldest-oldest-playwright-reporting 42.80% <33.33%> (+0.03%) ⬆️
test-optimization-playwright-oldest-oldest-playwright-test-management 44.54% <33.33%> (+0.01%) ⬆️
test-optimization-selenium-latest ?
test-optimization-selenium-oldest 44.80% <33.33%> (-0.25%) ⬇️
test-optimization-testopt-active 48.32% <33.33%> (+0.07%) ⬆️
test-optimization-testopt-latest 48.32% <33.33%> (+0.07%) ⬆️
test-optimization-testopt-maintenance 48.31% <33.33%> (+0.08%) ⬆️
test-optimization-testopt-oldest 49.41% <33.33%> (+0.04%) ⬆️
test-optimization-vitest-latest 50.77% <33.33%> (+0.02%) ⬆️
test-optimization-vitest-oldest 47.98% <33.33%> (+0.24%) ⬆️

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

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 83370aa | 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-06-11 17:39:26

Comparing candidate commit 83370aa in PR branch tlhunter/apms-19774-pm2-cluster-env with baseline commit 3df1dc2 in branch master.

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

tlhunter and others added 2 commits June 11, 2026 07:40
- process.env access is only allowed in config/helper.js per the
  eslint-process-env rule; move applyPm2ClusterEnv there and re-export
- Replace assert.doesNotThrow() (banned by no-restricted-syntax) with
  direct calls per the project's test style

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…spec.js

Tests via proxyquire (in index.spec.js) don't guarantee reliable coverage
attribution for helper.js function bodies in codecov's patch check. Adding
direct-require tests in helper.spec.js ensures the new lines are always
covered by the file that owns them.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
index.js decides noop vs full proxy by reading DD_TRACE_ENABLED and
OTEL_TRACES_EXPORTER via getValueFromEnvSources() at require() time —
before getConfig() is ever invoked. In PM2 cluster mode those values sit
in the pm2_env blob, so they were invisible to that early read.

Calling applyPm2ClusterEnv() as a module-level side-effect in helper.js
guarantees that process.env is populated from the blob before index.js's
first line executes (index.js already requires helper.js as its first
import). The call in getConfig() is kept for correctness when helper.js
is loaded before pm2_env is set (e.g. tests via proxyquire).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tlhunter tlhunter marked this pull request as draft June 11, 2026 17:24
…nfig

The module-level call in helper.js fires when the module is first
required, which is earlier than getConfig() in all real code paths.
In tests, proxyquire.noPreserveCache() re-runs the module-level call
on each getConfig() invocation — and all test cases already set
pm2_env before calling getConfig() — so the explicit call inside
getConfig() adds no value.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@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".

}

for (const [key, value] of Object.entries(pm2Config)) {
if ((key.startsWith('DD_') || key.startsWith('OTEL_')) && !(key in process.env) && value != null) {

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 Honor PM2 per-app env overrides

In PM2 cluster mode the worker later unpacks pm2_env by assigning its keys into process.env, so per-app values in the PM2 config override any inherited daemon/shell environment. With this guard, if the PM2 daemon was started with DD_SERVICE=host but the app's ecosystem config sets DD_SERVICE=app, --require dd-trace/init keeps the inherited host value and caches the tracer config before PM2 performs its normal overwrite, so traces are reported under the wrong service for that app.

Useful? React with 👍 / 👎.

@BridgeAR BridgeAR Jun 11, 2026

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 seems a legitimate issue

Suggested change
if ((key.startsWith('DD_') || key.startsWith('OTEL_')) && !(key in process.env) && value != null) {
if (key.startsWith('DD_') || key.startsWith('OTEL_') || aliasToCanonical.has(key)) {

}

for (const [key, value] of Object.entries(pm2Config)) {
if ((key.startsWith('DD_') || key.startsWith('OTEL_')) && !(key in process.env) && value != null) {

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 Copy supported env aliases from pm2_env

This only extracts DD_/OTEL_ names, but DATADOG_API_KEY is a supported alias for DD_API_KEY in supported-configurations.json. In PM2 cluster mode, users who put DATADOG_API_KEY in the app's PM2 env and preload the tracer will still get config.apiKey === undefined until PM2 unpacks the blob later, so agentless/LLMObs/log-submission paths can be disabled or drop data even though the app was configured with a valid supported key.

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.

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?

}
},

applyPm2ClusterEnv,

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.

Please do not expose the internal helper and test it with proxyquire instead. That way we prevent changing production code for tests.

/**
* 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.

}

for (const [key, value] of Object.entries(pm2Config)) {
if ((key.startsWith('DD_') || key.startsWith('OTEL_')) && !(key in process.env) && value != null) {

@BridgeAR BridgeAR Jun 11, 2026

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 seems a legitimate issue

Suggested change
if ((key.startsWith('DD_') || key.startsWith('OTEL_')) && !(key in process.env) && value != null) {
if (key.startsWith('DD_') || key.startsWith('OTEL_') || aliasToCanonical.has(key)) {

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