From 008e26bf70a89e5cb8d056435aabbab9fcbc73f0 Mon Sep 17 00:00:00 2001 From: Thomas Jost Date: Wed, 23 Nov 2016 11:21:13 +0100 Subject: [PATCH] Add file filter that can alter file names used in stack traces --- stacktrace.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/stacktrace.go b/stacktrace.go index 81ca3af..f992b0f 100644 --- a/stacktrace.go +++ b/stacktrace.go @@ -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 @@ -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)