Skip to content

Commit

Permalink
[fix] 修正SpanBuilder对象池借出Builder时,未设置Tracer的问题,该问题导致从池里借出来的Builder创建Sp…
Browse files Browse the repository at this point in the history
…an时都没有Tracer,从而无法向上汇总统计
  • Loading branch information
nnhy committed Dec 4, 2024
1 parent 4d2fc34 commit 31357d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions NewLife.Core/Log/ISpanBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@ public DefaultSpanBuilder() { }
/// <param name="name"></param>
public DefaultSpanBuilder(ITracer tracer, String name)
{
Tracer = tracer;

Init(name);
Init(tracer, name);
}
#endregion

#region 方法
/// <summary>初始化。重用已有对象</summary>
/// <param name="tracer"></param>
/// <param name="name"></param>
public void Init(String name)
public void Init(ITracer tracer, String name)
{
Tracer = tracer;
Name = name;
MinCost = -1;
StartTime = DateTime.UtcNow.ToLong();
Expand Down Expand Up @@ -241,7 +241,7 @@ internal void Return(IList<ISpan>? spans)
public void Clear()
{
//!!! 不能清空Tracer,否则长时间Span完成时,Builder已被处理,Span无法创建新的Builder来统计埋点数据
Tracer = null;
//Tracer = null;

Name = null!;
StartTime = 0;
Expand Down
2 changes: 1 addition & 1 deletion NewLife.Core/Log/ITracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ protected virtual ISpanBuilder OnBuildSpan(String name)
{
var builder = BuilderPool.Get();
if (builder is DefaultSpanBuilder dsb)
dsb.Init(name);
dsb.Init(this, name);
else
builder.Name = name;

Expand Down

0 comments on commit 31357d2

Please sign in to comment.