Skip to content

Commit

Permalink
fix(opentelemetry-resources): wait for async attributes for detecting…
Browse files Browse the repository at this point in the history
… resources
  • Loading branch information
ziolekjj committed May 8, 2024
1 parent 5608bba commit 7d68aa7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/opentelemetry-resources/src/detect-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export const detectResourcesSync = (
if (isPromiseLike<Resource>(resourceOrPromise)) {
const createPromise = async () => {
const resolvedResource = await resourceOrPromise;
if (resolvedResource.waitForAsyncAttributes) {
await resolvedResource.waitForAsyncAttributes();
}
return resolvedResource.attributes;
};
resource = new Resource({}, createPromise());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ describe('detectResourcesSync', () => {
it('handles resource detectors which return Promise<Resource>', async () => {
const detector: Detector = {
async detect() {
return new Resource({ sync: 'fromsync' });
return new Resource(
{ sync: 'fromsync' },
Promise.resolve({ async: 'fromasync' }).then(attrs => attrs)
);
},
};
const resource = detectResourcesSync({
Expand All @@ -38,6 +41,7 @@ describe('detectResourcesSync', () => {
await resource.waitForAsyncAttributes?.();
assert.deepStrictEqual(resource.attributes, {
sync: 'fromsync',
async: 'fromasync',
});
});

Expand Down

0 comments on commit 7d68aa7

Please sign in to comment.