Skip to content

Commit

Permalink
fix: fix mssql support (#256)
Browse files Browse the repository at this point in the history
* fix: fix mssql support

* fix: change to medium+
  • Loading branch information
doriaviram authored Apr 14, 2021
1 parent c975c19 commit 9f16dc5
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
environment:
- TZ: Asia/Jerusalem
- NODE_OPTIONS: --max_old_space_size=1500
resource_class: medium
resource_class: medium+
steps:
- checkout
- restore_cache:
Expand Down
2 changes: 2 additions & 0 deletions scripts/bd_to_prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ echo "Creating layer latest version arn table md file (LAYERS.md)"
cd ../larn && npm i -g
larn -r nodejs10.x -n layers/LAYERS10x --filter lumigo-node-tracer -p ~/lumigo-node
larn -r nodejs12.x -n layers/LAYERS12x --filter lumigo-node-tracer -p ~/lumigo-node
larn -r nodejs14.x -n layers/LAYERS14x --filter lumigo-node-tracer -p ~/lumigo-node
cd ../lumigo-node
git add layers/LAYERS10x.md
git add layers/LAYERS12x.md
git add layers/LAYERS14x.md
git commit -m "docs: layers md [skip ci]"
git push origin master
25 changes: 8 additions & 17 deletions src/extender.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,12 @@ export const hook = (module, funcName, options = {}) => {
};

export const hookPromise = (originalPromise, options) => {
const { beforeThen = noop, afterThen = noop, beforeCatch = noop, afterCatch = noop } = options;
hook(originalPromise, 'then', {
beforeHook: args => {
hook(args, '0', {
beforeHook: beforeThen,
afterHook: afterThen,
});
},
});
hook(originalPromise, 'catch', {
beforeHook: args => {
hook(args, '0', {
beforeHook: beforeCatch,
afterHook: afterCatch,
});
},
});
const { thenHandler = noop, catchHandler = noop } = options;
const safeThenHandler = safeExecute(thenHandler, `thenHandler of fail`);
const safeCatchHandler = safeExecute(catchHandler, `catchHandler of fail`);
const errorHandler = async err => {
safeCatchHandler(err);
throw err;
};
originalPromise.then(safeThenHandler).catch(errorHandler);
};
41 changes: 41 additions & 0 deletions src/extender.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,45 @@ describe('extender', () => {
done();
}
});

test('hookPromise -> thenHandler', done => {
let resolveRef;

const p = new Promise(function(resolve) {
resolveRef = resolve;
});

const thenHandler = value => {
expect(value).toEqual('Value');
done();
};
extender.hookPromise(p, { thenHandler: thenHandler });
resolveRef('Value');
});

test('hookPromise -> thenHandler -> safe from errors', async () => {
let resolveRef;

const p = new Promise(function(resolve) {
resolveRef = resolve;
});

const thenHandler = value => {
expect(value).toEqual('Value');
throw new Error('Bla bla');
};
extender.hookPromise(p, { thenHandler: thenHandler });
resolveRef('Value');
await p;
});

test('hookPromise -> catchHandler', async () => {
const p = Promise.reject(new Error('octopus'));

const catchHandler = value => {
expect(value).toEqual('octopus');
};
extender.hookPromise(p, { catchHandler: catchHandler });
await expect(p).rejects.toThrow();
});
});
8 changes: 4 additions & 4 deletions src/hooks/msSql.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ function queryAfterHook(args, originalFnResult, extenderContext) {
const { currentSpan } = extenderContext;
if (isPromise(originalFnResult)) {
hookPromise(originalFnResult, {
beforeThen: args => {
handleResult(currentSpan, args[0]);
thenHandler: args => {
handleResult(currentSpan, args);
},
beforeCatch: args => {
handleResult(currentSpan, null, args[0]);
catchHandler: args => {
handleResult(currentSpan, null, args);
},
});
}
Expand Down

0 comments on commit 9f16dc5

Please sign in to comment.