Skip to content

Commit

Permalink
refactor: ♻️ 异常请求输出追踪标识
Browse files Browse the repository at this point in the history
  • Loading branch information
tk authored and nsnail committed Dec 19, 2024
1 parent 93fe9e4 commit ce69758
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions assets/res/NetAdmin.Fields.ln
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@
请求方式
请求日志导出
调试
跟踪
跟踪标识
追踪
追踪标识
身份证
运行
通知
Expand Down
2 changes: 1 addition & 1 deletion refs/Gurion
2 changes: 1 addition & 1 deletion refs/NetAdmin.FreeSql
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public record Sys_RequestLog : SimpleEntity, IFieldCreatedTime, IFieldOwner, IFi
public virtual long? OwnerId { get; init; }

/// <summary>
/// 请求跟踪标识
/// 请求追踪标识
/// </summary>
[Column]
[CsvIgnore]
Expand Down
5 changes: 5 additions & 0 deletions src/backend/NetAdmin/NetAdmin.Domain/Dto/RestfulInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public record RestfulInfo<T> : DataAbstraction
/// </summary>
/// <example>请求成功</example>
public object Msg { get; init; }

/// <summary>
/// 追踪标识
/// </summary>
public Guid? TraceId { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ public sealed record ExportRequestLogRsp : QueryRequestLogRsp
/// <inheritdoc />
[CsvIndex(7)]
[CsvIgnore(false)]
[CsvName(nameof(Ln.跟踪标识))]
[CsvName(nameof(Ln.追踪标识))]
public override Guid TraceId { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public IActionResult OnException(ExceptionContext context, ExceptionMetadata met
var result = RestfulResult(errorCode, metadata.Data
, naException is NetAdminValidateException vEx
? vEx.ValidateResults
: naException?.Message ?? errorCode.ResDesc<ErrorCodes>());
: naException?.Message ?? errorCode.ResDesc<ErrorCodes>(), context.HttpContext.GetTraceId());

SetErrorCodeToHeader(context.HttpContext, errorCode);

Expand Down Expand Up @@ -95,9 +95,9 @@ private static object GetValidationResult(object validationResult)
/// <summary>
/// 返回 RESTful 风格结果集
/// </summary>
private static T RestfulResult(ErrorCodes errorCode, object data = default, object message = default)
private static T RestfulResult(ErrorCodes errorCode, object data = null, object message = null, Guid? traceId = null)
{
return new T { Code = errorCode, Data = data, Msg = message };
return new T { Code = errorCode, Data = data, Msg = message, TraceId = traceId };
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace NetAdmin.Infrastructure.Enums;
public enum LogLevels
{
/// <summary>
/// 跟踪
/// 追踪
/// </summary>
[Display(Name = "[gray]TCE[/]", ShortName = "TCE")]
[ResourceDescription<Ln>(nameof(Ln.跟踪))]
[ResourceDescription<Ln>(nameof(Ln.追踪))]
Trace = 0

,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static IPAddress GetRealIpAddress(this HttpContext me)
}

/// <summary>
/// 获取跟踪标识
/// 获取追踪标识
/// </summary>
public static Guid GetTraceId(this HttpContext me)
{
Expand Down

0 comments on commit ce69758

Please sign in to comment.