Skip to content

deep.processor.context.span_action

Handling for span actions.

SpanActionCallback

Bases: ActionCallback

Action callback to close created spans.

Source code in deep/processor/context/span_action.py
class SpanActionCallback(ActionCallback):
    """Action callback to close created spans."""

    def __init__(self, spans):
        """Create callback."""
        self.__spans = spans

    def process(self, ctx: 'TriggerContext', event: str, frame: FrameType, arg: any) -> bool:
        """
        Process a callback.

        :param ctx: the context for this trigger
        :param event: the event
        :param frame: the frame data
        :param arg: the arg from settrace
        :return: True, to keep this callback until next match.
        """
        for span in self.__spans:
            span.close()
        return False

__init__(spans)

Create callback.

Source code in deep/processor/context/span_action.py
def __init__(self, spans):
    """Create callback."""
    self.__spans = spans

process(ctx, event, frame, arg)

Process a callback.

:param ctx: the context for this trigger :param event: the event :param frame: the frame data :param arg: the arg from settrace :return: True, to keep this callback until next match.

Source code in deep/processor/context/span_action.py
def process(self, ctx: 'TriggerContext', event: str, frame: FrameType, arg: any) -> bool:
    """
    Process a callback.

    :param ctx: the context for this trigger
    :param event: the event
    :param frame: the frame data
    :param arg: the arg from settrace
    :return: True, to keep this callback until next match.
    """
    for span in self.__spans:
        span.close()
    return False

SpanActionContext

Bases: ActionContext

Action for spans.

Source code in deep/processor/context/span_action.py
class SpanActionContext(ActionContext):
    """Action for spans."""

    def can_trigger(self) -> bool:
        """
        Check if the action can trigger.

        If we do not have a span processor enabled, then skip this action.
        :return: True, if the trigger can be triggered.
        """
        if self.trigger_context.config.has_span_processor:
            return super().can_trigger()
        return False

    def _process_action(self):
        name = self._span_name
        if name is None:
            return

        spans = []

        for span_processor in self.trigger_context.config.span_processors:
            span = span_processor.create_span(name, self.trigger_context.id, self.location_action.tracepoint.id)
            if span:
                spans.append(span)

        if len(spans) > 0:
            self.trigger_context.attach_result(SpanResult(spans))

    @property
    def _span_name(self):
        location = self.location_action.location
        if location:
            return location.name

can_trigger()

Check if the action can trigger.

If we do not have a span processor enabled, then skip this action. :return: True, if the trigger can be triggered.

Source code in deep/processor/context/span_action.py
def can_trigger(self) -> bool:
    """
    Check if the action can trigger.

    If we do not have a span processor enabled, then skip this action.
    :return: True, if the trigger can be triggered.
    """
    if self.trigger_context.config.has_span_processor:
        return super().can_trigger()
    return False

SpanResult

Bases: ActionResult

Action result to map to callback.

Source code in deep/processor/context/span_action.py
class SpanResult(ActionResult):
    """Action result to map to callback."""

    def __init__(self, spans):
        """Create result."""
        self.__spans = spans

    def process(self, ctx: 'TriggerContext') -> Optional[ActionCallback]:
        """
        Process this result.

        :param ctx: the triggering context

        :return: an action callback if we need to do something at the 'end', or None
        """
        return SpanActionCallback(self.__spans)

__init__(spans)

Create result.

Source code in deep/processor/context/span_action.py
def __init__(self, spans):
    """Create result."""
    self.__spans = spans

process(ctx)

Process this result.

:param ctx: the triggering context

:return: an action callback if we need to do something at the 'end', or None

Source code in deep/processor/context/span_action.py
def process(self, ctx: 'TriggerContext') -> Optional[ActionCallback]:
    """
    Process this result.

    :param ctx: the triggering context

    :return: an action callback if we need to do something at the 'end', or None
    """
    return SpanActionCallback(self.__spans)