-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(stacktrace): support package name parsing for Go 1.20+ (#730)
- Loading branch information
Showing
5 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//go:build !go1.20 | ||
|
||
package sentry | ||
|
||
import "strings" | ||
|
||
func isCompilerGeneratedSymbol(name string) bool { | ||
// In versions of Go below 1.20 a prefix of "type." and "go." is a | ||
// compiler-generated symbol that doesn't belong to any package. | ||
// See variable reservedimports in cmd/compile/internal/gc/subr.go | ||
if strings.HasPrefix(name, "go.") || strings.HasPrefix(name, "type.") { | ||
return true | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//go:build !go1.20 | ||
|
||
package sentry | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestFilterCompilerGeneratedSymbols(t *testing.T) { | ||
tests := []struct { | ||
symbol string | ||
expectedPackageName string | ||
}{ | ||
{"type..eq.[9]debug/elf.intName", ""}, | ||
{"type..hash.debug/elf.ProgHeader", ""}, | ||
{"type..eq.runtime._panic", ""}, | ||
{"type..hash.struct { runtime.gList; runtime.n int32 }", ""}, | ||
{"go.(*struct { sync.Mutex; math/big.table [64]math/big", ""}, | ||
{"github.com/getsentry/sentry-go.Test.func2.1.1", "github.com/getsentry/sentry-go"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.symbol, func(t *testing.T) { | ||
packageName := packageName(tt.symbol) | ||
if diff := cmp.Diff(tt.expectedPackageName, packageName); diff != "" { | ||
t.Errorf("Package name mismatch (-want +got):\n%s", diff) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//go:build go1.20 | ||
|
||
package sentry | ||
|
||
import "strings" | ||
|
||
func isCompilerGeneratedSymbol(name string) bool { | ||
// In versions of Go 1.20 and above a prefix of "type:" and "go:" is a | ||
// compiler-generated symbol that doesn't belong to any package. | ||
// See variable reservedimports in cmd/compile/internal/gc/subr.go | ||
if strings.HasPrefix(name, "go:") || strings.HasPrefix(name, "type:") { | ||
return true | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//go:build go1.20 | ||
|
||
package sentry | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestFilterCompilerGeneratedSymbols(t *testing.T) { | ||
tests := []struct { | ||
symbol string | ||
expectedPackageName string | ||
}{ | ||
{"type:.eq.[9]debug/elf.intName", ""}, | ||
{"type:.hash.debug/elf.ProgHeader", ""}, | ||
{"type:.eq.runtime._panic", ""}, | ||
{"type:.hash.struct { runtime.gList; runtime.n int32 }", ""}, | ||
{"go:(*struct { sync.Mutex; math/big.table [64]math/big", ""}, | ||
{"go.uber.org/zap/buffer.(*Buffer).AppendString", "go.uber.org/zap/buffer"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.symbol, func(t *testing.T) { | ||
packageName := packageName(tt.symbol) | ||
if diff := cmp.Diff(tt.expectedPackageName, packageName); diff != "" { | ||
t.Errorf("Package name mismatch (-want +got):\n%s", diff) | ||
} | ||
}) | ||
} | ||
} |