Skip to content

Commit

Permalink
Add Package to the frame when creating stacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
grongor committed Sep 1, 2021
1 parent 5afc225 commit 95a10e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion stacktrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,24 @@ func NewFrame(f runtime.Frame) Frame {
}

function := f.Function
var pkg string
var pkg, lastSubpkg string

if function != "" {
pkg, function = splitQualifiedFunctionName(function)
}

if lastSlashIndex := strings.LastIndexByte(pkg, '/'); lastSlashIndex != -1 {
lastSubpkg = pkg[lastSlashIndex+1:]
} else {
lastSubpkg = pkg
}

frame := Frame{
AbsPath: abspath,
Filename: relpath,
Lineno: f.Line,
Module: pkg,
Package: lastSubpkg,
Function: function,
}

Expand Down
13 changes: 13 additions & 0 deletions stacktrace_external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestNewStacktrace(t *testing.T) {
{
Function: "f1",
Module: "github.com/getsentry/sentry-go_test",
Package: "sentry-go_test",
Lineno: 18,
InApp: true,
},
Expand All @@ -70,12 +71,14 @@ func TestNewStacktrace(t *testing.T) {
{
Function: "f2",
Module: "github.com/getsentry/sentry-go_test",
Package: "sentry-go_test",
Lineno: 22,
InApp: true,
},
{
Function: "f1",
Module: "github.com/getsentry/sentry-go_test",
Package: "sentry-go_test",
Lineno: 18,
InApp: true,
},
Expand All @@ -91,6 +94,7 @@ func TestNewStacktrace(t *testing.T) {
{
Function: "f3",
Module: "github.com/getsentry/sentry-go_test",
Package: "sentry-go_test",
Lineno: 25,
InApp: true,
},
Expand Down Expand Up @@ -120,12 +124,14 @@ func TestExtractStacktrace(t *testing.T) {
{
Function: "RedPkgErrorsRanger",
Module: "github.com/getsentry/sentry-go_test",
Package: "sentry-go_test",
Lineno: 29,
InApp: true,
},
{
Function: "BluePkgErrorsRanger",
Module: "github.com/getsentry/sentry-go_test",
Package: "sentry-go_test",
Lineno: 33,
InApp: true,
},
Expand All @@ -137,12 +143,14 @@ func TestExtractStacktrace(t *testing.T) {
{
Function: "RedPingcapErrorsRanger",
Module: "github.com/getsentry/sentry-go_test",
Package: "sentry-go_test",
Lineno: 37,
InApp: true,
},
{
Function: "BluePingcapErrorsRanger",
Module: "github.com/getsentry/sentry-go_test",
Package: "sentry-go_test",
Lineno: 41,
InApp: true,
},
Expand All @@ -154,12 +162,14 @@ func TestExtractStacktrace(t *testing.T) {
{
Function: "RedGoErrorsRanger",
Module: "github.com/getsentry/sentry-go_test",
Package: "sentry-go_test",
Lineno: 45,
InApp: true,
},
{
Function: "BlueGoErrorsRanger",
Module: "github.com/getsentry/sentry-go_test",
Package: "sentry-go_test",
Lineno: 49,
InApp: true,
},
Expand All @@ -185,6 +195,7 @@ func TestExtractStacktrace(t *testing.T) {
// {
// Function: "TestExtractStacktrace.func1",
// Module: "github.com/getsentry/sentry-go_test",
// Package: "sentry-go_test",
// Lineno: 178,
// InApp: true,
// },
Expand All @@ -205,6 +216,7 @@ func TestExtractStacktrace(t *testing.T) {
// {
// Function: "TestExtractStacktrace.func2",
// Module: "github.com/getsentry/sentry-go_test",
// Package: "sentry-go_test",
// Lineno: 198,
// InApp: true,
// },
Expand All @@ -225,6 +237,7 @@ func TestExtractStacktrace(t *testing.T) {
// {
// Function: "TestExtractStacktrace.func3",
// Module: "github.com/getsentry/sentry-go_test",
// Package: "sentry-go_test",
// Lineno: 218,
// InApp: true,
// },
Expand Down

0 comments on commit 95a10e7

Please sign in to comment.