fix(id): drop redundant tags optional chaining in agentless exporter/encoder - #9610
Conversation
Overall package sizeSelf size: 7.77 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 |
🎉 All green!🧪 All tests passed 🔄 Datadog retried 1 test - 1 passed on retry 🎯 Code Coverage (details) 🔗 Commit SHA: 51f00d9 | Docs | Datadog PR Page | Give us feedback! |
There was a problem hiding this comment.
More details
The removed optional chaining is safe on the reviewed production paths: tracer configuration always materializes the tags object, DogStatsD always receives the generated tag array, and both CI writers pass the live tags object. Valid and empty-tag adversarial scenarios preserved metadata and metric output. No additional tests recommended: existing tests already cover the affected branches and the production-shaped inputs.
📊 Validated against 8 scenarios · Open Bits AI session
🤖 Datadog Autotest · Commit ceb03fb · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest
There was a problem hiding this comment.
Pull request overview
Removes redundant optional chaining around tags access in agentless exporters/encoders and DogStatsD, aligning the code with the invariant that tracer config initializes tags (and DogStatsD client config initializes tags as an array) before these code paths run.
Changes:
- Agentless APM exporter now reads
runtime-iddirectly fromconfig.tags['runtime-id']and updates the JSDoc contract forconfig.tags. - Agentless CI Visibility encoder reads
envandruntime-iddirectly fromthis.tags(non-optional) and updates a unit test to passtags: {}. - DogStatsD client now builds
#tagsPrefixusingthis.#tags.length(non-optional) in both constructor andupdateTags().
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/dd-trace/test/encode/agentless-ci-visibility.spec.js | Updates test setup to pass a realistic { tags: {} } config shape to the encoder. |
| packages/dd-trace/src/exporters/agentless/index.js | Removes optional chaining on config.tags when reading runtime-id and tightens the documented config contract. |
| packages/dd-trace/src/encode/agentless-ci-visibility.js | Removes optional chaining on this.tags for env/runtime-id emission in payload metadata. |
| packages/dd-trace/src/dogstatsd.js | Removes optional chaining on the internal #tags array when computing the cached tag prefix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## tianning.li/dd-trace-microvm-identity-refresh-option-b #9610 +/- ##
==========================================================================================
+ Coverage 97.38% 98.53% +1.15%
==========================================================================================
Files 955 955
Lines 133754 133754
Branches 10982 11721 +739
==========================================================================================
+ Hits 130250 131801 +1551
+ Misses 3504 1953 -1551 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
03a2c2a to
b93ba51
Compare
ceb03fb to
51fee3e
Compare
b93ba51 to
42fb068
Compare
51fee3e to
74187cb
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 74187cb70a
ℹ️ 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".
42fb068 to
60f47c6
Compare
670aa21 to
a42c365
Compare
BenchmarksBenchmark execution time: 2026-08-03 20:34:32 Comparing candidate commit 51f00d9 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 2330 metrics, 28 unstable metrics.
|
a42c365 to
0db171f
Compare
9a30816 to
986d2e2
Compare
0db171f to
9bf2cd7
Compare
986d2e2 to
4d60483
Compare
9bf2cd7 to
ce322a2
Compare
4d60483 to
7714864
Compare
ce322a2 to
cacbefe
Compare
7714864 to
df2c5cc
Compare
4e03431 to
cdf643d
Compare
c1717a5 to
ff4f1f5
Compare
cdf643d to
a7dc32f
Compare
ff4f1f5 to
1b0e671
Compare
a7dc32f to
0338ffa
Compare
1b0e671 to
3effe66
Compare
…encoder
config.tags is always an object by the time these run - Config#applyDefaults
seeds it from DD_TAGS's default (parsed to {} for an empty string) before any
other config logic, and every production caller of these constructors passes
config.tags straight through. Addresses BridgeAR's "tags will always be an
object" review comments on #9355 for exporters/agentless/index.js and
encode/agentless-ci-visibility.js.
Also drops the same redundant `?.` on DogStatsDClient's #tags, which is
always populated via generateClientConfig()/buildClientConfig() (both build
it as an array, never undefined).
Updates one test that constructed AgentlessCiVisibilityEncoder without tags
(not a shape any real caller produces) to pass tags: {} instead.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
0338ffa to
51f00d9
Compare
20917aa
into
tianning.li/dd-trace-microvm-identity-refresh-option-b
…encoder (#9610) config.tags is always an object by the time these run - Config#applyDefaults seeds it from DD_TAGS's default (parsed to {} for an empty string) before any other config logic, and every production caller of these constructors passes config.tags straight through. Addresses BridgeAR's "tags will always be an object" review comments on #9355 for exporters/agentless/index.js and encode/agentless-ci-visibility.js. Also drops the same redundant `?.` on DogStatsDClient's #tags, which is always populated via generateClientConfig()/buildClientConfig() (both build it as an array, never undefined). Updates one test that constructed AgentlessCiVisibilityEncoder without tags (not a shape any real caller produces) to pass tags: {} instead. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
…encoder (#9610) config.tags is always an object by the time these run - Config#applyDefaults seeds it from DD_TAGS's default (parsed to {} for an empty string) before any other config logic, and every production caller of these constructors passes config.tags straight through. Addresses BridgeAR's "tags will always be an object" review comments on #9355 for exporters/agentless/index.js and encode/agentless-ci-visibility.js. Also drops the same redundant `?.` on DogStatsDClient's #tags, which is always populated via generateClientConfig()/buildClientConfig() (both build it as an array, never undefined). Updates one test that constructed AgentlessCiVisibilityEncoder without tags (not a shape any real caller produces) to pass tags: {} instead. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
…encoder (#9610) config.tags is always an object by the time these run - Config#applyDefaults seeds it from DD_TAGS's default (parsed to {} for an empty string) before any other config logic, and every production caller of these constructors passes config.tags straight through. Addresses BridgeAR's "tags will always be an object" review comments on #9355 for exporters/agentless/index.js and encode/agentless-ci-visibility.js. Also drops the same redundant `?.` on DogStatsDClient's #tags, which is always populated via generateClientConfig()/buildClientConfig() (both build it as an array, never undefined). Updates one test that constructed AgentlessCiVisibilityEncoder without tags (not a shape any real caller produces) to pass tags: {} instead. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
…encoder (#9610) config.tags is always an object by the time these run - Config#applyDefaults seeds it from DD_TAGS's default (parsed to {} for an empty string) before any other config logic, and every production caller of these constructors passes config.tags straight through. Addresses BridgeAR's "tags will always be an object" review comments on #9355 for exporters/agentless/index.js and encode/agentless-ci-visibility.js. Also drops the same redundant `?.` on DogStatsDClient's #tags, which is always populated via generateClientConfig()/buildClientConfig() (both build it as an array, never undefined). Updates one test that constructed AgentlessCiVisibilityEncoder without tags (not a shape any real caller produces) to pass tags: {} instead. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Summary
Follow-up to #9355 addressing BridgeAR's review comments that
tagswill always be an object by the time these getters/checks run:packages/dd-trace/src/exporters/agentless/index.js—config.tags?.['runtime-id']→config.tags['runtime-id'](comment)packages/dd-trace/src/encode/agentless-ci-visibility.js—this.tags?.env/this.tags?.['runtime-id']→ non-optional (comment, comment)packages/dd-trace/src/dogstatsd.js— same redundant?.onDogStatsDClient#tags, which is always built as an array bygenerateClientConfig()/buildClientConfig()In every case, traced the constructor back to its only production caller:
config.tagscomes from the tracer'sConfig, which seedstagsto{}(neverundefined) in#applyDefaults()before any other config logic runs.Updated one test (
test/encode/agentless-ci-visibility.spec.js) that constructedAgentlessCiVisibilityEncoderwithouttags— a shape no real caller produces — to passtags: {}instead.Test plan
./node_modules/.bin/mocha packages/dd-trace/test/exporters/agentless/exporter.spec.js— 19 passing./node_modules/.bin/mocha packages/dd-trace/test/encode/agentless-ci-visibility.spec.js— 27 passing./node_modules/.bin/mocha packages/dd-trace/test/dogstatsd.spec.js— 48 passing, 1 pre-existing unrelated timeout (reproduced identically without this change)./node_modules/.bin/mocha packages/dd-trace/test/ci-visibility/exporters/agentless/writer.spec.js packages/dd-trace/test/ci-visibility/exporters/ci-validation.spec.js— 30 passingnpm run linton touched files🤖 Generated with Claude Code