Skip to content

Commit

Permalink
Add response size for WebSocket Analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
AnuGayan committed Sep 11, 2023
1 parent 516ef4b commit 967d3aa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
if (APIUtil.isAnalyticsEnabled()) {
WebSocketUtils.setApiPropertyToChannel(ctx, Constants.BACKEND_END_TIME_PROPERTY,
System.currentTimeMillis());
if (msg instanceof TextWebSocketFrame) {
WebSocketUtils.setApiPropertyToChannel(ctx, Constants.RESPONSE_SIZE,
((TextWebSocketFrame) msg).text().length());
}
}
// publish analytics events if analytics is enabled
publishSubscribeEvent(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
if (APIUtil.isAnalyticsEnabled()) {
WebSocketUtils.setApiPropertyToChannel(ctx, Constants.REQUEST_END_TIME_PROPERTY,
System.currentTimeMillis());
if (msg instanceof TextWebSocketFrame) {
WebSocketUtils.setApiPropertyToChannel(ctx, Constants.RESPONSE_SIZE,
((TextWebSocketFrame) msg).text().length());
}
}
publishPublishEvent(ctx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ public Map<String, Object> getProperties() {
}
customProperties.put(Constants.API_USER_NAME_KEY, getUserName());
customProperties.put(Constants.API_CONTEXT_KEY, getApiContext());
customProperties.put(Constants.RESPONSE_SIZE,
WebSocketUtils.getPropertyFromChannel(Constants.RESPONSE_SIZE, ctx));
return customProperties;
}

Expand Down

0 comments on commit 967d3aa

Please sign in to comment.