diff --git a/src/plugins/Invocation.ts b/src/plugins/Invocation.ts index 5098aacd..ac0a60c1 100644 --- a/src/plugins/Invocation.ts +++ b/src/plugins/Invocation.ts @@ -102,6 +102,7 @@ class Invocation { } this.invocationData.setTags(InvocationSupport.tags); + this.invocationData.setUserTags(InvocationSupport.userTags); this.finishTimestamp = this.pluginContext.invocationFinishTimestamp; this.invocationData.finishTimestamp = this.finishTimestamp; this.invocationData.duration = this.finishTimestamp - this.startTimestamp; @@ -116,6 +117,7 @@ class Invocation { destroy(): void { InvocationSupport.removeTags(); + InvocationSupport.removeAgentTags(); InvocationTraceSupport.clear(); } } diff --git a/src/plugins/data/invocation/InvocationData.ts b/src/plugins/data/invocation/InvocationData.ts index ade8db17..2627b3e8 100644 --- a/src/plugins/data/invocation/InvocationData.ts +++ b/src/plugins/data/invocation/InvocationData.ts @@ -19,6 +19,7 @@ class InvocationData extends BaseMonitoringData { coldStart: boolean; timeout: boolean; tags: any; + userTags: any; resources: Resource[]; incomingTraceLinks: any[]; outgoingTraceLinks: any[]; @@ -36,6 +37,16 @@ class InvocationData extends BaseMonitoringData { ThundraLogger.getInstance().error(e); } } + + setUserTags(keyValuePairs: {[key: string]: any }): void { + try { + Object.keys(keyValuePairs).forEach((key) => { + this.userTags[key] = keyValuePairs[key]; + }); + } catch (e) { + ThundraLogger.getInstance().error(e); + } + } } export default InvocationData; diff --git a/src/plugins/support/InvocationSupport.ts b/src/plugins/support/InvocationSupport.ts index ef54e9ff..6318428b 100644 --- a/src/plugins/support/InvocationSupport.ts +++ b/src/plugins/support/InvocationSupport.ts @@ -2,10 +2,11 @@ import ThundraLogger from '../../ThundraLogger'; class InvocationSupport { static tags: any = {}; + static userTags: any = {}; static functionName: string = ''; static errorenous: boolean; - static setTag(key: string, value: any): void { + static setAgentTag(key: string, value: any): void { try { InvocationSupport.tags[key] = value; } catch (e) { @@ -13,11 +14,11 @@ class InvocationSupport { } } - static getTag(key: string): any { + static getAgentTag(key: string): any { return InvocationSupport.tags[key]; } - static setTags(keyValuePairs: {[key: string]: any }): void { + static setAgentTags(keyValuePairs: {[key: string]: any }): void { try { Object.keys(keyValuePairs).forEach((key) => { InvocationSupport.tags[key] = keyValuePairs[key]; @@ -27,10 +28,36 @@ class InvocationSupport { } } - static removeTags(): void { + static removeAgentTags(): void { InvocationSupport.tags = {}; } + static setTag(key: string, value: any): void { + try { + InvocationSupport.userTags[key] = value; + } catch (e) { + ThundraLogger.getInstance().error(e); + } + } + + static getTag(key: string): any { + return InvocationSupport.userTags[key]; + } + + static setTags(keyValuePairs: {[key: string]: any }): void { + try { + Object.keys(keyValuePairs).forEach((key) => { + InvocationSupport.userTags[key] = keyValuePairs[key]; + }); + } catch (e) { + ThundraLogger.getInstance().error(e); + } + } + + static removeTags(): void { + InvocationSupport.userTags = {}; + } + static setFunctionName(functionName: string): void { InvocationSupport.functionName = functionName; } diff --git a/src/plugins/utils/LambdaEventUtils.ts b/src/plugins/utils/LambdaEventUtils.ts index 09d98a96..a5408162 100644 --- a/src/plugins/utils/LambdaEventUtils.ts +++ b/src/plugins/utils/LambdaEventUtils.ts @@ -372,9 +372,9 @@ class LambdaEventUtils { } static injectTrigerTragsForInvocation(domainName: string, className: string, operationNames: any[]) { - InvocationSupport.setTag(SpanTags.TRIGGER_DOMAIN_NAME, domainName); - InvocationSupport.setTag(SpanTags.TRIGGER_CLASS_NAME, className); - InvocationSupport.setTag(SpanTags.TRIGGER_OPERATION_NAMES, operationNames); + InvocationSupport.setAgentTag(SpanTags.TRIGGER_DOMAIN_NAME, domainName); + InvocationSupport.setAgentTag(SpanTags.TRIGGER_CLASS_NAME, className); + InvocationSupport.setAgentTag(SpanTags.TRIGGER_OPERATION_NAMES, operationNames); } static injectTrigerTragsForSpan(span: ThundraSpan, domainName: string, className: string, operationNames: any[]) { diff --git a/test/plugins/invocation.support.test.js b/test/plugins/invocation.support.test.js index 391ceb7a..ac8ca22f 100644 --- a/test/plugins/invocation.support.test.js +++ b/test/plugins/invocation.support.test.js @@ -18,10 +18,10 @@ describe('Invocation Support', () => { InvocationSupport.setTag('object', object); - expect(InvocationSupport.tags['number']).toBe(5); - expect(InvocationSupport.tags['string']).toBe('value'); - expect(InvocationSupport.tags['boolean']).toBe(true); - expect(InvocationSupport.tags['object']).toBe(object); + expect(InvocationSupport.userTags['number']).toBe(5); + expect(InvocationSupport.userTags['string']).toBe('value'); + expect(InvocationSupport.userTags['boolean']).toBe(true); + expect(InvocationSupport.userTags ['object']).toBe(object); }); }); @@ -50,7 +50,7 @@ describe('Invocation Support', () => { InvocationSupport.setTag('string', 'value'); InvocationSupport.removeTags(); - expect(InvocationSupport.tags).toEqual({}); + expect(InvocationSupport.userTags).toEqual({}); }); }); }); \ No newline at end of file diff --git a/test/plugins/trace.test.js b/test/plugins/trace.test.js index 79366811..522917a1 100644 --- a/test/plugins/trace.test.js +++ b/test/plugins/trace.test.js @@ -314,7 +314,7 @@ describe('Trace', () => { const beforeInvocationData = createMockBeforeInvocationData(); beforeAll(() => { - InvocationSupport.removeTags(); + InvocationSupport.removeAgentTags(); InvocationTraceSupport.clear(); tracer.setPluginContext(pluginContext); @@ -341,7 +341,7 @@ describe('Trace', () => { const beforeInvocationData = createMockBeforeInvocationData(); beforeAll(() => { - InvocationSupport.removeTags(); + InvocationSupport.removeAgentTags(); InvocationTraceSupport.clear(); tracer.setPluginContext(pluginContext); @@ -372,7 +372,7 @@ describe('Trace', () => { const beforeInvocationData = createMockBeforeInvocationData(); beforeAll(() => { - InvocationSupport.removeTags(); + InvocationSupport.removeAgentTags(); InvocationTraceSupport.clear(); tracer.setPluginContext(pluginContext); @@ -381,9 +381,9 @@ describe('Trace', () => { }); it('should set trigger tags for DynamoDB to root span', () => { - expect(InvocationSupport.getTag('trigger.domainName')).toBe('DB'); - expect(InvocationSupport.getTag('trigger.className')).toBe('AWS-DynamoDB'); - expect(InvocationSupport.getTag('trigger.operationNames')).toEqual([ 'ExampleTableWithStream' ]); + expect(InvocationSupport.getAgentTag('trigger.domainName')).toBe('DB'); + expect(InvocationSupport.getAgentTag('trigger.className')).toBe('AWS-DynamoDB'); + expect(InvocationSupport.getAgentTag('trigger.operationNames')).toEqual([ 'ExampleTableWithStream' ]); }); it('should create incoming dynamodb trace links', () => { @@ -412,7 +412,7 @@ describe('Trace', () => { const beforeInvocationData = createMockBeforeInvocationData(); beforeAll(() => { - InvocationSupport.removeTags(); + InvocationSupport.removeAgentTags(); InvocationTraceSupport.clear(); tracer.setPluginContext(pluginContext); @@ -439,7 +439,7 @@ describe('Trace', () => { const beforeInvocationData = createMockBeforeInvocationData(); beforeAll(() => { - InvocationSupport.removeTags(); + InvocationSupport.removeAgentTags(); InvocationTraceSupport.clear(); tracer.setPluginContext(pluginContext); @@ -466,7 +466,7 @@ describe('Trace', () => { const beforeInvocationData = createMockBeforeInvocationData(); beforeAll(() => { - InvocationSupport.removeTags(); + InvocationSupport.removeAgentTags(); InvocationTraceSupport.clear(); tracer.setPluginContext(pluginContext); @@ -494,7 +494,7 @@ describe('Trace', () => { const beforeInvocationData = createMockBeforeInvocationData(); beforeAll(() => { - InvocationSupport.removeTags(); + InvocationSupport.removeAgentTags(); InvocationTraceSupport.clear(); tracer.setPluginContext(pluginContext); @@ -516,7 +516,7 @@ describe('Trace', () => { const beforeInvocationData = createMockBeforeInvocationData(); beforeAll(() => { - InvocationSupport.removeTags(); + InvocationSupport.removeAgentTags(); InvocationTraceSupport.clear(); tracer.setPluginContext(pluginContext); @@ -538,7 +538,7 @@ describe('Trace', () => { const beforeInvocationData = createMockBeforeInvocationData(); beforeAll(() => { - InvocationSupport.removeTags(); + InvocationSupport.removeAgentTags(); InvocationTraceSupport.clear(); tracer.setPluginContext(pluginContext); @@ -560,7 +560,7 @@ describe('Trace', () => { const beforeInvocationData = createMockBeforeInvocationData(); beforeAll(() => { - InvocationSupport.removeTags(); + InvocationSupport.removeAgentTags(); InvocationTraceSupport.clear(); tracer.setPluginContext(pluginContext); @@ -587,7 +587,7 @@ describe('Trace', () => { const beforeInvocationData = createMockBeforeInvocationData(); beforeAll(() => { - InvocationSupport.removeTags(); + InvocationSupport.removeAgentTags(); InvocationTraceSupport.clear(); tracer.setPluginContext(pluginContext); @@ -610,7 +610,7 @@ describe('Trace', () => { const beforeInvocationData = createMockBeforeInvocationData(); beforeAll(() => { - InvocationSupport.removeTags(); + InvocationSupport.removeAgentTags(); InvocationTraceSupport.clear(); tracer.setPluginContext(pluginContext);