Skip to content

Commit 188eb7d

Browse files
committed
feat: set backtrace frame context
1 parent 40958f5 commit 188eb7d

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/Honeybadger/NoticeHelpers/ErrorFactory.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class ErrorFactory
77
{
88
public static Error Get(StackTrace stackTrace, string message, string? className = null)
99
{
10-
var @class = className ?? stackTrace.GetFrame(0)?.GetMethod()?.DeclaringType?.FullName ?? "CLASS";
10+
var @class = className ?? stackTrace.GetFrame(0)?.GetMethod()?.DeclaringType?.FullName ?? "CLASS";
1111
return new Error(@class, message, GetBacktraces(stackTrace))
1212
{
1313
Fingerprint = null, // todo
@@ -33,10 +33,22 @@ private static ErrorBacktrace[] GetBacktraces(StackTrace stackTrace)
3333
File = sf.GetFileName(),
3434
Number = sf.GetFileLineNumber().ToString(),
3535
Method = sf.GetMethod()?.Name,
36-
Context = null, // todo
36+
Context = DetermineContext(sf.GetFileName(), HoneybadgerClient.Current?.Options?.ProjectRoot),
3737
});
3838
}
3939

4040
return result.ToArray();
4141
}
42-
}
42+
43+
private static string DetermineContext(string? fileName, string? projectRoot)
44+
{
45+
if (!string.IsNullOrEmpty(projectRoot) &&
46+
!string.IsNullOrEmpty(fileName) &&
47+
fileName.StartsWith(projectRoot))
48+
{
49+
return "app";
50+
}
51+
52+
return "all";
53+
}
54+
}

0 commit comments

Comments
 (0)