From e3d9a02a6db188d9022543befa547fe20d5e49f0 Mon Sep 17 00:00:00 2001 From: Ion Bazan Date: Mon, 5 Oct 2020 23:36:57 +0800 Subject: [PATCH] Fix missing source code excerpts for stacktrace frames when the absolute file path is equal to the stripped file path (#1104) Co-authored-by: Stefano Arlandini --- CHANGELOG.md | 2 ++ src/FrameBuilder.php | 2 +- src/StacktraceBuilder.php | 2 +- tests/FrameBuilderTest.php | 14 +++++++------- tests/StacktraceBuilderTest.php | 2 ++ 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4903a1479..81f70974f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Fix missing source code excerpts for stacktrace frames whose absolute file path is equal to the file path (#1104) + ## 3.0.2 (2020-10-02) - fix: Use the traces sample rate for traces instead of the event sample rate (#1106) diff --git a/src/FrameBuilder.php b/src/FrameBuilder.php index 5bbb40b80..21659f585 100644 --- a/src/FrameBuilder.php +++ b/src/FrameBuilder.php @@ -84,7 +84,7 @@ public function buildFromBacktraceFrame(string $file, int $line, array $backtrac $strippedFilePath, $line, $rawFunctionName, - Frame::INTERNAL_FRAME_FILENAME !== $file && $strippedFilePath !== $file ? $file : null, + Frame::INTERNAL_FRAME_FILENAME !== $file ? $file : null, $this->getFunctionArguments($backtraceFrame), $this->isFrameInApp($file, $functionName) ); diff --git a/src/StacktraceBuilder.php b/src/StacktraceBuilder.php index fc4b66c8d..d48b2cdf5 100644 --- a/src/StacktraceBuilder.php +++ b/src/StacktraceBuilder.php @@ -70,7 +70,7 @@ public function buildFromBacktrace(array $backtrace, string $file, int $line): S } // Add a final stackframe for the first method ever of this stacktrace - array_unshift($frames, new Frame(null, $file, $line)); + array_unshift($frames, $this->frameBuilder->buildFromBacktraceFrame($file, $line, [])); return new Stacktrace($frames); } diff --git a/tests/FrameBuilderTest.php b/tests/FrameBuilderTest.php index b73dd3696..2d0e6e1ec 100644 --- a/tests/FrameBuilderTest.php +++ b/tests/FrameBuilderTest.php @@ -36,7 +36,7 @@ public function buildFromBacktraceFrameDataProvider(): \Generator 'line' => 20, 'function' => 'test_function', ], - new Frame('test_function', '/path/to/file', 10), + new Frame('test_function', '/path/to/file', 10, null, '/path/to/file'), ]; yield [ @@ -46,7 +46,7 @@ public function buildFromBacktraceFrameDataProvider(): \Generator 'line' => 20, 'function' => 'test_function', ], - new Frame('test_function', '/path/to/file', 10), + new Frame('test_function', '/path/to/file', 10, null, '/path/to/file'), ]; yield [ @@ -57,7 +57,7 @@ public function buildFromBacktraceFrameDataProvider(): \Generator 'function' => 'test_function', 'class' => 'TestClass', ], - new Frame('TestClass::test_function', '/path/to/file', 10, 'TestClass::test_function'), + new Frame('TestClass::test_function', '/path/to/file', 10, 'TestClass::test_function', '/path/to/file'), ]; yield [ @@ -67,7 +67,7 @@ public function buildFromBacktraceFrameDataProvider(): \Generator 'line' => 10, 'function' => 'test_function', ], - new Frame('test_function', '/path/to/file', 10), + new Frame('test_function', '/path/to/file', 10, null, '/path/to/file'), ]; yield [ @@ -78,7 +78,7 @@ public function buildFromBacktraceFrameDataProvider(): \Generator 'function' => 'test_function', 'class' => "class@anonymous\0/path/to/file", ], - new Frame("class@anonymous\0/path/to/file::test_function", '/path/to/file', 10, "class@anonymous\0/path/to/file::test_function"), + new Frame("class@anonymous\0/path/to/file::test_function", '/path/to/file', 10, "class@anonymous\0/path/to/file::test_function", '/path/to/file'), ]; yield [ @@ -133,7 +133,7 @@ public function buildFromBacktraceFrameDataProvider(): \Generator 'file' => 'path/not/of/app/path/to/file', 'line' => 10, ], - new Frame(null, 'path/not/of/app/path/to/file', 10, null), + new Frame(null, 'path/not/of/app/path/to/file', 10, null, 'path/not/of/app/path/to/file'), ]; yield [ @@ -147,7 +147,7 @@ public function buildFromBacktraceFrameDataProvider(): \Generator 'file' => 'path/not/of/app/to/file', 'line' => 10, ], - new Frame(null, 'path/not/of/app/to/file', 10, null), + new Frame(null, 'path/not/of/app/to/file', 10, null, 'path/not/of/app/to/file'), ]; } diff --git a/tests/StacktraceBuilderTest.php b/tests/StacktraceBuilderTest.php index 1e8f0dccf..544919063 100644 --- a/tests/StacktraceBuilderTest.php +++ b/tests/StacktraceBuilderTest.php @@ -38,10 +38,12 @@ public function testBuildFromBacktrace(): void $this->assertNull($frames[0]->getFunctionName()); $this->assertSame('/in/jXVmi', $frames[0]->getFile()); + $this->assertSame('/in/jXVmi', $frames[0]->getAbsoluteFilePath()); $this->assertSame(5, $frames[0]->getLine()); $this->assertSame('{closure}', $frames[1]->getFunctionName()); $this->assertSame('/in/jXVmi', $frames[1]->getFile()); + $this->assertSame('/in/jXVmi', $frames[1]->getAbsoluteFilePath()); $this->assertSame(9, $frames[1]->getLine()); $this->assertSame('main', $frames[2]->getFunctionName());