mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 11:59:00 +08:00
Use runtime.CallersFrames to get more detailed stack information (#8868)
Signed-off-by: dragondriver <jiquan.long@zilliz.com>
This commit is contained in:
parent
7094722fb0
commit
3636ade689
@ -88,8 +88,9 @@ func StartSpanFromContextWithSkip(ctx context.Context, skip int, opts ...opentra
|
||||
span.LogFields(log.Error(errors.New("runtime.Callers failed")))
|
||||
return span, ctx
|
||||
}
|
||||
fn := runtime.FuncForPC(pcs[0])
|
||||
name := fn.Name()
|
||||
frames := runtime.CallersFrames(pcs[:])
|
||||
frame, _ := frames.Next()
|
||||
name := frame.Function
|
||||
if lastSlash := strings.LastIndexByte(name, '/'); lastSlash > 0 {
|
||||
name = name[lastSlash+1:]
|
||||
}
|
||||
@ -99,7 +100,7 @@ func StartSpanFromContextWithSkip(ctx context.Context, skip int, opts ...opentra
|
||||
}
|
||||
span := opentracing.StartSpan(name, opts...)
|
||||
|
||||
file, line := fn.FileLine(pcs[0])
|
||||
file, line := frame.File, frame.Line
|
||||
span.LogFields(log.String("filename", file), log.Int("line", line))
|
||||
|
||||
return span, opentracing.ContextWithSpan(ctx, span)
|
||||
@ -125,7 +126,9 @@ func StartSpanFromContextWithOperationNameWithSkip(ctx context.Context, operatio
|
||||
span.LogFields(log.Error(errors.New("runtime.Callers failed")))
|
||||
return span, ctx
|
||||
}
|
||||
file, line := runtime.FuncForPC(pcs[0]).FileLine(pcs[0])
|
||||
frames := runtime.CallersFrames(pcs[:])
|
||||
frame, _ := frames.Next()
|
||||
file, line := frame.File, frame.Line
|
||||
|
||||
if parentSpan := opentracing.SpanFromContext(ctx); parentSpan != nil {
|
||||
opts = append(opts, opentracing.ChildOf(parentSpan.Context()))
|
||||
@ -153,7 +156,9 @@ func LogError(span opentracing.Span, err error) error {
|
||||
return err
|
||||
}
|
||||
|
||||
file, line := runtime.FuncForPC(pcs[0]).FileLine(pcs[0])
|
||||
frames := runtime.CallersFrames(pcs[:])
|
||||
frame, _ := frames.Next()
|
||||
file, line := frame.File, frame.Line
|
||||
span.LogFields(log.String("filename", file), log.Int("line", line), log.Error(err))
|
||||
|
||||
return err
|
||||
|
@ -14,6 +14,7 @@ package trace
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"errors"
|
||||
@ -28,16 +29,18 @@ type simpleStruct struct {
|
||||
value string
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
closer := InitTracing("test")
|
||||
defer closer.Close()
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestInit(t *testing.T) {
|
||||
cfg := initFromEnv("test")
|
||||
assert.NotNil(t, cfg)
|
||||
}
|
||||
|
||||
func TestTracing(t *testing.T) {
|
||||
//Already Init in each framework, this can be ignored in debug
|
||||
closer := InitTracing("test")
|
||||
defer closer.Close()
|
||||
|
||||
// context normally can be propagated through func params
|
||||
ctx := context.Background()
|
||||
|
||||
@ -88,10 +91,6 @@ func caller(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func TestInject(t *testing.T) {
|
||||
//Already Init in each framework, this can be ignored in debug
|
||||
closer := InitTracing("test")
|
||||
defer closer.Close()
|
||||
|
||||
// context normally can be propagated through func params
|
||||
ctx := context.Background()
|
||||
|
||||
@ -109,10 +108,6 @@ func TestInject(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTraceError(t *testing.T) {
|
||||
//Already Init in each framework, this can be ignored in debug
|
||||
closer := InitTracing("test")
|
||||
defer closer.Close()
|
||||
|
||||
// context normally can be propagated through func params
|
||||
sp, ctx := StartSpanFromContext(nil)
|
||||
assert.Nil(t, ctx)
|
||||
@ -137,5 +132,4 @@ func TestTraceError(t *testing.T) {
|
||||
assert.Equal(t, id, "")
|
||||
assert.Equal(t, sampled, false)
|
||||
assert.Equal(t, found, false)
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user