clarkie/dynogels

Provide access to the AWS request object

zakwalters opened this issue · 0 comments

My team would like to be able to access the raw AWS request object that is returned by calls to the AWS SDK, as it provides useful monitoring information such as the number of retries before the request succeeded.

Currently the request object is thrown away on this line of sendRequest, so users of dynogels can't access any of the information included in the request.

Adding the request/context as an extra parameter to the callback was discussed here, and is clearly not a path that is going to be accepted.

One approach that should work is to add an includeContext option to wrap the returned item in an object that includes both the item and other contextual information, such as the request object. This would leave the interface the same for existing code, and users who want the contextual information can set the includeContext option, and would know that the object passed to their callback would look like { data: {}, context: {} }, rather than just the data object.

A drawback to this is that some of the table methods that call sendRequest don't include an options parameter and would have to have one added. However, in these cases the additional argument can be handled in the same way as in methods like destroy.

User code could then look like this:

myTable.get("myItem", null, { includeContext: true }, (err, result) => {
  var data = result.data;
  var awsRequestObject = result.context.awsRequest;
});

And sendRequest would include something like this:

-driver[method].call(driver, params, (err, data) => {
+let awsRequest = driver[method].call(driver, params, (err, data) => {
   const elapsed = Date.now() - startTime;
 
   if (err) {
     self.log.warn({ err: err }, 'dynogels %s error', method.toUpperCase());
     return callback(err);
   } else {
     self.log.info({ data: data }, 'dynogels %s response - %sms', method.toUpperCase(), elapsed);
+    // `includeContext` would be a parameter of `sendRequest`
+    let result = includeContext ? { data, context: { awsRequest } } : data;
-    return callback(null, data);
+    return callback(null, result);
   }
 });

Is this something we can add to dynogels? If not through this approach, then are there any alternatives?