Skip to content
This repository was archived by the owner on Aug 17, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/url"
"os"
"path"
"path/filepath"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
}
Expand Down
3 changes: 3 additions & 0 deletions ast/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"go/ast"
"go/parser"
"go/token"
"path/filepath"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions instrumentation/logging/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
stdlog "log"
"path/filepath"
"regexp"
"sync"
"time"
Expand Down Expand Up @@ -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{
Expand Down
3 changes: 3 additions & 0 deletions instrumentation/testing/tb.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/opentracing/opentracing-go/log"
"go.undefinedlabs.com/scopeagent/tags"
"path/filepath"
"runtime"
)

Expand Down Expand Up @@ -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)
}
}
Expand Down