Skip to content

Commit 00a135a

Browse files
authored
Do not push a new scope on StartSpan (#1013)
1 parent 64de096 commit 00a135a

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

scope.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ func (scope *Scope) SetPropagationContext(propagationContext PropagationContext)
302302
scope.propagationContext = propagationContext
303303
}
304304

305+
// GetSpan returns the span from the current scope.
306+
func (scope *Scope) GetSpan() *Span {
307+
return scope.span
308+
}
309+
305310
// SetSpan sets a span for the current scope.
306311
func (scope *Scope) SetSpan(span *Span) {
307312
scope.mu.Lock()

scope_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ func TestScopeParentChangedInheritance(t *testing.T) {
447447
assertEqual(t, User{ID: "foo"}, clone.user)
448448
assertEqual(t, r1, clone.request)
449449
assertEqual(t, p1, clone.propagationContext)
450-
assertEqual(t, s1, clone.span)
450+
assertEqual(t, s1, clone.GetSpan())
451451

452452
assertEqual(t, map[string]string{"foo": "baz"}, scope.tags)
453453
assertEqual(t, map[string]Context{"foo": {"foo": "baz"}}, scope.contexts)
@@ -458,7 +458,7 @@ func TestScopeParentChangedInheritance(t *testing.T) {
458458
assertEqual(t, []*Attachment{{Filename: "bar.txt", Payload: []byte("bar")}}, scope.attachments)
459459
assertEqual(t, User{ID: "bar"}, scope.user)
460460
assertEqual(t, r2, scope.request)
461-
assertEqual(t, s2, scope.span)
461+
assertEqual(t, s2, scope.GetSpan())
462462
}
463463

464464
func TestScopeChildOverrideInheritance(t *testing.T) {
@@ -517,7 +517,7 @@ func TestScopeChildOverrideInheritance(t *testing.T) {
517517
assertEqual(t, User{ID: "foo"}, clone.user)
518518
assertEqual(t, r2, clone.request)
519519
assertEqual(t, p2, clone.propagationContext)
520-
assertEqual(t, s2, clone.span)
520+
assertEqual(t, s2, clone.GetSpan())
521521

522522
assertEqual(t, map[string]string{"foo": "baz"}, scope.tags)
523523
assertEqual(t, map[string]Context{"foo": {"foo": "baz"}}, scope.contexts)
@@ -529,7 +529,7 @@ func TestScopeChildOverrideInheritance(t *testing.T) {
529529
assertEqual(t, User{ID: "bar"}, scope.user)
530530
assertEqual(t, r1, scope.request)
531531
assertEqual(t, p1, scope.propagationContext)
532-
assertEqual(t, s1, scope.span)
532+
assertEqual(t, s1, scope.GetSpan())
533533

534534
assertEqual(t, len(scope.eventProcessors), 1)
535535
assertEqual(t, len(clone.eventProcessors), 2)
@@ -548,7 +548,7 @@ func TestClear(t *testing.T) {
548548
assertEqual(t, []string{}, scope.fingerprint)
549549
assertEqual(t, Level(""), scope.level)
550550
assertEqual(t, (*http.Request)(nil), scope.request)
551-
assertEqual(t, (*Span)(nil), scope.span)
551+
assertEqual(t, (*Span)(nil), scope.GetSpan())
552552
}
553553

554554
func TestClearAndReconfigure(t *testing.T) {
@@ -580,7 +580,7 @@ func TestClearAndReconfigure(t *testing.T) {
580580
assertEqual(t, User{ID: "foo"}, scope.user)
581581
assertEqual(t, r, scope.request)
582582
assertEqual(t, p, scope.propagationContext)
583-
assertEqual(t, s, scope.span)
583+
assertEqual(t, s, scope.GetSpan())
584584
}
585585

586586
func TestClearBreadcrumbs(t *testing.T) {

tracing.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ func StartSpan(ctx context.Context, operation string, options ...SpanOption) *Sp
198198
clientOptions := span.clientOptions()
199199
if clientOptions.EnableTracing {
200200
hub := hubFromContext(ctx)
201-
if !span.IsTransaction() {
202-
// Push a new scope to stack for non transaction span
203-
hub.PushScope()
204-
}
205201
hub.Scope().SetSpan(&span)
206202
}
207203

@@ -359,8 +355,9 @@ func (s *Span) doFinish() {
359355

360356
hub := hubFromContext(s.ctx)
361357
if !s.IsTransaction() {
362-
// Referenced to StartSpan function that pushes current non-transaction span to scope stack
363-
defer hub.PopScope()
358+
if s.parent != nil {
359+
hub.Scope().SetSpan(s.parent)
360+
}
364361
}
365362

366363
if !s.Sampled.Bool() {

0 commit comments

Comments
 (0)