mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-18 23:04:20 +01:00
tracing: Consolidate tracing into a new katatrace package
Removes custom trace functions defined across the repo and creates a single trace function in a new katatrace package. Also moves span tag management into this package and provides a function to dynamically add a tag at runtime, such as a container id, etc. Fixes #1162 Signed-off-by: Benjamin Porter <bporter816@gmail.com>
This commit is contained in:
@@ -16,14 +16,19 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/kata-containers/kata-containers/src/runtime/pkg/katautils/katatrace"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
otelTrace "go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
// virtiofsdTracingTags defines tags for the trace span
|
||||
var virtiofsdTracingTags = map[string]string{
|
||||
"source": "runtime",
|
||||
"package": "virtcontainers",
|
||||
"subsystem": "virtiofsd",
|
||||
}
|
||||
|
||||
var (
|
||||
errVirtiofsdDaemonPathEmpty = errors.New("virtiofsd daemon path is empty")
|
||||
errVirtiofsdSocketPathEmpty = errors.New("virtiofsd socket path is empty")
|
||||
@@ -84,7 +89,7 @@ func (v *virtiofsd) getSocketFD() (*os.File, error) {
|
||||
|
||||
// Start the virtiofsd daemon
|
||||
func (v *virtiofsd) Start(ctx context.Context, onQuit onQuitFunc) (int, error) {
|
||||
span, _ := v.trace(ctx, "Start")
|
||||
span, _ := katatrace.Trace(ctx, v.Logger(), "Start", virtiofsdTracingTags)
|
||||
defer span.End()
|
||||
pid := 0
|
||||
|
||||
@@ -206,19 +211,8 @@ func (v *virtiofsd) Logger() *log.Entry {
|
||||
return virtLog.WithField("subsystem", "virtiofsd")
|
||||
}
|
||||
|
||||
func (v *virtiofsd) trace(parent context.Context, name string) (otelTrace.Span, context.Context) {
|
||||
if parent == nil {
|
||||
parent = context.Background()
|
||||
}
|
||||
|
||||
tracer := otel.Tracer("kata")
|
||||
ctx, span := tracer.Start(parent, name, otelTrace.WithAttributes(label.String("source", "runtime"), label.String("package", "virtcontainers"), label.String("subsystem", "virtiofsd")))
|
||||
|
||||
return span, ctx
|
||||
}
|
||||
|
||||
func (v *virtiofsd) kill(ctx context.Context) (err error) {
|
||||
span, _ := v.trace(ctx, "kill")
|
||||
span, _ := katatrace.Trace(ctx, v.Logger(), "kill", virtiofsdTracingTags)
|
||||
defer span.End()
|
||||
|
||||
if v.PID == 0 {
|
||||
|
||||
Reference in New Issue
Block a user