Skip to content

Commit a6e9160

Browse files
authored
Merge pull request #5 from Moesif/add-capture-outgoing-support
Refactor: Remove Config option for async functions
2 parents f8d6c3e + 7415f96 commit a6e9160

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,6 @@ options.maskContent = function(moesifEvent) {
263263
Type: `Boolean`
264264
Set to true to print debug logs if you're having integration issues.
265265

266-
#### __`promisedBased`__
267-
Type: `Boolean`
268-
Set to true while using aws lambda async functions. For more details, please refer to - https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html.
269-
270266
For more documentation regarding what fields and meaning,
271267
see below or the [Moesif Node API Documentation](https://www.moesif.com/docs/api?javascript).
272268

@@ -301,7 +297,8 @@ If you want to capture all outgoing API calls from your Node.js app to third par
301297
Stripe or to your own dependencies, call `startCaptureOutgoing()` to start capturing.
302298

303299
```javascript
304-
var moesifMiddleware = moesifExpress(options);
300+
const moesif = require('moesif-aws-lambda');
301+
var moesifMiddleware = moesif(options);
305302
moesifMiddleware.startCaptureOutgoing();
306303
```
307304

app.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ exports.handler = function (event, context, callback) {
5050
};
5151

5252
// Async Functions
53-
// Please set promisedBased configuration flag to true while using async functions. For more details, please refer to - https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html.
54-
55-
// moesifOptions.promisedBased = true;
53+
// For more details, please refer to - https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html.
5654

5755
// exports.handler = async (event, context) => {
5856
// const response = {

lib/index.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,31 +156,25 @@ module.exports = function (options, handler) {
156156
var moesifMiddleware = function (event, context, callback) {
157157
moesifConfigManager.tryGetConfig();
158158

159-
if (callback && typeof callback === 'function' && !options.promisedBased) {
160159
logMessage(options.debug, 'moesifMiddleware', 'start');
161160
var next = function (err, result) {
162161
logEvent(event, context, err, result, options, moesifController);
163162
callback(err, result)
164163
};
165164

166-
return handler(event, context, next);
167-
} else {
168-
var returnedPromise = handler(event, context, callback);
165+
const returnPromise = handler(event, context, next);
169166

170-
if (returnedPromise && returnedPromise.then && typeof returnedPromise.then === 'function') {
171-
return returnedPromise.then((result) => {
167+
if (returnPromise instanceof Promise) {
168+
return returnPromise.then((result) => {
172169
return logEvent(event, context, null, result, options, moesifController).then(() => {
173170
return result;
174171
});
175172
}).catch((err) => {
176173
logEvent(event, context, err, {}, options, moesifController);
177174
throw err;
178175
});
179-
} else {
180-
logMessage(options.debug, 'moesifMiddleware', 'Can not log promised based handler, please check your configuration.');
181-
return returnedPromise;
182-
}
183176
}
177+
return returnPromise;
184178
};
185179

186180
moesifMiddleware.updateUser = function(userModel, cb) {

0 commit comments

Comments
 (0)