use of core.framework.impl.log.ActionLog in project core-ng-project by neowu.
the class KafkaMessageListenerThread method handle.
private <T> void handle(String topic, KafkaMessageListener.MessageHandlerHolder<T> holder, List<ConsumerRecord<String, byte[]>> records, double longProcessThresholdInNano) {
for (ConsumerRecord<String, byte[]> record : records) {
ActionLog actionLog = logManager.begin("=== message handling begin ===");
try {
actionLog.action("topic:" + topic);
actionLog.context("topic", topic);
actionLog.context("handler", holder.handler.getClass().getCanonicalName());
actionLog.context("key", record.key());
logger.debug("message={}", new BytesParam(record.value()));
T message = holder.reader.fromJSON(record.value());
Headers headers = record.headers();
actionLog.refId(header(headers, KafkaHeaders.HEADER_REF_ID));
String client = header(headers, KafkaHeaders.HEADER_CLIENT);
if (client != null)
actionLog.context("client", client);
String clientIP = header(headers, KafkaHeaders.HEADER_CLIENT_IP);
if (clientIP != null)
actionLog.context("clientIP", clientIP);
if ("true".equals(header(headers, KafkaHeaders.HEADER_TRACE))) {
actionLog.trace = true;
}
holder.validator.validate(message);
holder.handler.handle(record.key(), message);
} catch (Throwable e) {
logManager.logError(e);
} finally {
long elapsedTime = actionLog.elapsedTime();
if (elapsedTime > longProcessThresholdInNano) {
logger.warn(Markers.errorCode("LONG_PROCESS"), "took too long to process message, elapsedTime={}", elapsedTime);
}
logManager.end("=== message handling end ===");
}
}
}
use of core.framework.impl.log.ActionLog in project core-ng-project by neowu.
the class KafkaMessageListenerThread method handle.
private <T> void handle(String topic, KafkaMessageListener.BulkMessageHandlerHolder<T> holder, List<ConsumerRecord<String, byte[]>> records, double longProcessThresholdInNano) {
ActionLog actionLog = logManager.begin("=== message handling begin ===");
try {
actionLog.action("topic:" + topic);
actionLog.context("topic", topic);
actionLog.context("handler", holder.handler.getClass().getCanonicalName());
actionLog.stat("messageCount", records.size());
List<Message<T>> messages = new ArrayList<>(records.size());
for (ConsumerRecord<String, byte[]> record : records) {
T message = holder.reader.fromJSON(record.value());
validate(holder.validator, message, record);
messages.add(new Message<>(record.key(), message));
if ("true".equals(header(record.headers(), KafkaHeaders.HEADER_TRACE))) {
// trigger trace if any message is trace
actionLog.trace = true;
}
}
holder.handler.handle(messages);
} catch (Throwable e) {
logManager.logError(e);
} finally {
long elapsedTime = actionLog.elapsedTime();
if (elapsedTime > longProcessThresholdInNano) {
logger.warn(Markers.errorCode("LONG_PROCESS"), "took too long to process message, elapsedTime={}", elapsedTime);
}
logManager.end("=== message handling end ===");
}
}
use of core.framework.impl.log.ActionLog in project core-ng-project by neowu.
the class ActionLogContext method track.
public static void track(String action, long elapsedTime, Integer readEntries, Integer writeEntries) {
LogManager logManager = logManager();
ActionLog actionLog = logManager.currentActionLog();
if (actionLog != null) {
actionLog.track(action, elapsedTime, readEntries, writeEntries);
}
}
use of core.framework.impl.log.ActionLog in project core-ng-project by neowu.
the class ActionLogContext method put.
public static void put(String key, Object value) {
LogManager logManager = logManager();
ActionLog actionLog = logManager.currentActionLog();
if (actionLog != null) {
// here to check null is for unit testing the logManager.begin may not be called
actionLog.context(key, value);
}
}
use of core.framework.impl.log.ActionLog in project core-ng-project by neowu.
the class ActionLogContext method id.
public static String id() {
LogManager logManager = logManager();
ActionLog actionLog = logManager.currentActionLog();
if (actionLog == null)
return null;
return actionLog.id;
}
Aggregations