perform ctx store-back (into state bag) before starting span to avoid reparenting
@@ -22,17 +22,17 @@ func (s *stepUpdateState) Run(state multistep.StateBag) multistep.StepAction {
logger := context.LoggerFromContext(ctx).WithField("self", "step_update_state")
- defer context.TimeSince(ctx, "step_update_state_run", time.Now())
-
- ctx, span := trace.StartSpan(ctx, "UpdateState.Run")
- defer span.End()
-
instanceID := instance.ID()
if instanceID != "" {
ctx = context.FromInstanceID(ctx, instanceID)
state.Put("ctx", ctx)
}
+ defer context.TimeSince(ctx, "step_update_state_run", time.Now())
+
+ ctx, span := trace.StartSpan(ctx, "UpdateState.Run")
+ defer span.End()
+
logWriter.SetJobStarted(&JobStartedMeta{
QueuedAt: buildJob.Payload().Job.QueuedAt,
Repo: buildJob.Payload().Repository.Slug,
@@ -62,11 +62,6 @@ func (s *stepUpdateState) Cleanup(state multistep.StateBag) {
ctx := state.Get("ctx").(gocontext.Context)
processedAt := state.Get("processedAt").(time.Time)
- defer context.TimeSince(ctx, "step_update_state_cleanup", time.Now())
-
- ctx, span := trace.StartSpan(ctx, "UpdateState.Cleanup")
- defer span.End()
-
instance := state.Get("instance").(backend.Instance)
instanceID := instance.ID()
if instanceID != "" {
@@ -74,6 +69,11 @@ func (s *stepUpdateState) Cleanup(state multistep.StateBag) {
state.Put("ctx", ctx)
}
+ defer context.TimeSince(ctx, "step_update_state_cleanup", time.Now())
+
+ ctx, span := trace.StartSpan(ctx, "UpdateState.Cleanup")
+ defer span.End()
+
logger := context.LoggerFromContext(ctx).WithField("self", "step_update_state")
logger.WithFields(logrus.Fields{
"since_processed_ms": time.Since(processedAt).Seconds() * 1e3,
