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

Commit

Permalink
Add user tags to the invocation support
Browse files Browse the repository at this point in the history
  • Loading branch information
hamitb committed Jul 2, 2019
1 parent 60b6d95 commit fca9e88
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 27 deletions.
2 changes: 2 additions & 0 deletions src/plugins/Invocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -116,6 +117,7 @@ class Invocation {

destroy(): void {
InvocationSupport.removeTags();
InvocationSupport.removeAgentTags();
InvocationTraceSupport.clear();
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/data/invocation/InvocationData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class InvocationData extends BaseMonitoringData {
coldStart: boolean;
timeout: boolean;
tags: any;
userTags: any;
resources: Resource[];
incomingTraceLinks: any[];
outgoingTraceLinks: any[];
Expand All @@ -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;
35 changes: 31 additions & 4 deletions src/plugins/support/InvocationSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ 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) {
ThundraLogger.getInstance().error(e);
}
}

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];
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/utils/LambdaEventUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) {
Expand Down
10 changes: 5 additions & 5 deletions test/plugins/invocation.support.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down Expand Up @@ -50,7 +50,7 @@ describe('Invocation Support', () => {
InvocationSupport.setTag('string', 'value');

InvocationSupport.removeTags();
expect(InvocationSupport.tags).toEqual({});
expect(InvocationSupport.userTags).toEqual({});
});
});
});
30 changes: 15 additions & 15 deletions test/plugins/trace.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ describe('Trace', () => {
const beforeInvocationData = createMockBeforeInvocationData();

beforeAll(() => {
InvocationSupport.removeTags();
InvocationSupport.removeAgentTags();
InvocationTraceSupport.clear();

tracer.setPluginContext(pluginContext);
Expand All @@ -341,7 +341,7 @@ describe('Trace', () => {
const beforeInvocationData = createMockBeforeInvocationData();

beforeAll(() => {
InvocationSupport.removeTags();
InvocationSupport.removeAgentTags();
InvocationTraceSupport.clear();

tracer.setPluginContext(pluginContext);
Expand Down Expand Up @@ -372,7 +372,7 @@ describe('Trace', () => {
const beforeInvocationData = createMockBeforeInvocationData();

beforeAll(() => {
InvocationSupport.removeTags();
InvocationSupport.removeAgentTags();
InvocationTraceSupport.clear();

tracer.setPluginContext(pluginContext);
Expand All @@ -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', () => {
Expand Down Expand Up @@ -412,7 +412,7 @@ describe('Trace', () => {
const beforeInvocationData = createMockBeforeInvocationData();

beforeAll(() => {
InvocationSupport.removeTags();
InvocationSupport.removeAgentTags();
InvocationTraceSupport.clear();

tracer.setPluginContext(pluginContext);
Expand All @@ -439,7 +439,7 @@ describe('Trace', () => {
const beforeInvocationData = createMockBeforeInvocationData();

beforeAll(() => {
InvocationSupport.removeTags();
InvocationSupport.removeAgentTags();
InvocationTraceSupport.clear();

tracer.setPluginContext(pluginContext);
Expand All @@ -466,7 +466,7 @@ describe('Trace', () => {
const beforeInvocationData = createMockBeforeInvocationData();

beforeAll(() => {
InvocationSupport.removeTags();
InvocationSupport.removeAgentTags();
InvocationTraceSupport.clear();

tracer.setPluginContext(pluginContext);
Expand Down Expand Up @@ -494,7 +494,7 @@ describe('Trace', () => {
const beforeInvocationData = createMockBeforeInvocationData();

beforeAll(() => {
InvocationSupport.removeTags();
InvocationSupport.removeAgentTags();
InvocationTraceSupport.clear();

tracer.setPluginContext(pluginContext);
Expand All @@ -516,7 +516,7 @@ describe('Trace', () => {
const beforeInvocationData = createMockBeforeInvocationData();

beforeAll(() => {
InvocationSupport.removeTags();
InvocationSupport.removeAgentTags();
InvocationTraceSupport.clear();

tracer.setPluginContext(pluginContext);
Expand All @@ -538,7 +538,7 @@ describe('Trace', () => {
const beforeInvocationData = createMockBeforeInvocationData();

beforeAll(() => {
InvocationSupport.removeTags();
InvocationSupport.removeAgentTags();
InvocationTraceSupport.clear();

tracer.setPluginContext(pluginContext);
Expand All @@ -560,7 +560,7 @@ describe('Trace', () => {
const beforeInvocationData = createMockBeforeInvocationData();

beforeAll(() => {
InvocationSupport.removeTags();
InvocationSupport.removeAgentTags();
InvocationTraceSupport.clear();

tracer.setPluginContext(pluginContext);
Expand All @@ -587,7 +587,7 @@ describe('Trace', () => {
const beforeInvocationData = createMockBeforeInvocationData();

beforeAll(() => {
InvocationSupport.removeTags();
InvocationSupport.removeAgentTags();
InvocationTraceSupport.clear();

tracer.setPluginContext(pluginContext);
Expand All @@ -610,7 +610,7 @@ describe('Trace', () => {
const beforeInvocationData = createMockBeforeInvocationData();

beforeAll(() => {
InvocationSupport.removeTags();
InvocationSupport.removeAgentTags();
InvocationTraceSupport.clear();

tracer.setPluginContext(pluginContext);
Expand Down

0 comments on commit fca9e88

Please sign in to comment.