diff --git a/agent/agent.go b/agent/agent.go index b6a0803b..2929c922 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -8,6 +8,7 @@ import ( "net/url" "os" "path" + "path/filepath" "runtime" "strings" "sync" @@ -260,7 +261,7 @@ func NewAgent(options ...Option) (*Agent, error) { // Current folder wd, _ := os.Getwd() - agent.metadata[tags.CurrentFolder] = wd + agent.metadata[tags.CurrentFolder] = filepath.Clean(wd) // Hostname hostname, _ := os.Hostname() @@ -292,7 +293,9 @@ func NewAgent(options ...Option) (*Agent, error) { // Expand '~' in source root if sRoot, ok := agent.metadata[tags.SourceRoot]; ok { - if sRootEx, err := homedir.Expand(sRoot.(string)); err == nil { + cSRoot := sRoot.(string) + cSRoot = filepath.Clean(cSRoot) + if sRootEx, err := homedir.Expand(cSRoot); err == nil { agent.metadata[tags.SourceRoot] = sRootEx } } diff --git a/ast/sources.go b/ast/sources.go index 11cfb42b..a85fee45 100644 --- a/ast/sources.go +++ b/ast/sources.go @@ -4,6 +4,7 @@ import ( "go/ast" "go/parser" "go/token" + "path/filepath" "runtime" "strings" "sync" @@ -36,6 +37,7 @@ func GetFuncSourceFromCaller(skip int) (*MethodCodeBoundaries, error) { func GetFuncSourceForName(pc uintptr, name string) (*MethodCodeBoundaries, error) { mFunc := runtime.FuncForPC(pc) mFile, _ := mFunc.FileLine(pc) + mFile = filepath.Clean(mFile) fileCode, err := getCodesForFile(mFile) if err != nil { return nil, err @@ -47,6 +49,7 @@ func GetFuncSourceForName(pc uintptr, name string) (*MethodCodeBoundaries, error func GetFuncSource(pc uintptr) (*MethodCodeBoundaries, error) { mFunc := runtime.FuncForPC(pc) mFile, _ := mFunc.FileLine(pc) + mFile = filepath.Clean(mFile) fileCode, err := getCodesForFile(mFile) if err != nil { return nil, err diff --git a/instrumentation/logging/logger.go b/instrumentation/logging/logger.go index 1dfdce02..d9e95fcb 100644 --- a/instrumentation/logging/logger.go +++ b/instrumentation/logging/logger.go @@ -4,6 +4,7 @@ import ( "fmt" "io" stdlog "log" + "path/filepath" "regexp" "sync" "time" @@ -167,6 +168,7 @@ func (w *otWriter) storeLogRecord(item *logItem) { log.String(tags.EventMessage, item.message), } if item.file != "" && item.lineNumber != "" { + item.file = filepath.Clean(item.file) fields = append(fields, log.String(tags.EventSource, fmt.Sprintf("%s:%s", item.file, item.lineNumber))) } w.logRecords = append(w.logRecords, opentracing.LogRecord{ diff --git a/instrumentation/testing/tb.go b/instrumentation/testing/tb.go index 61041dea..b1a2f503 100644 --- a/instrumentation/testing/tb.go +++ b/instrumentation/testing/tb.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/opentracing/opentracing-go/log" "go.undefinedlabs.com/scopeagent/tags" + "path/filepath" "runtime" ) @@ -224,10 +225,12 @@ func getSourceFileAndNumber() string { if isAPatchPointer(pcEntry) { // The monkey patching version adds 4 frames to the stack. if _, file, line, ok := runtime.Caller(6); ok == true { + file = filepath.Clean(file) source = fmt.Sprintf("%s:%d", file, line) } } else { // If we don't have monkey patching then we skip 2 frames + file = filepath.Clean(file) source = fmt.Sprintf("%s:%d", file, line) } }