@@ -30,6 +30,7 @@ import (
3030 "fmt"
3131
3232 "go.opentelemetry.io/otel"
33+ "go.opentelemetry.io/otel/codes"
3334 "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
3435 "go.opentelemetry.io/otel/sdk/resource"
3536 sdktrace "go.opentelemetry.io/otel/sdk/trace"
@@ -45,8 +46,8 @@ type Span struct {
4546 span trace.Span
4647}
4748
48- func NewSpan (parent context.Context , name string ) Span {
49- ctx , span := Tracer .Start (parent , name )
49+ func NewSpan (parent context.Context , name string , opts ... trace. SpanStartOption ) Span {
50+ ctx , span := Tracer .Start (parent , name , opts ... )
5051 return Span {Ctx : ctx , span : span }
5152}
5253
@@ -56,6 +57,19 @@ func (s *Span) End() {
5657 }
5758}
5859
60+ // SetError records err on the span and sets its status. Pass nil to mark the span OK.
61+ func (s * Span ) SetError (err error ) {
62+ if s .span == nil {
63+ return
64+ }
65+ if err != nil {
66+ s .span .RecordError (err )
67+ s .span .SetStatus (codes .Error , err .Error ())
68+ } else {
69+ s .span .SetStatus (codes .Ok , "" )
70+ }
71+ }
72+
5973func (s * Span ) Span () trace.Span {
6074 return s .span
6175}
0 commit comments