Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddtrace/mocktracer: use lock in String method #2229

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ddtrace/mocktracer/mockspan.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ func (s *mockspan) Finish(opts ...ddtrace.FinishOption) {

// String implements fmt.Stringer.
func (s *mockspan) String() string {
s.RLock()
defer s.RUnlock()
sc := s.context
return fmt.Sprintf(`
name: %s
Expand Down
8 changes: 8 additions & 0 deletions ddtrace/mocktracer/mockspan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ func TestSpanFinishTwice(t *testing.T) {
assert.Equal(len(s.tracer.finishedSpans), 1)
}

func TestSpanString(t *testing.T) {
s := basicSpan("http.request")
s.Finish(tracer.WithError(errors.New("some error")))

assert := assert.New(t)
assert.NotEmpty(s.String())
}

func TestSpanWithID(t *testing.T) {
spanID := uint64(123456789)
span := newMockTracer().StartSpan("", tracer.WithSpanID(spanID))
Expand Down
Loading