Skip to content

feat(config): add resource detection parsing#6435

Merged
trentm merged 16 commits intoopen-telemetry:mainfrom
honeycombio:mike/resource-detection-parsing
Mar 12, 2026
Merged

feat(config): add resource detection parsing#6435
trentm merged 16 commits intoopen-telemetry:mainfrom
honeycombio:mike/resource-detection-parsing

Conversation

@MikeGoldsmith
Copy link
Copy Markdown
Member

@MikeGoldsmith MikeGoldsmith commented Feb 20, 2026

Which problem is this PR solving?

Fixes #5980

RC3 spec requires parsing of detection/development block in declarative config. Currently:

  • ExperimentalResourceDetection.detectors is incorrectly typed as a single object; the spec schema defines it as an array
  • Neither FileConfigFactory nor EnvironmentConfigFactory parse the detection/development block

Short description of the changes

  • Fix ExperimentalResourceDetection.detectors type from ExperimentalResourceDetector to ExperimentalResourceDetector[] to match spec schema
  • Add parseDetectionDevelopment() to FileConfigFactory to parse the detection/development block from YAML config files, including detector list and attribute include/exclude filters
  • Map OTEL_NODE_RESOURCE_DETECTORS env var to detection/development.detectors in EnvironmentConfigFactory (container, host, process, serviceinstance→service, env, os)
  • Add env and os as Node.js-specific extensions to ExperimentalResourceDetector (no spec equivalent; supported under the experimental detection/development block)
  • Remove node_resource_detectors from ConfigurationModel; detection/development.detectors now owns this data
  • Update getResourceDetectorsFromConfiguration() in sdk-node to map ExperimentalResourceDetector objects to detector instances

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Updated configFromKitchenSinkFile expected config to include detection/development with all detectors including env and os
  • Added env var tests for all, none, specific detectors including env and os
  • Added unit tests for getResourceDetectorsFromConfiguration() covering all detector types and edge cases

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

Assisted-by: Claude Sonnet 4.6

- Fix ExperimentalResourceDetection.detectors type from object to array (per spec schema)
- Add parseDetectionDevelopment() to FileConfigFactory to parse detection/development block from YAML, including attribute include/exclude filters
- Map OTEL_NODE_RESOURCE_DETECTORS env var to detection/development.detectors (container, host, process, serviceinstance→service; skips JS-only env/os)
- Update configFromKitchenSinkFile test expectation with detection/development
- Add env var tests for all, none, and JS-only detector cases

Claude Sonnet 4.6 assisted with this change.
@MikeGoldsmith MikeGoldsmith requested a review from a team as a code owner February 20, 2026 13:44
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 20, 2026

Codecov Report

❌ Patch coverage is 98.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.74%. Comparing base (de02086) to head (bb6d2fd).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...al/packages/configuration/src/FileConfigFactory.ts 96.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6435   +/-   ##
=======================================
  Coverage   95.73%   95.74%           
=======================================
  Files         364      364           
  Lines       11826    11871   +45     
  Branches     2765     2789   +24     
=======================================
+ Hits        11322    11366   +44     
- Misses        504      505    +1     
Files with missing lines Coverage Δ
...ages/configuration/src/EnvironmentConfigFactory.ts 99.53% <100.00%> (+0.01%) ⬆️
...l/packages/configuration/src/models/configModel.ts 100.00% <ø> (ø)
...ental/packages/opentelemetry-sdk-node/src/start.ts 100.00% <100.00%> (ø)
...ental/packages/opentelemetry-sdk-node/src/utils.ts 96.19% <100.00%> (-0.03%) ⬇️
...al/packages/configuration/src/FileConfigFactory.ts 97.54% <96.66%> (-0.04%) ⬇️
🚀 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.

config.resource is always initialised before the detection/development block
is parsed, so the null check was dead code causing a codecov miss.
Use non-null assertion instead.

Claude Sonnet 4.6 assisted with this change.
Comment thread experimental/packages/configuration/src/FileConfigFactory.ts Outdated
Consistent with the rest of FileConfigFactory which uses for loops
rather than filter/map chains.

Claude Sonnet 4.6 assisted with this change.
@MikeGoldsmith MikeGoldsmith changed the title feat(configuration): add resource detection parsing feat(config): add resource detection parsing Feb 24, 2026
@maryliag
Copy link
Copy Markdown
Contributor

maryliag commented Mar 2, 2026

Thank you for working on this!

When I initially created these parsers, there was no place to add the node resource attributes, so I created the parameter node_resource_detectors in configModel, but with this change, it can now be removed, and the code that would set it on env variable can be removed.

JS-only env/os have no spec equivalent and are skipped

We don't want to lose any existing functionality, so I would not mark the issue itself as fixed until all items are added. You can have a PR on the config repo to update the schema to include the missing ones, and then add them into here on a following PR. Or you can hold on to this PR until the schema is updated and have it all here. It's up to you, either way works

…detection/development model

- Remove node_resource_detectors field from ConfigurationModel; detection/development.detectors now owns this data
- Remove redundant constructor code in EnvironmentConfigFactory that set node_resource_detectors
- Update getResourceDetectorsFromConfiguration() in sdk-node to map ExperimentalResourceDetector objects to detector instances
- Update setupResource() to check detection/development.detectors instead of node_resource_detectors
- Update start.test.ts: os detector is JS-only with no spec equivalent, not included via config model path
- Add unit tests for getResourceDetectorsFromConfiguration() covering all detector types and edge cases

Made-with: Cursor
@MikeGoldsmith
Copy link
Copy Markdown
Member Author

Not sure the test failure is related to my changes - could someone re-run it for me please?

@MikeGoldsmith
Copy link
Copy Markdown
Member Author

Never mind - merging main into this branch fixed it 😄

Copy link
Copy Markdown
Contributor

@maryliag maryliag left a comment

Choose a reason for hiding this comment

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

Great!

- Add `os` and `env` to `ExperimentalResourceDetector` as Node.js-specific extensions (no spec equivalent)
- Map `os`/`env` in `EnvironmentConfigFactory` OTEL_NODE_RESOURCE_DETECTORS parsing, including `all`
- Handle `os`/`env` in `FileConfigFactory` `parseDetectionDevelopment()`
- Map `detector.os`/`detector.env` to `osDetector`/`envDetector` in `getResourceDetectorsFromConfiguration()`
- Update tests and kitchen-sink fixture
- Note Node.js-only status in sdk-node README

Assisted-by: Claude Sonnet 4.6
@MikeGoldsmith
Copy link
Copy Markdown
Member Author

@maryliag I decided to add os and env support in this PR as it didn't feel like a big change in 3e6a8f7 - let me know what you think.

os is now included in OTEL_NODE_RESOURCE_DETECTORS=all via config model

Assisted-by: Claude Sonnet 4.6
Copy link
Copy Markdown
Contributor

@maryliag maryliag left a comment

Choose a reason for hiding this comment

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

Thanks for adding the missing ones, it makes things easier 😄

Comment thread experimental/packages/configuration/src/EnvironmentConfigFactory.ts Outdated
Comment thread experimental/packages/opentelemetry-sdk-node/src/utils.ts Outdated
Comment thread experimental/packages/opentelemetry-sdk-node/README.md
Copy link
Copy Markdown
Contributor

@maryliag maryliag left a comment

Choose a reason for hiding this comment

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

removing the approval, just so it doesn't get merged accidentally until the changes are made

env detector must run last so its attributes take highest priority
over other detectors

Assisted-by: Claude Sonnet 4.6
Comment thread experimental/packages/configuration/src/models/resourceModel.ts Outdated
Comment thread experimental/CHANGELOG.md Outdated
Comment thread experimental/packages/configuration/test/fixtures/kitchen-sink.yaml Outdated
if (detector.host != null) result.push(hostDetector);
if (detector.os != null) result.push(osDetector);
if (detector.process != null) result.push(processDetector);
if (detector.service != null) result.push(serviceInstanceIdDetector);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We are allowed to have a breaking change in v3. I wonder if we want to change our (currently experimental, I think?) serviceInstanceIdDetector and deprecate it in favour of a serviceDetector that does the same thing.

(I'm not sure if the intent is that OTEL_SERVICE_NAME is handled by service or by env.)

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.

Agree this is worth discussing, but feels like a separate concern from this PR. Happy to open a follow-up issue to track renaming serviceInstanceIdDetectorserviceDetector for v3 if that's the direction.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Absolutely a separate PR kind of thing.
I'm curious for @maryliag's opinion. I.e. whether changes in OTel JS here are worth it to have a service resource detector be closer in naming and scope to other languages (or at least closer to what I assume OTel Java does).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like the idea of a serviceDetector that handles everything service related, meaning instance ID and name, and making it clear the priority of where the value comes from, so it's worth opening a new issue/PR to handle that.

To answer your other question:

OTEL_SERVICE_NAME is handled by service or by env

I think being handled by the service would make more obvious to users, because is in the name, and we can make the priority clear of where the value comes from.
Using a serviceDetector would also help with the decision between the random uuid and defined service instance ID, where today depending on the order the users adds (serviceInstanceId, env VS env, serviceInstanceId) it returns different results.
That would be a breaking change, so as long as we make that clear to users, then should be fine

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.

Thanks both - I like the idea of replacing serviceInstanceDetecto -> serviceDetector and simplifying to cover name and ID.

I opened the follow-up issue to track doing that

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FWIW, I spent some time looking at OTel Java and Python implementations, and ... gave up after a little bit. Python doesn't have anything for service.instance.id I don't think, yet.

OTel Java has a ServiceInstanceIdResourceProvider (https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/resources/ServiceInstanceIdResourceProvider.java#L20-L47). It and the EnvironmentResourceProvider are using .order() SPI things (with values -1 and MAX_INT) to handle priority.

It also has a ServiceResourceDetector (with name "service") in the declarative config code (https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetector.java#L18) that is slightly different in that it handles service.name and service.instance.id.

Anyway, clarity to seek on another day.

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.

Thanks for the notes @trentm - I've been helping out on the Java implementation and am leading the Python implementation too (which is still very early).

I'd like to consolidate on a consistent pattern too and will keep an eye on it the linked issue 👍🏻

MikeGoldsmith and others added 2 commits March 10, 2026 11:54
- Fix service detector JSDoc: only populates service.instance.id, not service.name
- Move CHANGELOG entry to Unreleased section
- Sort detectors alphabetically in kitchen-sink.yaml (order is user-controlled in YAML configs)

Assisted-by: Claude Sonnet 4.6
@trentm trentm added this pull request to the merge queue Mar 12, 2026
Merged via the queue into open-telemetry:main with commit 2d361ec Mar 12, 2026
27 checks passed
@MikeGoldsmith MikeGoldsmith deleted the mike/resource-detection-parsing branch March 13, 2026 11:49
MikeGoldsmith added a commit to honeycombio/opentelemetry-js that referenced this pull request Mar 16, 2026
- resolve conflicts from PR open-telemetry#6435 (resource detection parsing)
- keep Zod-based FileConfigFactory, drop upstream's manual parser
- port OTEL_NODE_RESOURCE_DETECTORS env var parsing into EnvironmentConfigFactory
- fix null-check pattern: use !== undefined so YAML-produced null values work
- rename OTEL_EXPERIMENTAL_CONFIG_FILE → OTEL_CONFIG_FILE
- fix TS7056: annotate OpenTelemetryConfigurationSchema as ZodTypeAny
- replace z.infer<> in types.ts with explicit Configuration interface
- fix sdk-node type refs: ConfigurationModel → Configuration
- fix sdk-node test fixture logger.yaml TLS field names
- all 53 configuration tests and 150 sdk-node tests passing

Assisted-by: Claude Sonnet 4.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set values coming from OTEL_NODE_RESOURCE_DETECTORS when using config file

5 participants