Skip to content

Commit

Permalink
Adding tracing to Run functions (#6)
Browse files Browse the repository at this point in the history
* adding trace to Run functions
  • Loading branch information
ankurs authored Nov 8, 2022
1 parent 3f2101e commit d6cffed
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,18 @@ func (p *plan) Replace(ctx context.Context, from interface{}, to interface{}) er
}

func (p *plan) Run(ctx context.Context, initData ...interface{}) (Result, error) {
return p.RunParallel(ctx, 1, initData...)
span, ctx := tracing.NewInternalSpan(ctx, "DBRun")
defer span.End()
r, err := p.RunParallel(ctx, 1, initData...)
if err != nil {
span.SetError(err)
}
return r, err
}

func (p *plan) RunParallel(ctx context.Context, workers uint, initData ...interface{}) (Result, error) {
span, ctx := tracing.NewInternalSpan(ctx, "DBRunParallel")
defer span.End()
dataMap := make(map[string]interface{})
initialData := sets.NewString()
for _, inter := range initData {
Expand All @@ -82,10 +90,11 @@ func (p *plan) RunParallel(ctx context.Context, workers uint, initData ...interf
initialData.Insert(name)
dataMap[name] = inter
}
span.SetTag("workers", workers)
if p.initData.Difference(initialData).Len() > 0 {
return nil, ErrInitialDataMissing
return nil, span.SetError(ErrInitialDataMissing)
}
return dataMap, p.run(ctx, workers, dataMap)
return dataMap, span.SetError(p.run(ctx, workers, dataMap))
}

type work struct {
Expand Down

0 comments on commit d6cffed

Please sign in to comment.