-
Notifications
You must be signed in to change notification settings - Fork 838
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
base: main
Are you sure you want to change the base?
Converge sync and async resources #5350
Conversation
packages/opentelemetry-resources/test/regression/existing-detectors-1-9-1.test.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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 :)
experimental/packages/opentelemetry-browser-detector/test/util.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-resources/src/detectors/BrowserDetector.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-resources/src/detectors/platform/node/OSDetector.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-resources/src/detectors/BrowserDetector.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-bsd.test.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-darwin.test.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-resources/test/detectors/node/machine-id/getMachineId-linux.test.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-resources/src/detectors/BrowserDetector.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-resources/src/detectors/platform/node/OSDetector.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-resources/src/detectors/platform/node/ProcessDetector.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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!
There was a problem hiding this 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.
return Resource.FromAttributeList([ | ||
...resource._rawAttributes, | ||
...this._rawAttributes, | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nice to ahve a comment here that resource
is first here because (a) the implementation is "first one wins" and (b) the spec says:
https://opentelemetry.io/docs/specs/otel/resource/sdk/#merge
If a key exists on both the old and updating resource, the value of the updating resource MUST be picked (even if the updated value is empty).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add a comment, but does this implementation convey intent better to you?
return Resource.FromAttributeList(
[...this.getRawAttributes(), ...resource.getRawAttributes()].reverse()
);
advantages:
- More explicit intent
- reversing both arrays guards against arrays with duplicate entries (unlikely/impossible but /shrug)
disadvantages:
- slightly less efficient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another possibility would be to change the impl of FromAttributeList
to have the opposite order semantic.
edit: actually the first-wins semantic comes from the attributes
getter, so that's what would have to change.
experimental/packages/opentelemetry-browser-detector/src/BrowserDetector.ts
Outdated
Show resolved
Hide resolved
|
||
return new Resource(mergedSyncAttributes, mergedAttributesPromise); | ||
return Resource.FromAttributeList([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible that we get duplicated attributes if both resources define the same one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they can be duplicated in the list but the attributes
getter would ignore duplicates when they are retrieved and memoized
* @param config Configuration for resource detection | ||
*/ | ||
export const detectResources = async ( | ||
export const detectResources = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe I missed some context. We removed the call to waitForAsyncAttributes
in this function and it seems no component is calling it. So some attributes may stay as promises within the resource instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the wait for async attributes happens in the export pipeline (i think specifically in the processor). The resource no longer needs to be awaited for the new list-based merge logic, which was the original reason for awaiting in the detection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the explanation :)
Fixes: #3582
This PR makes it so that any resource detector can detect sync and async resources, returning both in a single resource object.
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: