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

fix(resources): wait for async attributes for detecting resources #4687

Merged
merged 5 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/
* fix(resources): prevent circular import (resource -> detector -> resource -> ...) [#4653](https://github.com/open-telemetry/opentelemetry-js/pull/4653) @pichlermarc
* fixes a circular import warning which would appear in rollup when bundling `@opentelemetry/resources`
* fix(exporter-metrics-otlp-grpc): add explicit otlp-exporter-base dependency to exporter-metrics-otlp-grpc [#4678](https://github.com/open-telemetry/opentelemetry-js/pull/4678) @AkselAllas
* fix(resources) wait for async attributes for detecting resources [#4687](https://github.com/open-telemetry/opentelemetry-js/pull/4687) @ziolekjj

### :books: (Refine Doc)

Expand Down
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();
}
ziolekjj marked this conversation as resolved.
Show resolved Hide resolved
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)
ziolekjj marked this conversation as resolved.
Show resolved Hide resolved
);
},
};
const resource = detectResourcesSync({
Expand All @@ -38,6 +41,7 @@ describe('detectResourcesSync', () => {
await resource.waitForAsyncAttributes?.();
assert.deepStrictEqual(resource.attributes, {
sync: 'fromsync',
async: 'fromasync',
});
});

Expand Down