Skip to content

Commit

Permalink
feat: capture router success/failure metrics (#2279)
Browse files Browse the repository at this point in the history
feat: capture router failure metric

Co-authored-by: Ujjwal Abhishek <[email protected]>
  • Loading branch information
Gauravudia and ujjwal-ab authored Jun 20, 2023
1 parent 9faa41a commit 7d4a9b2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
16 changes: 3 additions & 13 deletions src/services/destination/cdkV2Integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,16 @@ export default class CDKV2DestinationService implements IntegrationDestinationSe
destInputArray[0].metadata.workspaceId,
tags.FEATURES.ROUTER,
);
metaTo.metadata = destInputArray[0].metadata;
try {
const doRouterTransformationResponse: RouterTransformationResponse[] =
await processCdkV2Workflow(destinationType, destInputArray, tags.FEATURES.ROUTER);

stats.increment('event_transform_success', {
destType: destinationType,
module: tags.MODULES.DESTINATION,
destinationId: destInputArray[0].metadata.destinationId,
workspaceId: destInputArray[0].metadata.workspaceId,
feature: tags.FEATURES.ROUTER,
implementation: tags.IMPLEMENTATIONS.CDK_V2,
});

return DestinationPostTransformationService.handleRouterTransformSuccessEvents(
doRouterTransformationResponse,
undefined,
metaTo,
tags.IMPLEMENTATIONS.CDK_V2,
destinationType.toUpperCase(),
);
} catch (error: any) {
metaTo.metadatas = destInputArray.map((input) => input.metadata);
Expand All @@ -145,9 +138,6 @@ export default class CDKV2DestinationService implements IntegrationDestinationSe
error,
metaTo,
);

stats.increment('event_transform_failure', metaTo.errorDetails);

return [erroredResp];
}
},
Expand Down
3 changes: 3 additions & 0 deletions src/services/destination/nativeIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,13 @@ export default class NativeIntegrationDestinationService implements IntegrationD
try {
const doRouterTransformationResponse: RouterTransformationResponse[] =
await destHandler.processRouterDest(destInputArray);
metaTO.metadata = destInputArray[0].metadata;
return DestinationPostTransformationService.handleRouterTransformSuccessEvents(
doRouterTransformationResponse,
destHandler,
metaTO,
tags.IMPLEMENTATIONS.NATIVE,
destinationType.toUpperCase(),
);
} catch (error: any) {
metaTO.metadatas = destInputArray.map((input) => input.metadata);
Expand Down
26 changes: 22 additions & 4 deletions src/services/destination/postTransformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
} from '../../types/index';
import { generateErrorObject } from '../../v0/util';
import ErrorReportingService from '../errorReporting';
import tags from '../../v0/util/tags';
import stats from '../../util/stats';

export default class DestinationPostTransformationService {
public static handleProcessorTransformSucessEvents(
Expand Down Expand Up @@ -63,27 +65,42 @@ export default class DestinationPostTransformationService {
transformedPayloads: RouterTransformationResponse[],
destHandler: any,
metaTO: MetaTransferObject,
implementation: string,
destinationType: string,
): RouterTransformationResponse[] {
const resultantPayloads: RouterTransformationResponse[] = cloneDeep(transformedPayloads);
resultantPayloads.forEach((resultantPayload) => {
if (resultantPayload.batchedRequest && resultantPayload.batchedRequest.userId) {
resultantPayload.batchedRequest.userId = `${resultantPayload.batchedRequest.userId}`;
}
});

if (destHandler?.processMetadataForRouter) {
return resultantPayloads.map((resultantPayload) => {
resultantPayload.metadata = destHandler.processMetadataForRouter(resultantPayload);
return resultantPayload;
});
}
resultantPayloads
.filter((resp) => 'error' in resp && isObject(resp.statTags) && !isEmpty(resp.statTags))
.forEach((resp) => {

resultantPayloads.forEach((resp) => {
if ('error' in resp && isObject(resp.statTags) && !isEmpty(resp.statTags)) {
resp.statTags = {
...resp.statTags,
...metaTO.errorDetails,
};
});
stats.increment('event_transform_failure', metaTO.errorDetails);
} else {
stats.increment('event_transform_success', {
destType: destinationType,
module: tags.MODULES.DESTINATION,
implementation,
feature: tags.FEATURES.ROUTER,
destinationId: metaTO.metadata?.destinationId,
workspaceId: metaTO.metadata?.workspaceId,
});
}
});

return resultantPayloads;
}

Expand All @@ -100,6 +117,7 @@ export default class DestinationPostTransformationService {
statTags: errObj.statTags,
} as RouterTransformationResponse;
ErrorReportingService.reportError(error, metaTO.errorContext, resp);
stats.increment('event_transform_failure', metaTO.errorDetails);
return resp;
}

Expand Down

0 comments on commit 7d4a9b2

Please sign in to comment.