Skip to content

Commit

Permalink
[Fix] StackedSpan._depth, SpanContext.nspans
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-pytel committed Dec 5, 2020
1 parent f56f119 commit 5ae74bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
14 changes: 8 additions & 6 deletions skywalking/trace/context.py
Expand Up @@ -74,6 +74,7 @@ def __init__(self):
self.segment = Segment() # type: Segment
self._sid = Counter()
self._correlation = {} # type: dict
self._nspans = 0

def new_local_span(self, op: str) -> Span:
span = self.ignore_check(op, Kind.Local)
Expand Down Expand Up @@ -150,22 +151,23 @@ def ignore_check(self, op: str, kind: Kind):
return None

def start(self, span: Span):
self._nspans += 1
spans = _spans()
if span not in spans:
spans.append(span)

def stop(self, span: Span) -> bool:
spans = _spans()
idx = spans.index(span) # span SHOULD now always be at end even in async-world, but just in case
span.finish(self.segment)
del spans[spans.index(span)]

if span.finish(self.segment):
del spans[idx]

if len(spans) == 0:
self._nspans -= 1
if self._nspans == 0:
_local().context = None
agent.archive(self.segment)
return True

return len(spans) == 0
return False

def active_span(self):
spans = _spans()
Expand Down
22 changes: 12 additions & 10 deletions skywalking/trace/span.py
Expand Up @@ -126,11 +126,19 @@ def __exit__(self, exc_type, exc_val, exc_tb):

@tostring
class StackedSpan(Span):
_depth = 0
def __init__(self, *args, **kwargs):
Span.__init__(self, *args, **kwargs)
self._depth = 0

def finish(self, segment: 'Segment') -> bool:
def start(self):
self._depth += 1
if self._depth == 1:
Span.start(self)

def stop(self):
self._depth -= 1
return self._depth == 0 and Span.finish(self, segment)
if self._depth == 0:
Span.stop(self)


@tostring
Expand Down Expand Up @@ -159,10 +167,8 @@ def __init__(
self._max_depth = 0

def start(self):
self._depth += 1
StackedSpan.start(self)
self._max_depth = self._depth
if self._max_depth == 1:
StackedSpan.start(self)
self.component = 0
self.layer = Layer.Unknown
self.logs = []
Expand Down Expand Up @@ -217,10 +223,6 @@ def inject(self, carrier: 'Carrier') -> 'Span':
carrier.correlation_carrier.correlation = self.context._correlation
return self

def start(self):
self._depth += 1
StackedSpan.start(self)


@tostring
class NoopSpan(Span):
Expand Down

0 comments on commit 5ae74bd

Please sign in to comment.