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

Commit

Permalink
Fix: silently ignore the invalid keys and values (#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 authored Oct 9, 2019
1 parent ae226fa commit 24db9ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
7 changes: 1 addition & 6 deletions packages/opencensus-core/src/tags/tag-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ export class TagMap {
* @param tagMetadata The TagMetadata associated with this Tag.
*/
set(tagKey: TagKey, tagValue: TagValue, tagMetadata?: TagMetadata): void {
if (!isValidTagKey(tagKey)) {
throw new Error(`Invalid TagKey name: ${tagKey.name}`);
}
if (!isValidTagValue(tagValue)) {
throw new Error(`Invalid TagValue: ${tagValue.value}`);
}
if (!isValidTagKey(tagKey) || !isValidTagValue(tagValue)) return;
let existingKey;
for (const key of this.registeredTags.keys()) {
if (key.name === tagKey.name) {
Expand Down
16 changes: 8 additions & 8 deletions packages/opencensus-core/test/test-tag-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ describe('TagMap()', () => {
assert.deepStrictEqual(tags.get(key1), expectedTagValueWithMetadata);
});

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

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

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

0 comments on commit 24db9ed

Please sign in to comment.