add-trace:增加链路追踪

- 新增/修改轨迹
- 新增/修改轨迹事件处理跳过
- 推送拦截失败
This commit is contained in:
hardstylewyl 2025-04-16 10:59:21 +08:00
parent 24a80c7a50
commit bcd4ad5781
3 changed files with 24 additions and 2 deletions

View File

@ -5,6 +5,7 @@ using Microsoft.Extensions.Options;
using Newtonsoft.Json; using Newtonsoft.Json;
using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.InterfaceRelay.Application.Contracts; using SJZY.InterfaceRelay.Application.Contracts;
using SJZY.OTel;
using SJZY.Track.Application.Contract.Dtos.TrackPush; using SJZY.Track.Application.Contract.Dtos.TrackPush;
using SJZY.Track.Application.Contract.Events; using SJZY.Track.Application.Contract.Events;
using SJZY.Track.Application.Contract.Services; using SJZY.Track.Application.Contract.Services;
@ -549,6 +550,11 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
//轨迹推送失败(被拦截) //轨迹推送失败(被拦截)
private void TrackPushFailedPublicTopic(string failedMessage, TrackPushEvent @event, OrderEntity order) private void TrackPushFailedPublicTopic(string failedMessage, TrackPushEvent @event, OrderEntity order)
{ {
using var activity = ActivityHelper.CreateSpanActivity("TrackPushEventHandler");
activity.SetTag("TrackPushFailedPublicTopic", failedMessage);
activity.SetTag("failedMessage", failedMessage);
activity.SetTag("@event", @event);
activity.SetTag("order", order);
_broadcastingService.TrackPushFailedPubilcTopic(new TrackPushRecordDto _broadcastingService.TrackPushFailedPubilcTopic(new TrackPushRecordDto
{ {
SubSystemCode = @event.SubSystemCode, SubSystemCode = @event.SubSystemCode,
@ -581,6 +587,10 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
List<dynamic> pushOrUpdateInputs List<dynamic> pushOrUpdateInputs
) )
{ {
using var activity = ActivityHelper.CreateSpanActivity("TrackPushEventHandler");
activity.SetTag("TrackPushFailedPublicTopic", failedMessage);
activity.SetTag("failedMessage", failedMessage);
activity.SetTag("@event", @event);
foreach (var pushInput in pushOrUpdateInputs) foreach (var pushInput in pushOrUpdateInputs)
{ {
_broadcastingService.TrackPushFailedPubilcTopic(new TrackPushRecordDto _broadcastingService.TrackPushFailedPubilcTopic(new TrackPushRecordDto

View File

@ -1,8 +1,8 @@
using System.Diagnostics;
using DotNetCore.CAP; using DotNetCore.CAP;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SJZY.Expand.ABP.Core.Logger; using SJZY.Expand.ABP.Core.Logger;
using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.OTel;
using SJZY.Track.Application.Contract.Events; using SJZY.Track.Application.Contract.Events;
using SJZY.Track.Application.Contract.Services; using SJZY.Track.Application.Contract.Services;
using SJZY.Track.Application.Services.Warning.Handlers; using SJZY.Track.Application.Services.Warning.Handlers;
@ -11,7 +11,6 @@ using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate;
using SJZY.Track.Domain.Aggregates.WarningAggregate.Signals; using SJZY.Track.Domain.Aggregates.WarningAggregate.Signals;
using SJZY.Track.Domain.Dtos.TrackContents; using SJZY.Track.Domain.Dtos.TrackContents;
using SJZY.Track.Domain.Enums; using SJZY.Track.Domain.Enums;
using SJZY.Track.Domain.Extensions;
using SJZY.Track.Domain.Queries; using SJZY.Track.Domain.Queries;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using OrderIdentifier = SJZY.Track.Application.Contract.Events.OrderIdentifier; using OrderIdentifier = SJZY.Track.Application.Contract.Events.OrderIdentifier;
@ -309,11 +308,14 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
// 修改了extra,要校验修改后的extra是否存在 // 修改了extra,要校验修改后的extra是否存在
|| (!string.IsNullOrWhiteSpace(@event.NewExtra) && x.Extra == @event.NewExtra)).ToList(); || (!string.IsNullOrWhiteSpace(@event.NewExtra) && x.Extra == @event.NewExtra)).ToList();
using var activity = ActivityHelper.CreateSpanActivity("TrackUpsertEventHandler");
if (@event.IsAdd) if (@event.IsAdd)
{ {
if (existTracks.Count > 0) if (existTracks.Count > 0)
{ {
_logger.LogInformation("订单已经存在不允许重复的轨迹,不允许重复添加:{@event}", @event); _logger.LogInformation("订单已经存在不允许重复的轨迹,不允许重复添加:{@event}", @event);
activity.SetTag("errorMsg", "订单已经存在不允许重复的轨迹,不允许重复添加");
activity.SetTag("@event", @event);
continue; continue;
} }
@ -325,12 +327,16 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
if (existTracks.Count == 0) if (existTracks.Count == 0)
{ {
_logger.LogInformation("订单不存在轨迹,不允许修改:{@event}", @event); _logger.LogInformation("订单不存在轨迹,不允许修改:{@event}", @event);
activity.SetTag("errorMsg", "订单不存在轨迹,不允许修改");
activity.SetTag("@event", @event);
continue; continue;
} }
if (existTracks.Count > 1) if (existTracks.Count > 1)
{ {
_logger.LogInformation("订单存在多条轨迹不允许修改:{@event}", @event); _logger.LogInformation("订单存在多条轨迹不允许修改:{@event}", @event);
activity.SetTag("errorMsg", "订单存在多条轨迹不允许修改");
activity.SetTag("@event", @event);
continue; continue;
} }

View File

@ -1,5 +1,7 @@
using DotNetCore.CAP; using DotNetCore.CAP;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.OTel;
using SJZY.Track.Application.Contract.Dtos.ProvideServices; using SJZY.Track.Application.Contract.Dtos.ProvideServices;
using SJZY.Track.Application.Contract.Events; using SJZY.Track.Application.Contract.Events;
using SJZY.Track.Application.Contract.Services.ProvideServices; using SJZY.Track.Application.Contract.Services.ProvideServices;
@ -265,6 +267,8 @@ public partial class TrackService : ApplicationService, ITrackService
[HttpPost("Track/Upsert")] [HttpPost("Track/Upsert")]
public async Task<UnifyResultDto> UpsertTrackAsync(UpsertTrackInput input) public async Task<UnifyResultDto> UpsertTrackAsync(UpsertTrackInput input)
{ {
using var activity = ActivityHelper.CreateSpanActivity("UpsertTrack");
activity.SetTag("UpsertTrackInput", input.ToJson());
var order = await _orderRepository.GetFirstAsync(x => var order = await _orderRepository.GetFirstAsync(x =>
x.SubSystemId == input.SubSystemId x.SubSystemId == input.SubSystemId
&& x.OrderType == input.OrderType && x.OrderType == input.OrderType
@ -338,6 +342,8 @@ public partial class TrackService : ApplicationService, ITrackService
[HttpPost("Track/BatchUpsert")] [HttpPost("Track/BatchUpsert")]
public async Task<UnifyResultDto> BatchUpsertTrackAsync(BatchUpsertTrackInput input) public async Task<UnifyResultDto> BatchUpsertTrackAsync(BatchUpsertTrackInput input)
{ {
using var activity = ActivityHelper.CreateSpanActivity("BatchUpsert");
activity.SetTag("BatchUpsertTrackInput", input.ToJson());
input.OrderNos = input.OrderNos.Where(x => !x.IsNullOrWhiteSpace()).Distinct().ToList(); // 单号去重、去空 input.OrderNos = input.OrderNos.Where(x => !x.IsNullOrWhiteSpace()).Distinct().ToList(); // 单号去重、去空
var orders = await _orderRepository.GetListAsync(x => var orders = await _orderRepository.GetListAsync(x =>
x.SubSystemId == input.SubSystemId x.SubSystemId == input.SubSystemId