@@ -63,6 +63,8 @@ type SpanTemplate struct {
6363 Service string `js:"service"`
6464 // Name represents the name of the span. If empty, the name will be randomly generated.
6565 Name * string `js:"name"`
66+ // Status string sets the span status. "error", "ok" or "unset" are supported
67+ Status * string `js:"status"`
6668 // ParentIDX defines the index of the parent span in TraceTemplate.Spans. ParentIDX must be smaller than the
6769 // own index. If empty, the parent is the span with the position directly before this span in TraceTemplate.Spans.
6870 ParentIDX * int `js:"parentIdx"`
@@ -154,6 +156,7 @@ type internalSpanTemplate struct {
154156 parent * internalSpanTemplate
155157 name string
156158 kind ptrace.SpanKind
159+ status * ptrace.StatusCode
157160 duration * Range
158161 attributeSemantics * OTelSemantics
159162 attributes map [string ]interface {}
@@ -322,6 +325,10 @@ func (g *TemplatedGenerator) generateSpan(scopeSpans ptrace.ScopeSpans, tmpl *in
322325 }
323326 }
324327
328+ if tmpl .status != nil {
329+ span .Status ().SetCode (* tmpl .status )
330+ }
331+
325332 // generate links
326333 span .Links ().EnsureCapacity (len (tmpl .links ))
327334 for _ , l := range tmpl .links {
@@ -530,6 +537,20 @@ func (g *TemplatedGenerator) initializeSpan(idx int, parent *internalSpanTemplat
530537 }
531538 span .attributes = util .MergeMaps (defaults .Attributes , tmpl .Attributes )
532539
540+ // set status
541+ if tmpl .Status != nil {
542+ var status ptrace.StatusCode
543+ switch * tmpl .Status {
544+ case "error" :
545+ status = ptrace .StatusCodeError
546+ case "ok" :
547+ status = ptrace .StatusCodeOk
548+ case "unset" :
549+ status = ptrace .StatusCodeUnset
550+ }
551+ span .status = & status
552+ }
553+
533554 // set span name
534555 if tmpl .Name != nil {
535556 span .name = * tmpl .Name
0 commit comments