Skip to content

Commit

Permalink
chore: add logic to trigger stats for destinations that don't send me…
Browse files Browse the repository at this point in the history
…tadata
  • Loading branch information
Sai Sankeerth committed Jun 13, 2024
1 parent 0f9558d commit 883f3cb
Showing 1 changed file with 49 additions and 22 deletions.
71 changes: 49 additions & 22 deletions src/adapters/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,64 @@ const networkClientConfigs = {
httpsAgent: new https.Agent({ keepAlive: true }),
};

const fireOutgoingReqStats = ({
destType,
feature,
endpointPath,
requestMethod,
module,
metadata,
}) => {
const logMetaInfo = log.getLogMetadata(metadata);
stats.timing('outgoing_request_latency', startTime, {
...logMetaInfo,
feature,
destType,
endpointPath,
requestMethod,
module,
});
stats.counter('outgoing_request_count', 1, {
...logMetaInfo,
feature,
destType,
endpointPath,
success: clientResponse.success,
statusCode,
requestMethod,
module,
});
};

const fireHTTPStats = (clientResponse, startTime, statTags) => {
const destType = statTags.destType ? statTags.destType : '';
const feature = statTags.feature ? statTags.feature : '';
const endpointPath = statTags.endpointPath ? statTags.endpointPath : '';
const requestMethod = statTags.requestMethod ? statTags.requestMethod : '';
const module = statTags.module ? statTags.module : '';
const statusCode = clientResponse.success ? clientResponse.response.status : '';
let metadata = statTags?.metadata || [];
if (statTags?.metadata && !Array.isArray(statTags?.metadata)) {
metadata = [statTags.metadata];
}
metadata?.forEach((m) => {
const logMetaInfo = log.getLogMetadata(m);
stats.timing('outgoing_request_latency', startTime, {
...logMetaInfo,
feature,
destType,
endpointPath,
requestMethod,
module,
});
stats.counter('outgoing_request_count', 1, {
...logMetaInfo,
feature,
destType,
endpointPath,
success: clientResponse.success,
statusCode,
requestMethod,
module,
const metadata = !Array.isArray(statTags?.metadata) ? [statTags.metadata] : statTags.metadata;
metadata?.forEach((m) => {
fireOutgoingReqStats({
destType,
endpointPath,
feature,
module,
requestMethod,
statusCode,
metadata: m,
});
});
return;
}
fireOutgoingReqStats({
destType,
endpointPath,
feature,
module,
requestMethod,
statusCode,
});
};

Expand Down

0 comments on commit 883f3cb

Please sign in to comment.