From 4c609aa13c899dd2b7a963d2e3e491bc35ffb742 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Tue, 2 Mar 2021 18:47:06 +0530 Subject: [PATCH] fix: specification compliant resource collision precedence (#1975) Co-authored-by: Daniel Dyla Co-authored-by: Bartlomiej Obecny Co-authored-by: Valentin Marchaud --- README.md | 6 ++++++ packages/opentelemetry-resources/src/Resource.ts | 6 +++--- packages/opentelemetry-resources/test/Resource.test.ts | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3511731e8b..1cdfd7ca0e 100644 --- a/README.md +++ b/README.md @@ -245,6 +245,12 @@ To request automatic tracing support for a module not on this list, please [file ## Upgrade guidelines +### 0.17.0 to 0.18.0 + +[PR-1975](https://github.com/open-telemetry/opentelemetry-js/pull/1975) + +- Breaking change - The resulting resource MUST have all attributes that are on any of the two input resources. If a key exists on both the old and updating resource, the value of the updating resource MUST be picked - previously it was opposite. + ### 0.16.0 to 0.17.0 [PR-1880](https://github.com/open-telemetry/opentelemetry-js/pull/1880) feat(diag-logger): introduce a new global level api.diag for internal diagnostic logging diff --git a/packages/opentelemetry-resources/src/Resource.ts b/packages/opentelemetry-resources/src/Resource.ts index a459cfd590..b80d6614b0 100644 --- a/packages/opentelemetry-resources/src/Resource.ts +++ b/packages/opentelemetry-resources/src/Resource.ts @@ -54,7 +54,7 @@ export class Resource { /** * Returns a new, merged {@link Resource} by merging the current Resource - * with the other Resource. In case of a collision, current Resource takes + * with the other Resource. In case of a collision, other Resource takes * precedence. * * @param other the Resource that will be merged with this. @@ -66,8 +66,8 @@ export class Resource { // SpanAttributes from resource overwrite attributes from other resource. const mergedAttributes = Object.assign( {}, - other.attributes, - this.attributes + this.attributes, + other.attributes ); return new Resource(mergedAttributes); } diff --git a/packages/opentelemetry-resources/test/Resource.test.ts b/packages/opentelemetry-resources/test/Resource.test.ts index 3203148fc4..4e5962895c 100644 --- a/packages/opentelemetry-resources/test/Resource.test.ts +++ b/packages/opentelemetry-resources/test/Resource.test.ts @@ -50,7 +50,7 @@ describe('Resource', () => { it('should return merged resource when collision in attributes', () => { const expectedResource = new Resource({ - 'k8s.io/container/name': 'c1', + 'k8s.io/container/name': 'c2', 'k8s.io/namespace/name': 'default', 'k8s.io/pod/name': 'pod-xyz-123', 'k8s.io/location': 'location1',