Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize error before sending to xray #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/traceResolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const tracer = function (resolver, parent, args, ctx, info) {
result.then(function () {
subsegment.close();
}).catch(function (error) {
subsegment.close(error);
subsegment.close(serializeError(error));
});
} else {
subsegment.close();
Expand All @@ -38,6 +38,21 @@ const tracer = function (resolver, parent, args, ctx, info) {
return result;
};

/* Constructs an xray-safe error object (no circular structure errors) */
export const serializeError = (e: string | Error) => {
if (typeof e === 'string') {
return e;
}

// See here for how error properties are parsed - https://github.com/aws/aws-xray-sdk-node/blob/master/packages/core/lib/segments/attributes/captured_exception.js#L12
return {
message: e.message,
name: e.name,
stack: e.stack,
};
};


module.exports = function (schema) {
applyMiddlewareToDeclaredResolvers(schema, tracer);
};