Skip to content

Commit a506a35

Browse files
authored
Improve test source start line for CI Visibility UI. (#3755)
1 parent 719ab6c commit a506a35

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

tracer/src/Datadog.Trace/Ci/Test.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,20 @@ public void SetTestMethodInfo(MethodInfo methodInfo)
136136
{
137137
if (MethodSymbolResolver.Instance.TryGetMethodSymbol(methodInfo, out var methodSymbol))
138138
{
139+
var startLine = methodSymbol.StartLine;
140+
// startline refers to the first instruction of method body.
141+
// In order to improve the source code in the CI Visibility UI, we decrease
142+
// this value by 2 so <bold>most of the time</bold> will show the missing
143+
// `{` char and the method signature.
144+
// There's no an easy way to extract the correct startline number.
145+
if (startLine > 1)
146+
{
147+
startLine -= 2;
148+
}
149+
139150
var tags = (TestSpanTags)_scope.Span.Tags;
140151
tags.SourceFile = CIEnvironmentValues.Instance.MakeRelativePathFromSourceRoot(methodSymbol.File, false);
141-
tags.SourceStart = methodSymbol.StartLine;
152+
tags.SourceStart = startLine;
142153
tags.SourceEnd = methodSymbol.EndLine;
143154

144155
if (CIEnvironmentValues.Instance.CodeOwners is { } codeOwners)

0 commit comments

Comments
 (0)