Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.
This repository was archived by the owner on May 23, 2023. It is now read-only.

Simplify capturing errors from Spans #168

@savaki

Description

@savaki

It's very useful to know when a Span has failed and to capture the error. However, with the current mechanism, log.Error, one ends up with code that looks like this:

span, ctx := opentracing.StartSpanFromContext(ctx, "operationName")
defer span.Finish()

if err := boom(); err != nil {
  err := errors.Wrapf(err, "unable to do %v to %v", x, y)
  ext.Error.Set(span, true)
  return nil, err
}

Instead, have you considered adding Error/Errorf or Wrap/Wrapf funcs to span similar to Dave Cheney's error package? The previous code could be reduced to:

span, ctx := opentracing.StartSpanFromContext(ctx, "operationName")
defer span.Finish()

if err := boom(); err != nil {
  return nil, span.Errorf(err, "unable to do %v to %v", x, y)
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions