Skip to content

Commit

Permalink
Test SDK's Span.IsRecording
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Sep 19, 2024
1 parent effdec9 commit dff33eb
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions sdk/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,34 @@ func TestSpanNilUnsampledGuards(t *testing.T) {
t.Run("SetAttributes", run(func(s *span) { s.SetAttributes(attrs...) }))
t.Run("TracerProvider", run(func(s *span) { _ = s.TracerProvider() }))
}

func TestSpanIsRecording(t *testing.T) {
builder := spanBuilder{}
s := builder.Build()
assert.True(t, s.IsRecording(), "sampled span should be recorded")

builder.NotSampled = true
s = builder.Build()
assert.False(t, s.IsRecording(), "unsampled span should not be recorded")
}

type spanBuilder struct {
Name string
NotSampled bool
SpanContext trace.SpanContext
Options []trace.SpanStartOption
}

func (b spanBuilder) Build() *span {
tracer := new(tracer)
s := &span{sampled: !b.NotSampled, spanContext: b.SpanContext}
s.traces, s.span = tracer.traces(
context.Background(),
b.Name,
trace.NewSpanStartConfig(b.Options...),
s.spanContext,
trace.SpanContext{},
)

return s
}

0 comments on commit dff33eb

Please sign in to comment.