Skip to content

Commit 2d8e971

Browse files
committed
more traces; currently not displaying properly in opensearch
1 parent 79556e8 commit 2d8e971

11 files changed

Lines changed: 268 additions & 147 deletions

common/tracing/tracing.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
5973
func (s *Span) Span() trace.Span {
6074
return s.span
6175
}

0 commit comments

Comments
 (0)