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

Commit

Permalink
add setError function to InvocationData
Browse files Browse the repository at this point in the history
  • Loading branch information
fatihaydilek committed Aug 21, 2019
1 parent 6030e42 commit 68a211d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
19 changes: 4 additions & 15 deletions src/plugins/Invocation.ts
Expand Up @@ -43,6 +43,8 @@ class Invocation {
this.finishTimestamp = null;
this.startTimestamp = this.pluginContext.invocationStartTimestamp;

InvocationSupport.clearError();

this.invocationData = Utils.initMonitoringData(this.pluginContext,
MonitoringDataType.INVOCATION) as InvocationData;

Expand Down Expand Up @@ -81,30 +83,17 @@ class Invocation {

afterInvocation = (data: any) => {
if (InvocationSupport.hasError()) {
this.invocationData.erroneous = true;
this.invocationData.tags.error = true;
this.invocationData.errorType = InvocationSupport.error.errorType;
this.invocationData.errorMessage = InvocationSupport.error.errorMessage;
this.invocationData.tags['error.message'] = InvocationSupport.error.errorMessage;
this.invocationData.tags['error.kind'] = InvocationSupport.error.errorType;
if (InvocationSupport.error.code) {
this.invocationData.tags['error.code'] = InvocationSupport.error.code;
}
if (InvocationSupport.error.stack) {
this.invocationData.tags['error.stack'] = InvocationSupport.error.stack;
}
this.invocationData.setError(InvocationSupport.error);
}

if (data.error) {
const error = Utils.parseError(data.error);
this.invocationData.erroneous = true;
this.invocationData.setError(error);
if (data.error instanceof TimeoutError) {
this.invocationData.timeout = true;
this.invocationData.tags['aws.lambda.invocation.timeout'] = true;
}

this.invocationData.errorType = error.errorType;
this.invocationData.errorMessage = error.errorMessage;
this.invocationData.tags.error = true;
this.invocationData.tags['error.message'] = error.errorMessage;
this.invocationData.tags['error.kind'] = error.errorType;
Expand Down
10 changes: 8 additions & 2 deletions src/plugins/data/invocation/InvocationData.ts
Expand Up @@ -30,7 +30,7 @@ class InvocationData extends BaseMonitoringData {
setTags(keyValuePairs: {[key: string]: any }): void {
try {
Object.keys(keyValuePairs).forEach((key) => {
this.tags[key] = keyValuePairs[key];
this.tags[key] = keyValuePairs[key];
});
} catch (e) {
ThundraLogger.getInstance().error(e);
Expand All @@ -40,12 +40,18 @@ class InvocationData extends BaseMonitoringData {
setUserTags(keyValuePairs: {[key: string]: any }): void {
try {
Object.keys(keyValuePairs).forEach((key) => {
this.userTags[key] = keyValuePairs[key];
this.userTags[key] = keyValuePairs[key];
});
} catch (e) {
ThundraLogger.getInstance().error(e);
}
}

setError(error: any): void {
this.erroneous = true;
this.errorType = error.errorType;
this.errorMessage = error.errorMessage;
}
}

export default InvocationData;

0 comments on commit 68a211d

Please sign in to comment.