Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converge sync and async resources #5350

Merged

Conversation

dyladan
Copy link
Member

@dyladan dyladan commented Jan 17, 2025

Fixes: #3582

This PR makes it so that any resource detector can detect sync and async resources, returning both in a single resource object.

  • Internally, the resource now stores all key/value pairs in a list. This means the override order comes from the order of detection, not the order of when the promises are resolved. Rejected promises are skipped. This should make the order of resource detection significantly more obvious to end users. It also paves the way for entities which explicitly require detection priority to be defined by the order in which entity detectors are configured.
  • Resource detectors now return plain objects instead of new Resource instances. This should improve type compatibility in the future.
  • Detected resource interface contains an optional attributes key, which all attributes are nested under. This will make it easier to extend for entities in the future by adding a new key to the object.

To be done in follow-up:

@dyladan dyladan requested a review from a team as a code owner January 17, 2025 15:19
Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

Thank you for working on this 🙂
A quick preliminary review - I'll have a closer look at the implementation details next week :)

Copy link

codecov bot commented Jan 22, 2025

Codecov Report

Attention: Patch coverage is 85.16484% with 27 lines in your changes missing coverage. Please review.

Project coverage is 94.79%. Comparing base (f9fda8b) to head (ee3e732).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...lemetry-resources/src/detectors/BrowserDetector.ts 43.75% 9 Missing ⚠️
...ntelemetry-browser-detector/src/BrowserDetector.ts 0.00% 4 Missing ⚠️
...entelemetry-resources/src/detectors/EnvDetector.ts 93.87% 3 Missing ⚠️
...es/opentelemetry-resources/src/detect-resources.ts 80.00% 2 Missing ⚠️
...ntelemetry-resources/src/detectors/NoopDetector.ts 33.33% 2 Missing ⚠️
...tectors/platform/node/ServiceInstanceIdDetector.ts 33.33% 2 Missing ⚠️
packages/opentelemetry-resources/src/Resource.ts 97.87% 1 Missing ⚠️
...tors/platform/browser/ServiceInstanceIdDetector.ts 0.00% 1 Missing ⚠️
...ces/src/detectors/platform/node/ProcessDetector.ts 91.66% 1 Missing ⚠️
...rs/platform/node/machine-id/getMachineId-darwin.ts 66.66% 1 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5350      +/-   ##
==========================================
+ Coverage   94.65%   94.79%   +0.13%     
==========================================
  Files         317      310       -7     
  Lines        8025     7967      -58     
  Branches     1687     1680       -7     
==========================================
- Hits         7596     7552      -44     
+ Misses        429      415      -14     
Files with missing lines Coverage Δ
...imental/packages/opentelemetry-sdk-node/src/sdk.ts 96.03% <100.00%> (ø)
...ental/packages/opentelemetry-sdk-node/src/utils.ts 91.37% <100.00%> (ø)
...ges/opentelemetry-resources/src/detectors/index.ts 100.00% <100.00%> (ø)
...elemetry-resources/src/detectors/platform/index.ts 100.00% <100.00%> (ø)
...ources/src/detectors/platform/node/HostDetector.ts 100.00% <100.00%> (ø)
...esources/src/detectors/platform/node/OSDetector.ts 100.00% <100.00%> (ø)
...try-resources/src/detectors/platform/node/index.ts 100.00% <100.00%> (ø)
...ctors/platform/node/machine-id/getMachineId-bsd.ts 100.00% <100.00%> (ø)
...ors/platform/node/machine-id/getMachineId-linux.ts 100.00% <100.00%> (ø)
...ctors/platform/node/machine-id/getMachineId-win.ts 93.33% <100.00%> (ø)
... and 12 more

... and 1 file with indirect coverage changes

Copy link
Contributor

@chancancode chancancode left a comment

Choose a reason for hiding this comment

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

Take it with an unhealthy amount of salt, but other than the suggestions I left (feel free to make your own judgment call), it looks good to me!

Copy link
Contributor

@trentm trentm left a comment

Choose a reason for hiding this comment

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

I think this LGTM.

I asked a Q at #5358 (comment)
I'm not totally clear on what the user's experience with resources (usage with the SDK I mean) will be after these changes at #5358, especially when Entities come along.

@dyladan dyladan added this pull request to the merge queue Feb 3, 2025
Merged via the queue into open-telemetry:main with commit 595d0e9 Feb 3, 2025
17 checks passed
@dyladan dyladan deleted the resource-async-sync branch February 3, 2025 19:59
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.

Consolidate sync and async resource interfaces
5 participants