appmetrics
appmetrics copied to clipboard
Improve http/https outbound request handler probe
trafficstars
I found that a lot of http libs don't use the standard request callback. (superagent , requests).
What do you think about this for http/https outbound?
// After 'http.request' function returns
function(target, methodName, methodArgs, probeData, rc) {
// If no callback has been used then end the metrics after returning from the method instead
// Need to get request method and URL again
var ri = getRequestItems(methodArgs[0]);
if (aspect.findCallbackArg(methodArgs) === undefined) {
aspect.after(rc._events, ["socket"], probeData, function(target, methodName, methodArgs, context, rc) {
aspect.before(target._events, ["response"], function(target, methodName, methodArgs, context) {
that.metricsProbeEnd(probeData, ri.requestMethod, ri.urlRequested, methodArgs[0], ri.headers);
that.requestProbeEnd(probeData, ri.requestMethod, ri.urlRequested, methodArgs[0], ri.headers);
});
});
}
return rc;
}