yumeng před 1 týdnem
rodič
revize
c22e180e5a

+ 33 - 4
src/main/java/com/adx/tencent/honor/HonorTrackingController.java

@@ -70,18 +70,30 @@ public class HonorTrackingController {
         String tagId = requireTagId(params);
         String traceId = honorTraceId(params);
         if (traceId == null || traceId.isBlank()) {
+            log.warn("[荣耀][曝光] 缺少 traceId, params={}", params.keySet());
             throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "missing honor trace id (trackId)");
         }
+        log.info("[荣耀][曝光] 收到曝光请求 | traceId={} | IP={} | 全部入参: {}", traceId, clientIp(request), params);
 
         NormalizedBidResponse response = adxClient.requestBid(buildBidRequest(request, traceId, params));
-        if (response == null) throw new ResponseStatusException(HttpStatus.BAD_GATEWAY, "empty baidu ADX response");
+        if (response == null) {
+            log.warn("[荣耀][曝光] 百度ADX返回空响应, traceId={}", traceId);
+            throw new ResponseStatusException(HttpStatus.BAD_GATEWAY, "empty baidu ADX response");
+        }
+        log.info("[荣耀][曝光] 百度ADX返回: qk={}, hasBid={}, showUrls={}, clickUrls={}",
+                response.getQk(),
+                response.getBid() != null,
+                response.getBid() != null && response.getBid().getShowUrls() != null ? response.getBid().getShowUrls().size() : 0,
+                response.getBid() != null && response.getBid().getClickUrls() != null ? response.getBid().getClickUrls().size() : 0);
 
         HonorBidRecord record = bidRecordFromResponse(response, traceId, "impression", params);
         hotStore.recordBid(record);
+        log.info("[荣耀][曝光] 已缓存bid, qk={}, traceId={}", record.getQk(), traceId);
 
         List<TrackingResult> tracking = Collections.emptyList();
         if (response.getBid() != null && response.getBid().getShowUrls() != null && !response.getBid().getShowUrls().isEmpty()) {
             tracking = adxClient.reportImpression(response.getBid().getShowUrls(), response.getBid().getPrice());
+            log.info("[荣耀][曝光] 曝光上报完成, qk={}, results={}", record.getQk(), tracking);
             recordTracking(record.getQk(), tagId, "impression", tracking);
         }
         return Map.of("qk", record.getQk(), "traceId", traceId, "tagId", tagId);
@@ -93,30 +105,46 @@ public class HonorTrackingController {
         String tagId = requireTagId(params);
         String traceId = honorTraceId(params);
         if (traceId == null || traceId.isBlank()) {
+            log.warn("[荣耀][点击] 缺少 traceId, params={}", params.keySet());
             throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "missing honor trace id (trackId)");
         }
+        log.info("[荣耀][点击] 收到点击请求 | traceId={} | IP={} | 全部入参: {}", traceId, clientIp(request), params);
 
         HonorBidRecord record = hotStore.findBidByMediaTrace(traceId);
         if (record == null) {
+            log.info("[荣耀][点击] Redis未命中, 发起竞价请求, traceId={}", traceId);
             NormalizedBidResponse bidResponse = adxClient.requestBid(buildBidRequest(request, traceId, params));
-            if (bidResponse == null) throw new ResponseStatusException(HttpStatus.BAD_GATEWAY, "empty baidu ADX response");
+            if (bidResponse == null) {
+                log.warn("[荣耀][点击] 百度ADX返回空响应, traceId={}", traceId);
+                throw new ResponseStatusException(HttpStatus.BAD_GATEWAY, "empty baidu ADX response");
+            }
             record = bidRecordFromResponse(bidResponse, traceId, "click", params);
             hotStore.recordBid(record);
+            log.info("[荣耀][点击] 竞价成功, qk={}, traceId={}", record.getQk(), traceId);
             if (bidResponse.getBid() != null && bidResponse.getBid().getShowUrls() != null && !bidResponse.getBid().getShowUrls().isEmpty()) {
                 List<TrackingResult> impressionTracking = adxClient.reportImpression(
                         bidResponse.getBid().getShowUrls(), bidResponse.getBid().getPrice());
+                log.info("[荣耀][点击] Redis未命中补竞价后,曝光上报完成, qk={}, results={}", record.getQk(), impressionTracking);
                 recordTracking(record.getQk(), tagId, "impression", impressionTracking);
             }
+        } else {
+            log.info("[荣耀][点击] Redis命中, qk={}, traceId={}", record.getQk(), traceId);
         }
 
         List<TrackingResult> tracking = adxClient.reportClick(
                 record.getClickUrls() != null ? record.getClickUrls() : Collections.emptyList());
+        log.info("[荣耀][点击] 点击上报完成, qk={}, results={}", record.getQk(), tracking);
         recordTracking(record.getQk(), tagId, "click", tracking);
-        hotStore.shrinkAfterClick(record);
+        try {
+            hotStore.shrinkAfterClick(record);
+        } catch (Exception e) {
+            log.warn("[荣耀][点击] Redis缩减失败(不影响主流程), qk={}, error={}", record.getQk(), e.getMessage());
+        }
 
         String destination = record.getAppStoreLink() != null && !record.getAppStoreLink().isBlank()
                 ? record.getAppStoreLink() : record.getLandingPage();
         if (destination != null && !destination.isBlank()) {
+            log.info("[荣耀][点击] 302重定向, qk={}, destination={}", record.getQk(), destination);
             response.sendRedirect(destination);
             return null;
         }
@@ -173,6 +201,7 @@ public class HonorTrackingController {
         bidReq.put("device", device);
         List<Integer> appList = parseAppList(firstParam(params, "appList", "app_list", "applist"));
         if (!appList.isEmpty()) bidReq.put("appList", appList);
+        log.info("[荣耀][百度ADX] 竞价请求 | traceId={} | body={}", traceId, bidReq);
         return bidReq;
     }
 
@@ -274,7 +303,7 @@ public class HonorTrackingController {
             try {
                 result.add(Integer.parseInt(item));
             } catch (NumberFormatException e) {
-                log.warn("[Honor] 忽略非法 appList 值 | raw={} | item={}", value, item);
+                log.warn("[荣耀][百度ADX] 忽略非法 appList 值 | raw={} | item={}", value, item);
             }
         }
         return result;

+ 18 - 18
src/main/java/com/adx/tencent/httpapi/TrackingController.java

@@ -75,23 +75,23 @@ public class TrackingController {
         Map<String, String> params = flatQueryParams(request);
         String traceId = mediaTraceId(params);
         if (traceId == null || traceId.isBlank()) {
-            log.warn("[impression] 缺少 traceId, params={}", params.keySet());
+            log.warn("[腾讯][曝光] 缺少 traceId, params={}", params.keySet());
             throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "missing media trace id (click_id/oaid/imei/idfa)");
         }
         if (tencentPlacement == null) {
             throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, "tencent placement not configured");
         }
 
-        log.info("[曝光] 收到曝光请求 | traceId={} | IP={} | 全部入参: {}", traceId, clientIp(request), params);
+        log.info("[腾讯][曝光] 收到曝光请求 | traceId={} | IP={} | 全部入参: {}", traceId, clientIp(request), params);
 
         Map<String, Object> bidRequest = mediaBidRequest(request, "tencent", traceId, params, tencentPlacement);
         NormalizedBidResponse response = adxClient.requestBid(bidRequest);
         if (response == null) {
-            log.warn("[impression] 百度ADX返回空响应, traceId={}", traceId);
+            log.warn("[腾讯][曝光] 百度ADX返回空响应, traceId={}", traceId);
             throw new ResponseStatusException(HttpStatus.BAD_GATEWAY, "empty baidu ADX response");
         }
 
-        log.info("[impression] 百度ADX返回: qk={}, hasBid={}, showUrls={}, clickUrls={}", 
+        log.info("[腾讯][曝光] 百度ADX返回: qk={}, hasBid={}, showUrls={}, clickUrls={}",
                 response.getQk(),
                 response.getBid() != null,
                 response.getBid() != null && response.getBid().getShowUrls() != null ? response.getBid().getShowUrls().size() : 0,
@@ -99,14 +99,14 @@ public class TrackingController {
 
         BidRecord record = bidRecordFromMediaResponse(response, "tencent", traceId, "impression", params);
         hotStore.recordBid(record);
-        log.info("[impression] 已缓存bid, qk={}, traceId={}", record.getQk(), traceId);
+        log.info("[腾讯][曝光] 已缓存bid, qk={}, traceId={}", record.getQk(), traceId);
 
         // 上报百度曝光
         if (response.getBid() != null && response.getBid().getShowUrls() != null
                 && !response.getBid().getShowUrls().isEmpty()) {
             List<TrackingResult> trackingResults = adxClient.reportImpression(
                     response.getBid().getShowUrls(), response.getBid().getPrice());
-            log.info("[impression] 曝光上报完成, qk={}, results={}", response.getQk(), trackingResults);
+            log.info("[腾讯][曝光] 曝光上报完成, qk={}, results={}", response.getQk(), trackingResults);
             recordTrackingResults(response.getQk(), "impression", trackingResults);
         }
         return Map.of("qk", nvl(record.getQk()), "traceId", traceId);
@@ -139,21 +139,21 @@ public class TrackingController {
         Map<String, String> params = flatQueryParams(request);
         String traceId = mediaTraceId(params);
         if (traceId == null || traceId.isBlank()) {
-            log.warn("[click] 缺少 traceId, params={}", params.keySet());
+            log.warn("[腾讯][点击] 缺少 traceId, params={}", params.keySet());
             throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "missing media trace id (click_id/oaid/imei/idfa)");
         }
 
-        log.info("[点击] 收到点击请求 | traceId={} | IP={} | 全部入参: {}", traceId, clientIp(request), params);
+        log.info("[腾讯][点击] 收到点击请求 | traceId={} | IP={} | 全部入参: {}", traceId, clientIp(request), params);
 
         // 先从 Redis 按 mediaTrace 查找已有 bid
         BidRecord record = hotStore.findBidByMediaTrace("tencent", traceId);
         if (record == null) {
-            log.info("[click] Redis未命中, 发起竞价请求, traceId={}", traceId);
+            log.info("[腾讯][点击] Redis未命中, 发起竞价请求, traceId={}", traceId);
             // 未找到,临时发起竞价请求
             Map<String, Object> bidRequest = mediaBidRequest(request, "tencent", traceId, params, tencentPlacement);
             NormalizedBidResponse resp = adxClient.requestBid(bidRequest);
             if (resp == null) {
-                log.warn("[click] 百度ADX返回空响应, traceId={}", traceId);
+                log.warn("[腾讯][点击] 百度ADX返回空响应, traceId={}", traceId);
                 throw new ResponseStatusException(HttpStatus.BAD_GATEWAY, "empty baidu ADX response");
             }
             BidRecord newRecord = bidRecordFromMediaResponse(resp, "tencent", traceId, "click", params);
@@ -163,18 +163,18 @@ public class TrackingController {
                     && !resp.getBid().getShowUrls().isEmpty()) {
                 List<TrackingResult> impressionResults = adxClient.reportImpression(
                         resp.getBid().getShowUrls(), resp.getBid().getPrice());
-                log.info("[click] Redis未命中补竞价后,曝光上报完成, qk={}, results={}", record.getQk(), impressionResults);
+                log.info("[腾讯][点击] Redis未命中补竞价后,曝光上报完成, qk={}, results={}", record.getQk(), impressionResults);
                 recordTrackingResults(record.getQk(), "impression", impressionResults);
             }
-            log.info("[click] 竞价成功, qk={}, traceId={}", record.getQk(), traceId);
+            log.info("[腾讯][点击] 竞价成功, qk={}, traceId={}", record.getQk(), traceId);
         } else {
-            log.info("[click] Redis命中, qk={}, traceId={}", record.getQk(), traceId);
+            log.info("[腾讯][点击] Redis命中, qk={}, traceId={}", record.getQk(), traceId);
         }
 
         // 上报百度点击
         List<TrackingResult> trackingResults = adxClient.reportClick(
                 record.getClickUrls() != null ? record.getClickUrls() : Collections.emptyList());
-        log.info("[click] 点击上报完成, qk={}, results={}", record.getQk(), trackingResults);
+        log.info("[腾讯][点击] 点击上报完成, qk={}, results={}", record.getQk(), trackingResults);
         recordTrackingResults(record.getQk(), "click", trackingResults);
 
         // 点击处理完成,缩减 Redis 数据(清除 clickUrls/landingPage/appStoreLink)
@@ -183,12 +183,12 @@ public class TrackingController {
         try {
             hotStore.shrinkAfterClick(record);
         } catch (Exception e) {
-            log.warn("[click] Redis缩减失败(不影响主流程), qk={}, error={}", record.getQk(), e.getMessage());
+            log.warn("[腾讯][点击] Redis缩减失败(不影响主流程), qk={}, error={}", record.getQk(), e.getMessage());
         }
 
         // 重定向到 landing page 或 app store link
         if (destination != null && !destination.isBlank()) {
-            log.info("[click] 302重定向, qk={}, destination={}", record.getQk(), destination);
+            log.info("[腾讯][点击] 302重定向, qk={}, destination={}", record.getQk(), destination);
             response.sendRedirect(destination);
             return null;
         }
@@ -298,7 +298,7 @@ public class TrackingController {
         List<Integer> appList = parseAppList(firstParam(params, "appList", "app_list", "applist"));
         if (!appList.isEmpty()) bidReq.put("appList", appList);
 
-        log.info("[百度ADX] 竞价请求 | traceId={} | body={}", traceId, bidReq);
+        log.info("[腾讯][百度ADX] 竞价请求 | traceId={} | body={}", traceId, bidReq);
 
         return bidReq;
     }
@@ -373,7 +373,7 @@ public class TrackingController {
             try {
                 result.add(Integer.parseInt(item));
             } catch (NumberFormatException e) {
-                log.warn("[百度ADX] 忽略非法 appList 值 | raw={} | item={}", value, item);
+                log.warn("[腾讯][百度ADX] 忽略非法 appList 值 | raw={} | item={}", value, item);
             }
         }
         return result;