Skip to content

Commit

Permalink
runtime: tracing: End root span at end of trace
Browse files Browse the repository at this point in the history
The root span should exist the duration of the trace. Defer ending span
until the end of the trace instead of end of function. Add the span to
the service struct to do so.

Fixes #4902

Signed-off-by: Chelsea Mafrica <chelsea.e.mafrica@intel.com>
(cherry picked from commit fcc1e0c)
  • Loading branch information
cmaf authored and amshinde committed Sep 1, 2022
1 parent 5532930 commit 25b1a52
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/runtime/pkg/containerd-shim-v2/create.go
Expand Up @@ -97,9 +97,10 @@ func create(ctx context.Context, s *service, r *taskAPI.CreateTaskRequest) (*con
}

// create root span
// rootSpan will be ended when the entire trace is ended
rootSpan, newCtx := katatrace.Trace(s.ctx, shimLog, "rootSpan", shimTracingTags)
s.rootCtx = newCtx
defer rootSpan.End()
s.rootSpan = rootSpan

// create span
span, newCtx := katatrace.Trace(s.rootCtx, shimLog, "create", shimTracingTags)
Expand Down
7 changes: 5 additions & 2 deletions src/runtime/pkg/containerd-shim-v2/service.go
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
otelTrace "go.opentelemetry.io/otel/trace"
"golang.org/x/sys/unix"

"github.com/kata-containers/kata-containers/src/runtime/pkg/katautils"
Expand Down Expand Up @@ -122,8 +123,9 @@ type exit struct {
type service struct {
sandbox vc.VCSandbox

ctx context.Context
rootCtx context.Context // root context for tracing
ctx context.Context
rootCtx context.Context // root context for tracing
rootSpan otelTrace.Span

containers map[string]*container

Expand Down Expand Up @@ -946,6 +948,7 @@ func (s *service) Shutdown(ctx context.Context, r *taskAPI.ShutdownRequest) (_ *
s.mu.Unlock()

span.End()
s.rootSpan.End()
katatrace.StopTracing(s.rootCtx)

return empty, nil
Expand Down

0 comments on commit 25b1a52

Please sign in to comment.