Skip to content

Commit e3163be

Browse files
bmermetEmanuele Palazzetti
authored andcommitted
Add close method on Scope (#32)
1 parent 540d9de commit e3163be

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/Datadog.Trace.Tests/TracerTests.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,19 @@ public void StartActive_FinishOnClose_SpanIsFinishedWhenScopeIsClosed()
6666
var scope = _tracer.StartActive("Operation");
6767
Assert.False(scope.Span.IsFinished);
6868

69-
scope.Dispose();
69+
scope.Close();
70+
71+
Assert.True(scope.Span.IsFinished);
72+
Assert.Null(_tracer.ActiveScope);
73+
}
74+
75+
[Fact]
76+
public void StartActive_FinishOnClose_SpanIsFinishedWhenScopeIsDisposed()
77+
{
78+
Scope scope;
79+
using(scope = _tracer.StartActive("Operation")){
80+
Assert.False(scope.Span.IsFinished);
81+
}
7082

7183
Assert.True(scope.Span.IsFinished);
7284
Assert.Null(_tracer.ActiveScope);

src/Datadog.Trace/Implementations/Scope.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,21 @@ internal Scope(Scope parent, Span span, AsyncLocalScopeManager scopeManager, bo
3131
/// <summary>
3232
/// Closes the current scope and makes its parent scope active
3333
/// </summary>
34-
public void Dispose()
34+
public void Close()
3535
{
3636
_scopeManager.Close(this);
3737
if (_finishOnClose)
3838
{
3939
Span.Finish();
4040
}
4141
}
42+
43+
/// <summary>
44+
/// Closes the current scope and makes its parent scope active
45+
/// </summary>
46+
public void Dispose()
47+
{
48+
Close();
49+
}
4250
}
4351
}

0 commit comments

Comments
 (0)