Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Add file filter that can alter file names used in stack traces #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions stacktrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ import (
"sync"
)

var (
// FileFilter is a function that alters the file names reported in stack
// traces.
//
// It is mostly useful when an app has different build and runtime
// locations (e.g. apps deployed on Heroku), to make sure that source
// files are correct at runtime, which allows stacktraces to have a
// correct context.
//
// This is nil by default, which means that it does nothing.
FileFilter func(string) string
)

// https://docs.getsentry.com/hosted/clientdev/interfaces/#failure-interfaces
type Stacktrace struct {
// Required
Expand Down Expand Up @@ -64,6 +77,9 @@ func NewStacktrace(skip int, context int, appPackagePrefixes []string) *Stacktra
if !ok {
break
}
if FileFilter != nil {
file = FileFilter(file)
}
frame := NewStacktraceFrame(pc, file, line, context, appPackagePrefixes)
if frame != nil {
frames = append(frames, frame)
Expand Down