From 87531af15ec323ad4c548b6598e0bc6c765c2f0b Mon Sep 17 00:00:00 2001 From: Siim Kallas Date: Thu, 7 Nov 2024 09:48:56 +0200 Subject: [PATCH 1/2] Resource: remove unnecessary diagnostic when accessing attributes while async attributes are resolving --- .../opentelemetry-resources/src/Resource.ts | 6 ------ .../test/Resource.test.ts | 18 ------------------ 2 files changed, 24 deletions(-) diff --git a/packages/opentelemetry-resources/src/Resource.ts b/packages/opentelemetry-resources/src/Resource.ts index d44dbacc4df..8310bf1d9a9 100644 --- a/packages/opentelemetry-resources/src/Resource.ts +++ b/packages/opentelemetry-resources/src/Resource.ts @@ -93,12 +93,6 @@ export class Resource implements IResource { } get attributes(): ResourceAttributes { - if (this.asyncAttributesPending) { - diag.error( - 'Accessing resource attributes before async attributes settled' - ); - } - return this._attributes ?? {}; } diff --git a/packages/opentelemetry-resources/test/Resource.test.ts b/packages/opentelemetry-resources/test/Resource.test.ts index 3916e1c985d..635b8c9bec2 100644 --- a/packages/opentelemetry-resources/test/Resource.test.ts +++ b/packages/opentelemetry-resources/test/Resource.test.ts @@ -98,24 +98,6 @@ describe('Resource', () => { assert.strictEqual(resource.attributes['custom.boolean'], true); }); - it('should log when accessing attributes before async attributes promise has settled', () => { - const debugStub = sinon.spy(diag, 'error'); - const resource = new Resource( - {}, - new Promise(resolve => { - setTimeout(resolve, 1); - }) - ); - - resource.attributes; - - assert.ok( - debugStub.calledWithMatch( - 'Accessing resource attributes before async attributes settled' - ) - ); - }); - describe('.empty()', () => { it('should return an empty resource (except required service name)', () => { const resource = Resource.empty(); From 1e7bdd6f511d3de45e28098c820035456396a516 Mon Sep 17 00:00:00 2001 From: Siim Kallas Date: Thu, 7 Nov 2024 11:56:49 +0200 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7fc0c04ae4..85ebece2dd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se ### :rocket: (Enhancement) +* fix(resources): remove diagnostic error when accessing attributes while async attributes are resolving. [#5119](https://github.com/open-telemetry/opentelemetry-js/pull/5119) @seemk + ### :bug: (Bug Fix) ### :books: (Refine Doc)