Skip to content

deep.api.plugin.python

Simple plugin for deep, decorating some python information.

PythonPlugin

Bases: ResourceProvider, SnapshotDecorator, TracepointLogger

Deep python plugin.

This plugin provides the python version to the resource, and the thread name to the attributes.

Source code in deep/api/plugin/python.py
class PythonPlugin(ResourceProvider, SnapshotDecorator, TracepointLogger):
    """
    Deep python plugin.

    This plugin provides the python version to the resource, and the thread name to the attributes.
    """

    def decorate(self, snapshot_id: str, context: ActionContext) -> Optional[BoundedAttributes]:
        """
        Decorate a snapshot with additional data.

        :param snapshot_id: the id of the collected snapshot
        :param context: the action context for this action

        :return: the additional attributes to attach
        """
        thread = threading.current_thread()

        return BoundedAttributes(attributes={
            'thread_name': thread.name
        })

    def resource(self) -> Optional[Resource]:
        """
        Provide resource.

        :return: the provided resource
        """
        return Resource({
            "python_version": platform.python_version(),
        })

    def log_tracepoint(self, log_msg: str, tp_id: str, ctx_id: str):
        """
        Log the dynamic log message.

        :param (str) log_msg: the log message to log
        :param (str) tp_id:  the id of the tracepoint that generated this log
        :param (str) ctx_id: the id of the context that was created by this tracepoint
        """
        logging.info(log_msg + " ctx=%s tracepoint=%s" % (ctx_id, tp_id))

decorate(snapshot_id, context)

Decorate a snapshot with additional data.

:param snapshot_id: the id of the collected snapshot :param context: the action context for this action

:return: the additional attributes to attach

Source code in deep/api/plugin/python.py
def decorate(self, snapshot_id: str, context: ActionContext) -> Optional[BoundedAttributes]:
    """
    Decorate a snapshot with additional data.

    :param snapshot_id: the id of the collected snapshot
    :param context: the action context for this action

    :return: the additional attributes to attach
    """
    thread = threading.current_thread()

    return BoundedAttributes(attributes={
        'thread_name': thread.name
    })

log_tracepoint(log_msg, tp_id, ctx_id)

Log the dynamic log message.

:param (str) log_msg: the log message to log :param (str) tp_id: the id of the tracepoint that generated this log :param (str) ctx_id: the id of the context that was created by this tracepoint

Source code in deep/api/plugin/python.py
def log_tracepoint(self, log_msg: str, tp_id: str, ctx_id: str):
    """
    Log the dynamic log message.

    :param (str) log_msg: the log message to log
    :param (str) tp_id:  the id of the tracepoint that generated this log
    :param (str) ctx_id: the id of the context that was created by this tracepoint
    """
    logging.info(log_msg + " ctx=%s tracepoint=%s" % (ctx_id, tp_id))

resource()

Provide resource.

:return: the provided resource

Source code in deep/api/plugin/python.py
def resource(self) -> Optional[Resource]:
    """
    Provide resource.

    :return: the provided resource
    """
    return Resource({
        "python_version": platform.python_version(),
    })