Skip to content

Commit 592903c

Browse files
authored
refactor: attach logHandler spans to main trace (#56)
Refactors the container log publishing mechanism to ensure that these operations are correctly linked to their parent spans.
1 parent 07f0707 commit 592903c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

internal/engine/services/worker/service.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,17 @@ func (s *Service) runTask(ctx context.Context, t *task.Task) error {
160160
logOpts := []broker.PublishOption{
161161
broker.PublishWithQueue(string(log.Queue)),
162162
}
163-
s.broker.Publish(context.Background(), logData, logOpts...)
163+
ctx, publishLogSpan := s.tracer.Start(ctx, "Publish Container Log", trace.WithAttributes(
164+
attribute.String("task.id", t.ID),
165+
attribute.String("log", logLine),
166+
))
167+
defer publishLogSpan.End()
168+
if err := s.broker.Publish(ctx, logData, logOpts...); err != nil {
169+
publishLogSpan.RecordError(err)
170+
publishLogSpan.SetStatus(codes.Error, err.Error())
171+
} else {
172+
publishLogSpan.SetStatus(codes.Ok, "container log published")
173+
}
164174
}
165175

166176
var ms []*task.Mount

0 commit comments

Comments
 (0)