feat: add workspace-isolated toolhost runtime and capability-gap skill loop
This commit is contained in:
32
internal/logger/trace.go
Normal file
32
internal/logger/trace.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
type traceIDKey struct{}
|
||||
|
||||
func NewTraceID() string {
|
||||
now := time.Now().UTC().UnixNano()
|
||||
randPart := rand.Int63()
|
||||
return fmt.Sprintf("tr-%x-%x", now, randPart)
|
||||
}
|
||||
|
||||
func WithTraceID(ctx context.Context, traceID string) context.Context {
|
||||
if traceID == "" {
|
||||
return ctx
|
||||
}
|
||||
return context.WithValue(ctx, traceIDKey{}, traceID)
|
||||
}
|
||||
|
||||
func TraceIDFromContext(ctx context.Context) string {
|
||||
if ctx == nil {
|
||||
return ""
|
||||
}
|
||||
v := ctx.Value(traceIDKey{})
|
||||
s, _ := v.(string)
|
||||
return s
|
||||
}
|
||||
Reference in New Issue
Block a user