|
@@ -3,18 +3,17 @@ package tracing
|
|
|
import (
|
|
import (
|
|
|
"context"
|
|
"context"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
- "sort"
|
|
|
|
|
- "time"
|
|
|
|
|
-
|
|
|
|
|
- "strconv"
|
|
|
|
|
-
|
|
|
|
|
"github.com/coroot/coroot-node-agent/ebpftracer"
|
|
"github.com/coroot/coroot-node-agent/ebpftracer"
|
|
|
"github.com/coroot/coroot-node-agent/ebpftracer/l7"
|
|
"github.com/coroot/coroot-node-agent/ebpftracer/l7"
|
|
|
|
|
+ "github.com/coroot/coroot-node-agent/utils"
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
"go.opentelemetry.io/otel/codes"
|
|
"go.opentelemetry.io/otel/codes"
|
|
|
semconv "go.opentelemetry.io/otel/semconv/v1.18.0"
|
|
semconv "go.opentelemetry.io/otel/semconv/v1.18.0"
|
|
|
"go.opentelemetry.io/otel/trace"
|
|
"go.opentelemetry.io/otel/trace"
|
|
|
"inet.af/netaddr"
|
|
"inet.af/netaddr"
|
|
|
|
|
+ "strconv"
|
|
|
|
|
+ "sync/atomic"
|
|
|
|
|
+ "time"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -39,71 +38,113 @@ type TimeMap struct {
|
|
|
Map *ebpftracer.StackFunEvent
|
|
Map *ebpftracer.StackFunEvent
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (t *Trace) buildFun() {
|
|
|
|
|
- mapSlice := []TimeMap{}
|
|
|
|
|
- for i, v := range t.stack {
|
|
|
|
|
- timeStartMap := TimeMap{}
|
|
|
|
|
- if v.StackEvent.Location == 0 {
|
|
|
|
|
- timeStartMap = TimeMap{
|
|
|
|
|
- Time: v.StackEvent.TimeNsStart,
|
|
|
|
|
- Type: 0,
|
|
|
|
|
- Map: &t.stack[i],
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- timeStartMap = TimeMap{
|
|
|
|
|
- Time: v.StackEvent.TimeNsEnd,
|
|
|
|
|
- Type: 1,
|
|
|
|
|
- Map: &t.stack[i],
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- mapSlice = append(mapSlice, timeStartMap)
|
|
|
|
|
- }
|
|
|
|
|
- sort.Slice(mapSlice, func(i, j int) bool {
|
|
|
|
|
- return mapSlice[i].Time < mapSlice[j].Time
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- funStack := []TimeMap{}
|
|
|
|
|
-
|
|
|
|
|
- currentfunNum := 1
|
|
|
|
|
-
|
|
|
|
|
- // for k, v := range mapSlice {
|
|
|
|
|
- // fmt.Println("---SliceSliceindex", k, "value", v.Time, v.Type, v.Map.Uprobe.Funcname, v.Map.StackEvent.Nid)
|
|
|
|
|
- // }
|
|
|
|
|
|
|
+//func (t *Trace) buildFun() {
|
|
|
|
|
+// mapSlice := []TimeMap{}
|
|
|
|
|
+// for i, v := range t.stack {
|
|
|
|
|
+// timeStartMap := TimeMap{}
|
|
|
|
|
+// if v.StackEvent.Location == 0 {
|
|
|
|
|
+// timeStartMap = TimeMap{
|
|
|
|
|
+// Time: v.StackEvent.TimeNsStart,
|
|
|
|
|
+// Type: 0,
|
|
|
|
|
+// Map: &t.stack[i],
|
|
|
|
|
+// }
|
|
|
|
|
+// } else {
|
|
|
|
|
+// timeStartMap = TimeMap{
|
|
|
|
|
+// Time: v.StackEvent.TimeNsEnd,
|
|
|
|
|
+// Type: 1,
|
|
|
|
|
+// Map: &t.stack[i],
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// mapSlice = append(mapSlice, timeStartMap)
|
|
|
|
|
+// }
|
|
|
|
|
+// sort.Slice(mapSlice, func(i, j int) bool {
|
|
|
|
|
+// return mapSlice[i].Time < mapSlice[j].Time
|
|
|
|
|
+// })
|
|
|
|
|
+//
|
|
|
|
|
+// funStack := []TimeMap{}
|
|
|
|
|
+//
|
|
|
|
|
+// currentfunNum := 1
|
|
|
|
|
+//
|
|
|
|
|
+// // for k, v := range mapSlice {
|
|
|
|
|
+// // fmt.Println("---SliceSliceindex", k, "value", v.Time, v.Type, v.Map.Uprobe.Funcname, v.Map.StackEvent.Nid)
|
|
|
|
|
+// // }
|
|
|
|
|
+//
|
|
|
|
|
+// mapSliceLen := len(mapSlice)
|
|
|
|
|
+// for k, v := range mapSlice {
|
|
|
|
|
+// // fmt.Println("SliceSliceindex", k, "value", v.Time, v.Type, v.Map.Uprobe.Funcname, v.Map.StackEvent.Nid)
|
|
|
|
|
+// if v.Type == 0 {
|
|
|
|
|
+// // 函数入口
|
|
|
|
|
+// funStack = append(funStack, v)
|
|
|
|
|
+// } else if v.Type == 1 {
|
|
|
|
|
+// // 函数出口
|
|
|
|
|
+// len := len(funStack)
|
|
|
|
|
+// if len < 1 {
|
|
|
|
|
+// fmt.Printf("buildFun ErrorError return before enter: %v\n", v)
|
|
|
|
|
+// continue
|
|
|
|
|
+// }
|
|
|
|
|
+// currnt := funStack[len-1]
|
|
|
|
|
+// if currnt.Map.StackEvent.Location != 0 {
|
|
|
|
|
+// fmt.Printf("currnt StackEvent ErrorError is not enter: %v\n", v)
|
|
|
|
|
+// continue
|
|
|
|
|
+// }
|
|
|
|
|
+// if k < mapSliceLen-1 && len >= 2 {
|
|
|
|
|
+// nextfun := mapSlice[k+1]
|
|
|
|
|
+// preCurrnt := funStack[len-2]
|
|
|
|
|
+// // // 处理 .netcore 多次 returun
|
|
|
|
|
+// // 下一个事件是 return 并且函数名跟当前事件是一样的,且上一个函数不是当前函数
|
|
|
|
|
+// if nextfun.Map.StackEvent.Location == 1 && nextfun.Map.Uprobe.Funcname == currnt.Map.Uprobe.Funcname && preCurrnt.Map.Uprobe.Funcname != currnt.Map.Uprobe.Funcname {
|
|
|
|
|
+// currentfunNum++
|
|
|
|
|
+// continue
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// funStack = funStack[:len-1]
|
|
|
|
|
+// duration := v.Map.StackEvent.TimeNsEnd - currnt.Map.StackEvent.TimeNsStart
|
|
|
|
|
+// t.FuncTraceQuery(currnt.Map.Uprobe.Funcname, time.Duration(duration), currnt.Map.StackEvent.TimeNsStart, v.Map.StackEvent.TimeNsEnd, currentfunNum)
|
|
|
|
|
+// currentfunNum = 1
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+//}
|
|
|
|
|
|
|
|
- mapSliceLen := len(mapSlice)
|
|
|
|
|
- for k, v := range mapSlice {
|
|
|
|
|
- // fmt.Println("SliceSliceindex", k, "value", v.Time, v.Type, v.Map.Uprobe.Funcname, v.Map.StackEvent.Nid)
|
|
|
|
|
- if v.Type == 0 {
|
|
|
|
|
- // 函数入口
|
|
|
|
|
- funStack = append(funStack, v)
|
|
|
|
|
- } else if v.Type == 1 {
|
|
|
|
|
- // 函数出口
|
|
|
|
|
- len := len(funStack)
|
|
|
|
|
- if len < 1 {
|
|
|
|
|
- fmt.Printf("buildFun ErrorError return before enter: %v\n", v)
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
- currnt := funStack[len-1]
|
|
|
|
|
- if currnt.Map.StackEvent.Location != 0 {
|
|
|
|
|
- fmt.Printf("currnt StackEvent ErrorError is not enter: %v\n", v)
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
- if k < mapSliceLen-1 && len >= 2 {
|
|
|
|
|
- nextfun := mapSlice[k+1]
|
|
|
|
|
- preCurrnt := funStack[len-2]
|
|
|
|
|
- // // 处理 .netcore 多次 returun
|
|
|
|
|
- // 下一个事件是 return 并且函数名跟当前事件是一样的,且上一个函数不是当前函数
|
|
|
|
|
- if nextfun.Map.StackEvent.Location == 1 && nextfun.Map.Uprobe.Funcname == currnt.Map.Uprobe.Funcname && preCurrnt.Map.Uprobe.Funcname != currnt.Map.Uprobe.Funcname {
|
|
|
|
|
- currentfunNum++
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- funStack = funStack[:len-1]
|
|
|
|
|
- duration := v.Map.StackEvent.TimeNsEnd - currnt.Map.StackEvent.TimeNsStart
|
|
|
|
|
- t.FuncTraceQuery(currnt.Map.Uprobe.Funcname, time.Duration(duration), currnt.Map.StackEvent.TimeNsStart, v.Map.StackEvent.TimeNsEnd, currentfunNum)
|
|
|
|
|
- currentfunNum = 1
|
|
|
|
|
- }
|
|
|
|
|
|
|
+func (t *Trace) startReady() {
|
|
|
|
|
+ t.lock.Lock()
|
|
|
|
|
+ defer t.lock.Unlock()
|
|
|
|
|
+ t.startEventReady = true
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (t *Trace) endReadyEvent(needCount uint32) {
|
|
|
|
|
+ t.lock.Lock()
|
|
|
|
|
+ defer t.lock.Unlock()
|
|
|
|
|
+ t.endEventReady = true
|
|
|
|
|
+ t.needEventCount = needCount
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (t *Trace) AllEventReady(traceID uint64) bool {
|
|
|
|
|
+ fmt.Printf("[AllEventReady (current/need)|start|end|traceid](%d/%d)%v|%v|%d\n", *t.currenEventCount, t.needEventCount, t.startEventReady, t.endEventReady, traceID)
|
|
|
|
|
+ return t.startEventReady && t.endEventReady && *t.currenEventCount >= t.needEventCount
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (t *Trace) TraceStartEvent(method, path string, status l7.Status, addr netaddr.IPPort) {
|
|
|
|
|
+ t.span.SetAttributes(semconv.HTTPURL(fmt.Sprintf("http://%s%s", addr.String(), path)),
|
|
|
|
|
+ semconv.HTTPMethod(method),
|
|
|
|
|
+ attribute.String("http.uri", path))
|
|
|
|
|
+ if status > 399 {
|
|
|
|
|
+ t.span.SetStatus(codes.Error, "")
|
|
|
|
|
+ }
|
|
|
|
|
+ t.destination = addr
|
|
|
|
|
+ t.commonAttrs = []attribute.KeyValue{
|
|
|
|
|
+ semconv.NetPeerName(addr.IP().String()),
|
|
|
|
|
+ semconv.NetPeerPort(int(addr.Port())),
|
|
|
}
|
|
}
|
|
|
|
|
+ t.span.SetAttributes(t.commonAttrs...)
|
|
|
|
|
+ t.startReady()
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// set context span
|
|
|
|
|
+func (t *Trace) CreateRootSpan(traceId uint64) {
|
|
|
|
|
+ traceIdStr := strconv.Itoa(int(traceId))
|
|
|
|
|
+ ctx, span := tracer(t.containerId).Start(context.Background(), traceIdStr, trace.WithSpanKind(trace.SpanKindClient))
|
|
|
|
|
+ t.setContext(ctx)
|
|
|
|
|
+ t.setSpan(span)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (t *Trace) TraceStart(method, path string, status l7.Status, duration time.Duration) {
|
|
func (t *Trace) TraceStart(method, path string, status l7.Status, duration time.Duration) {
|
|
@@ -147,10 +188,61 @@ func (t *Trace) TraceEnd(r *l7.RequestData) {
|
|
|
// for _, v := range t.stack {
|
|
// for _, v := range t.stack {
|
|
|
// fmt.Printf("TraceEndTraceEndTraceEnd%s\n", v)
|
|
// fmt.Printf("TraceEndTraceEndTraceEnd%s\n", v)
|
|
|
// }
|
|
// }
|
|
|
- t.buildFun()
|
|
|
|
|
|
|
+ //t.buildFun()
|
|
|
t.span.End(trace.WithTimestamp(time.Now()))
|
|
t.span.End(trace.WithTimestamp(time.Now()))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 新增结束事件
|
|
|
|
|
+func (t *Trace) TraceEndEvent(r *l7.RequestData) {
|
|
|
|
|
+ if t == nil {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ var attr []attribute.KeyValue
|
|
|
|
|
+ attr = append(attr,
|
|
|
|
|
+ semconv.HTTPStatusCode(int(r.Status)),
|
|
|
|
|
+ attribute.String("server.trace_id_from", r.ParentSpanContext.TraceIdFrom),
|
|
|
|
|
+ )
|
|
|
|
|
+ //t.span.SetAttributes(
|
|
|
|
|
+ // semconv.HTTPStatusCode(int(r.Status)),
|
|
|
|
|
+ // attribute.String("server.trace_id_from", r.ParentSpanContext.TraceIdFrom),
|
|
|
|
|
+ //)
|
|
|
|
|
+
|
|
|
|
|
+ calledId, err := strconv.ParseInt(r.ParentSpanContext.CalledId, 10, 64)
|
|
|
|
|
+ if err == nil && calledId != 0 {
|
|
|
|
|
+ attr = append(attr, attribute.Int64("server.called_id", calledId))
|
|
|
|
|
+ //t.span.SetAttributes(attribute.Int64("server.called_id", CalledId))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ instanceIdFrom, err := strconv.ParseInt(r.ParentSpanContext.InstanceIdFrom, 10, 64)
|
|
|
|
|
+ if err == nil && instanceIdFrom != 0 {
|
|
|
|
|
+ attr = append(attr, attribute.Int64("server.instance_id_from", instanceIdFrom))
|
|
|
|
|
+
|
|
|
|
|
+ //t.span.SetAttributes(attribute.Int64("server.instance_id_from", InstanceIdFrom))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ appIdFrom, err := strconv.ParseInt(r.ParentSpanContext.AppIdFrom, 10, 64)
|
|
|
|
|
+ if err == nil && appIdFrom != 0 {
|
|
|
|
|
+ attr = append(attr, attribute.Int64("server.app_id_from", appIdFrom))
|
|
|
|
|
+ //t.span.SetAttributes(attribute.Int64("server.app_id_from", AppIdFrom))
|
|
|
|
|
+ }
|
|
|
|
|
+ if r.ParentSpanContext.SpanIdFrom != "0000000000000000" {
|
|
|
|
|
+ attr = append(attr, attribute.String("server.span_id_from", r.ParentSpanContext.SpanIdFrom))
|
|
|
|
|
+ //t.span.SetAttributes(attribute.String("server.span_id_from", r.ParentSpanContext.SpanIdFrom))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ t.appendTimestamp(&attr, r.StartAt, r.EndAt, r.Duration.Nanoseconds())
|
|
|
|
|
+ t.span.SetAttributes(attr...)
|
|
|
|
|
+ t.endReadyEvent(r.EventCount)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (t *Trace) appendTimestamp(attr *[]attribute.KeyValue, s, e uint64, d int64) {
|
|
|
|
|
+ *attr = append(*attr,
|
|
|
|
|
+ attribute.Int64("time.start_at", utils.KtimeToTimestamp(s)),
|
|
|
|
|
+ attribute.Int64("time.end_at", utils.KtimeToTimestamp(e)),
|
|
|
|
|
+ attribute.Int64("time.duration", d),
|
|
|
|
|
+ )
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func (t *Trace) createParentSpan(name string, duration time.Duration, error bool, attrs ...attribute.KeyValue) {
|
|
func (t *Trace) createParentSpan(name string, duration time.Duration, error bool, attrs ...attribute.KeyValue) {
|
|
|
end := time.Now()
|
|
end := time.Now()
|
|
|
start := end.Add(-duration)
|
|
start := end.Add(-duration)
|
|
@@ -164,6 +256,19 @@ func (t *Trace) createParentSpan(name string, duration time.Duration, error bool
|
|
|
t.setSpan(span)
|
|
t.setSpan(span)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func (t *Trace) SendEvent() {
|
|
|
|
|
+ t.span.End()
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (t *Trace) GetSpan() trace.Span {
|
|
|
|
|
+ return t.span
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (t *Trace) createTraceEvent(name string, eventType int, l7Type int, attrs ...attribute.KeyValue) {
|
|
|
|
|
+ t.span.AddEventApm(name, eventType, l7Type, trace.WithAttributes(attrs...))
|
|
|
|
|
+ atomic.AddUint32(t.currenEventCount, 1)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func (t *Trace) createTraceSpan(name string, duration time.Duration, error bool, attrs ...attribute.KeyValue) {
|
|
func (t *Trace) createTraceSpan(name string, duration time.Duration, error bool, attrs ...attribute.KeyValue) {
|
|
|
end := time.Now()
|
|
end := time.Now()
|
|
|
start := end.Add(-duration)
|
|
start := end.Add(-duration)
|
|
@@ -189,6 +294,22 @@ func (t *Trace) MysqlTraceQuery(query string, error bool, duration time.Duration
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func (t *Trace) MysqlTraceQueryEvent(query string, r *l7.RequestData, destination netaddr.IPPort) {
|
|
|
|
|
+ if t == nil || query == "" {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var attr []attribute.KeyValue
|
|
|
|
|
+ attr = append(attr,
|
|
|
|
|
+ semconv.DBSystemMySQL,
|
|
|
|
|
+ semconv.DBStatement(query),
|
|
|
|
|
+ semconv.NetPeerName(destination.IP().String()),
|
|
|
|
|
+ semconv.NetPeerPort(int(destination.Port())),
|
|
|
|
|
+ )
|
|
|
|
|
+ t.appendTimestamp(&attr, r.StartAt, r.EndAt, r.Duration.Nanoseconds())
|
|
|
|
|
+ t.createTraceEvent(l7.ProtocolHTTP.String(), int(ebpftracer.EventTypeL7Request), int(l7.ProtocolMysql), attr...)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func (t *Trace) RedisTraceQuery(cmd, args string, error bool, duration time.Duration) {
|
|
func (t *Trace) RedisTraceQuery(cmd, args string, error bool, duration time.Duration) {
|
|
|
if t == nil || cmd == "" {
|
|
if t == nil || cmd == "" {
|
|
|
return
|
|
return
|
|
@@ -204,6 +325,27 @@ func (t *Trace) RedisTraceQuery(cmd, args string, error bool, duration time.Dura
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func (t *Trace) RedisTraceQueryEvent(cmd, args string, r *l7.RequestData, destination netaddr.IPPort) {
|
|
|
|
|
+ if t == nil || cmd == "" {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ statement := cmd
|
|
|
|
|
+ if args != "" {
|
|
|
|
|
+ statement += " " + args
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var attr []attribute.KeyValue
|
|
|
|
|
+ attr = append(attr,
|
|
|
|
|
+ semconv.DBSystemRedis,
|
|
|
|
|
+ semconv.DBOperation(cmd),
|
|
|
|
|
+ semconv.DBStatement(statement),
|
|
|
|
|
+ semconv.NetPeerName(destination.IP().String()),
|
|
|
|
|
+ semconv.NetPeerPort(int(destination.Port())),
|
|
|
|
|
+ )
|
|
|
|
|
+ t.appendTimestamp(&attr, r.StartAt, r.EndAt, r.Duration.Nanoseconds())
|
|
|
|
|
+ t.createTraceEvent(l7.ProtocolHTTP.String(), int(ebpftracer.EventTypeL7Request), int(l7.ProtocolRedis), attr...)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func (t *Trace) HttpTraceRequest(method, path, ip string, port uint16, r *l7.RequestData) {
|
|
func (t *Trace) HttpTraceRequest(method, path, ip string, port uint16, r *l7.RequestData) {
|
|
|
if t == nil || method == "" {
|
|
if t == nil || method == "" {
|
|
|
return
|
|
return
|
|
@@ -226,11 +368,38 @@ func (t *Trace) HttpTraceRequest(method, path, ip string, port uint16, r *l7.Req
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (t *Trace) FuncTraceQuery(funcname string, duration time.Duration, start uint64, end uint64, num int) {
|
|
|
|
|
|
|
+// 新增事件处理
|
|
|
|
|
+func (t *Trace) HttpTraceRequestEvent(method, path, ip string, port uint16, r *l7.RequestData) {
|
|
|
|
|
+ if t == nil || method == "" {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ assumedAppID, err := strconv.ParseInt(r.AssumedAppId, 10, 64)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ assumedAppID = 0
|
|
|
|
|
+ }
|
|
|
|
|
+ status := r.Status
|
|
|
|
|
+ var attr []attribute.KeyValue
|
|
|
|
|
+ attr = append(attr,
|
|
|
|
|
+ semconv.HTTPURL(fmt.Sprintf("http://%s%s", t.destination.String(), path)),
|
|
|
|
|
+ semconv.HTTPMethod(method),
|
|
|
|
|
+ semconv.HTTPStatusCode(int(status)),
|
|
|
|
|
+ attribute.Bool("http.status_error", status > 399),
|
|
|
|
|
+ attribute.String("http.uri", path),
|
|
|
|
|
+ attribute.String("http.ip", ip),
|
|
|
|
|
+ attribute.Int64("http.assumed_app_id", assumedAppID),
|
|
|
|
|
+ attribute.String("http.span_id", r.SpanId),
|
|
|
|
|
+ attribute.Int("http.port", int(port)),
|
|
|
|
|
+ )
|
|
|
|
|
+ t.appendTimestamp(&attr, r.StartAt, r.EndAt, r.Duration.Nanoseconds())
|
|
|
|
|
+ t.createTraceEvent(l7.ProtocolHTTP.String(), int(ebpftracer.EventTypeL7Request), int(l7.ProtocolHTTP), attr...)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (t *Trace) FuncTraceQuery(funcname string, duration time.Duration, start uint64, end uint64) {
|
|
|
if t == nil || funcname == "" {
|
|
if t == nil || funcname == "" {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- t.createTraceSpanNoTime(funcname, duration, false, start, end, attribute.Int("num", num))
|
|
|
|
|
|
|
+ t.createTraceSpanNoTime2(funcname, duration, false, start, end)
|
|
|
|
|
+ //t.createTraceSpanNoTime2(funcname, duration, false, start, end, attribute.Int("num", num))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (t *Trace) createTraceSpanNoTime(name string, duration time.Duration, error bool, start uint64, end uint64, attrs ...attribute.KeyValue) {
|
|
func (t *Trace) createTraceSpanNoTime(name string, duration time.Duration, error bool, start uint64, end uint64, attrs ...attribute.KeyValue) {
|
|
@@ -247,3 +416,25 @@ func (t *Trace) createTraceSpanNoTime(name string, duration time.Duration, error
|
|
|
}
|
|
}
|
|
|
span.End(trace.WithTimestamp(endTime))
|
|
span.End(trace.WithTimestamp(endTime))
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func (t *Trace) createTraceSpanNoTime2(name string, duration time.Duration, error bool, start uint64, end uint64) {
|
|
|
|
|
+ // end := time.Now()
|
|
|
|
|
+ // start := end.Add(-duration)
|
|
|
|
|
+ //startTime := time.Unix(0, int64(start))
|
|
|
|
|
+ //endTime := time.Unix(0, int64(end))
|
|
|
|
|
+ ////fmt.Println("createTraceSpan:", t.ctx)
|
|
|
|
|
+ //_, span := tracer(t.containerId).Start(t.ctx, name, trace.WithTimestamp(startTime), trace.WithSpanKind(trace.SpanKindClient))
|
|
|
|
|
+ //span.SetAttributes(t.commonAttrs...)
|
|
|
|
|
+ //span.SetAttributes(attrs...)
|
|
|
|
|
+ //if error {
|
|
|
|
|
+ // span.SetStatus(codes.Error, "")
|
|
|
|
|
+ //}
|
|
|
|
|
+ //span.End(trace.WithTimestamp(endTime))
|
|
|
|
|
+ //attrs = append([]attribute.KeyValue{
|
|
|
|
|
+ // attribute.Int64("startAt", int64(start)),
|
|
|
|
|
+ // attribute.Int64("endAt", int64(end)),
|
|
|
|
|
+ //})
|
|
|
|
|
+ var attr []attribute.KeyValue
|
|
|
|
|
+ t.appendTimestamp(&attr, start, end, int64(end-start))
|
|
|
|
|
+ t.createTraceEvent(name, int(ebpftracer.EventTypeFunEnt), 0, attr...)
|
|
|
|
|
+}
|