Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 24db9ed

Browse files
authored
Fix: silently ignore the invalid keys and values (#664)
1 parent ae226fa commit 24db9ed

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

packages/opencensus-core/src/tags/tag-map.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,7 @@ export class TagMap {
4242
* @param tagMetadata The TagMetadata associated with this Tag.
4343
*/
4444
set(tagKey: TagKey, tagValue: TagValue, tagMetadata?: TagMetadata): void {
45-
if (!isValidTagKey(tagKey)) {
46-
throw new Error(`Invalid TagKey name: ${tagKey.name}`);
47-
}
48-
if (!isValidTagValue(tagValue)) {
49-
throw new Error(`Invalid TagValue: ${tagValue.value}`);
50-
}
45+
if (!isValidTagKey(tagKey) || !isValidTagValue(tagValue)) return;
5146
let existingKey;
5247
for (const key of this.registeredTags.keys()) {
5348
if (key.name === tagKey.name) {

packages/opencensus-core/test/test-tag-map.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ describe('TagMap()', () => {
7575
assert.deepStrictEqual(tags.get(key1), expectedTagValueWithMetadata);
7676
});
7777

78-
it('should throw an error when invalid tagKey', () => {
79-
assert.throws(() => {
80-
tagMap.set(invalidKey1, value1);
81-
}, /^Error: Invalid TagKey name:/);
78+
it('should silently ignore when invalid tagKey', () => {
79+
tagMap.set(invalidKey1, value1);
80+
const tags = tagMap.tagsWithMetadata;
81+
assert.strictEqual(tags.size, 0);
8282
});
8383

84-
it('should throw an error when invalid tagValue', () => {
85-
assert.throws(() => {
86-
tagMap.set(key1, invalidValue1);
87-
}, /^Error: Invalid TagValue:/);
84+
it('should silently ignore when invalid tagValue', () => {
85+
tagMap.set(key1, invalidValue1);
86+
const tags = tagMap.tagsWithMetadata;
87+
assert.strictEqual(tags.size, 0);
8888
});
8989

9090
it('should not set duplicate tagkey and tagvalue', () => {

0 commit comments

Comments
 (0)