Skip to content
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
5 changes: 5 additions & 0 deletions scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ func (scope *Scope) SetPropagationContext(propagationContext PropagationContext)
scope.propagationContext = propagationContext
}

// GetSpan returns the span from the current scope.
func (scope *Scope) GetSpan() *Span {
return scope.span
}

// SetSpan sets a span for the current scope.
func (scope *Scope) SetSpan(span *Span) {
scope.mu.Lock()
Expand Down
12 changes: 6 additions & 6 deletions scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func TestScopeParentChangedInheritance(t *testing.T) {
assertEqual(t, User{ID: "foo"}, clone.user)
assertEqual(t, r1, clone.request)
assertEqual(t, p1, clone.propagationContext)
assertEqual(t, s1, clone.span)
assertEqual(t, s1, clone.GetSpan())

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

func TestScopeChildOverrideInheritance(t *testing.T) {
Expand Down Expand Up @@ -517,7 +517,7 @@ func TestScopeChildOverrideInheritance(t *testing.T) {
assertEqual(t, User{ID: "foo"}, clone.user)
assertEqual(t, r2, clone.request)
assertEqual(t, p2, clone.propagationContext)
assertEqual(t, s2, clone.span)
assertEqual(t, s2, clone.GetSpan())

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

assertEqual(t, len(scope.eventProcessors), 1)
assertEqual(t, len(clone.eventProcessors), 2)
Expand All @@ -548,7 +548,7 @@ func TestClear(t *testing.T) {
assertEqual(t, []string{}, scope.fingerprint)
assertEqual(t, Level(""), scope.level)
assertEqual(t, (*http.Request)(nil), scope.request)
assertEqual(t, (*Span)(nil), scope.span)
assertEqual(t, (*Span)(nil), scope.GetSpan())
}

func TestClearAndReconfigure(t *testing.T) {
Expand Down Expand Up @@ -580,7 +580,7 @@ func TestClearAndReconfigure(t *testing.T) {
assertEqual(t, User{ID: "foo"}, scope.user)
assertEqual(t, r, scope.request)
assertEqual(t, p, scope.propagationContext)
assertEqual(t, s, scope.span)
assertEqual(t, s, scope.GetSpan())
}

func TestClearBreadcrumbs(t *testing.T) {
Expand Down
9 changes: 3 additions & 6 deletions tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ func StartSpan(ctx context.Context, operation string, options ...SpanOption) *Sp
clientOptions := span.clientOptions()
if clientOptions.EnableTracing {
hub := hubFromContext(ctx)
if !span.IsTransaction() {
// Push a new scope to stack for non transaction span
hub.PushScope()
}
hub.Scope().SetSpan(&span)
}

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

hub := hubFromContext(s.ctx)
if !s.IsTransaction() {
// Referenced to StartSpan function that pushes current non-transaction span to scope stack
defer hub.PopScope()
if s.parent != nil {
hub.Scope().SetSpan(s.parent)
}
}

if !s.Sampled.Bool() {
Expand Down
Loading