Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set absolute path when stripping project path on stack frame #2117

Merged
merged 12 commits into from
Jan 13, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Fix unhandled exception not captured when hub disabled ([#2103](https://github.com/getsentry/sentry-dotnet/pull/2103))
- Fix Android support for Portable PDB format when app uses split APKs ([#2108](https://github.com/getsentry/sentry-dotnet/pull/2108))
- Fix session ending as crashed for unobserved task exceptions ([#2112](https://github.com/getsentry/sentry-dotnet/pull/2112))
- Set absolute path when stripping project path on stack frame ([#2117](https://github.com/getsentry/sentry-dotnet/pull/2117))

## 3.25.0

Expand Down
1 change: 1 addition & 0 deletions src/Sentry/Internal/DebugStackTrace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ private SentryStackFrame InternalCreateFrame(StackFrame stackFrame, bool demangl
{
if (projectPath != null && frameFileName.StartsWith(projectPath, StringComparison.OrdinalIgnoreCase))
{
frame.AbsolutePath = frameFileName;
frameFileName = frameFileName.Substring(projectPath.Length);
}
frame.FileName = frameFileName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
FileName: Internals/SentryStackTraceFactoryTests.cs,
Function: void SentryStackTraceFactoryTests.GenericMethodThatThrows<T>(T value),
AbsolutePath: {ProjectDirectory}Internals/SentryStackTraceFactoryTests.cs,
InApp: true,
AddressMode: rel:0
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
FileName: Internals/SentryStackTraceFactoryTests.cs,
Function: GenericMethodThatThrows,
Module: Other.Tests.Internals.SentryStackTraceFactoryTests,
AbsolutePath: {ProjectDirectory}Internals/SentryStackTraceFactoryTests.cs,
InApp: true,
AddressMode: rel:0
}
18 changes: 14 additions & 4 deletions test/Sentry.Tests/Internals/SentryStackTraceFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,26 @@ public void FileNameShouldBeRelative()
exception = e;
}

var expected = Path.Combine("Internals", "SentryStackTraceFactoryTests.cs");
var path = sut.Create(exception)?.Frames[0].FileName;
var stackTrace = sut.Create(exception);

Assert.NotNull(stackTrace);

var frame = stackTrace.Frames[0];

#if __MOBILE__
// We don't get file paths on mobile unless we've got a debugger attached.
Skip.If(string.IsNullOrEmpty(path));
Skip.If(string.IsNullOrEmpty(frame.FileName));
#endif
Assert.Equal(expected, path);

var path = Path.Combine("Internals", "SentryStackTraceFactoryTests.cs");
Assert.Equal(path, frame.FileName);

var fullPath = GetThisFilePath();
Assert.Equal(fullPath, frame.AbsolutePath);
}

private static string GetThisFilePath([CallerFilePath] string path = null) => path;

[Theory]
[InlineData(StackTraceMode.Original, "ByRefMethodThatThrows")]
[InlineData(StackTraceMode.Enhanced, "(Fixture f, int b) SentryStackTraceFactoryTests.ByRefMethodThatThrows(int value, in int valueIn, ref int valueRef, out int valueOut)")]
Expand Down