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

remove test.code empty #192

Merged
merged 2 commits into from
Mar 13, 2020
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
2 changes: 1 addition & 1 deletion ast/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func GetFuncSource(pc uintptr) (*MethodCodeBoundaries, error) {

func getCodesForFile(file string) (map[string]*MethodCodeBoundaries, error) {
mutex.Lock()
defer mutex.Unlock()
if methodCodes == nil {
methodCodes = map[string]map[string]*MethodCodeBoundaries{}
}
Expand Down Expand Up @@ -99,6 +100,5 @@ func getCodesForFile(file string) (map[string]*MethodCodeBoundaries, error) {
}
}
}
mutex.Unlock()
return methodCodes[file], nil
}
21 changes: 10 additions & 11 deletions instrumentation/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,26 @@ func StartTestFromCaller(t *testing.T, pc uintptr, opts ...Option) *Test {
}
packageName := funcFullName[:funcNameIndex-1]

sourceBounds, _ := ast.GetFuncSourceForName(pc, funcName)
var testCode string
if sourceBounds != nil {
testCode = fmt.Sprintf("%s:%d:%d", sourceBounds.File, sourceBounds.Start.Line, sourceBounds.End.Line)
}

var startOptions []opentracing.StartSpanOption
startOptions = append(startOptions, opentracing.Tags{
testTags := opentracing.Tags{
"span.kind": "test",
"test.name": fullTestName,
"test.suite": packageName,
"test.code": testCode,
"test.framework": "testing",
"test.language": "go",
})
}
sourceBounds, sErr := ast.GetFuncSourceForName(pc, funcName)
if sErr != nil {
instrumentation.Logger().Printf("error calculating the source boundaries for '%s [%s]': %v", funcName, funcFullName, sErr)
}
if sourceBounds != nil {
testTags["test.code"] = fmt.Sprintf("%s:%d:%d", sourceBounds.File, sourceBounds.Start.Line, sourceBounds.End.Line)
}

if test.ctx == nil {
test.ctx = context.Background()
}

span, ctx := opentracing.StartSpanFromContextWithTracer(test.ctx, instrumentation.Tracer(), fullTestName, startOptions...)
span, ctx := opentracing.StartSpanFromContextWithTracer(test.ctx, instrumentation.Tracer(), fullTestName, testTags)
span.SetBaggageItem("trace.kind", "test")
test.span = span
test.ctx = ctx
Expand Down