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

Provide access to the AWS request object #169

Open
zakwalters opened this issue Nov 23, 2018 · 0 comments
Open

Provide access to the AWS request object #169

zakwalters opened this issue Nov 23, 2018 · 0 comments

Comments

@zakwalters
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants