doc/book/devrepo/debug_channels.rst
author Philippe Pepiot <ph@itsalwaysdns.eu>
Tue, 31 Mar 2020 18:22:05 +0200
changeset 12966 6cd938c29ca3
parent 12818 3954554f5b48
permissions -rw-r--r--
[server] Make connection pooler configurable and set better default values Drop the configuration connections-pool-size and add new configurations options: * connections-pool-min-size. Set to 0 by default so we open connections only when needed. This avoid opening min-size*processes connections at startup, which is, it think, a good default. * connections-pool-max-size. Set to 0 (unlimited) by default, so we move the bottleneck to postgresql. * connections-idle-timeout. Set to 10 minutes. I don't have arguments about this except that this is the default in pgbouncer.

.. -*- coding: utf-8 -*-

.. _debug_channels:

Debug Channels
==============

In *CubicWeb* 3.27 a new debug channels mechanism has been added to help build
the pyramid debug toolbar custom panels. It isn't meant to do regular CW
development but can be used for tools building (like the custom panel) if desired.

The API is really simple to use and is used like this:

.. code-block:: python

    from cubicweb.debug import subscribe_to_debug_channel, unsubscribe_to_debug_channel


    # the callback will only receive one argument which is a python dict
    # containing debug information
    def example_debug_callback(message):
        print(message)


    # "channel" must be one of: controller, rql, sql, vreg, registry_decisions
    subscribe_to_debug_channel(channel, example_debug_callback)

    # when it is not needed anymore (and to avoid dandling references)
    unsubscribe_to_debug_channel(channel, example_debug_callback)

Channels documentation
----------------------

The list of sent messages by channels:

Controller
~~~~~~~~~~

**This debug message will only be sent in a pyramid context**.
Emitted for each request.

.. code-block:: python

    {
        "kind": ctrlid,
        "request": request_object,
        "path": request_object.path,
        "controller": controller,
        "config": repo_configuration,
    }

RQL
~~~

Emitted for each query.

.. code-block:: python

    {
        "rql": rql_as_a_string,
        # arguments used to format the query
        "args": args,
        # used to link rql and sql queries
        "rql_query_tracing_token": rql_query_tracing_token,
        "callstack": python_call_stack,
        "time": time_taken_in_ms_by_the_query,
        "result": the_result_as_python_data,
        "description": description_object,
    }

SQL
~~~

Emitted for each query. Be advised that a SQL query generated by a RQL query
will be emitted before the corresponding RQL query.

.. code-block:: python

    {
        "sql": sql_as_a_string,
        # arguments used to format the query
        "args": args,
        "rollback": True|False,
        "callstack": "".join(traceback.format_stack()[:-1]),
        # used to link rql and sql queries
        "rql_query_tracing_token": rql_query_tracing_token,
        "time": time_taken_in_ms_by_the_query,
    }

vreg
~~~~

**This debug message will only be sent in a pyramid context**.
Emitted for each request.

.. code-block:: python

    {
        "vreg": vreg,
    }

registry_decisions
~~~~~~~~~~~~~~~~~~

This is emitted each time a decision is taken in a registry.

.. code-block:: python

    {
        "all_objects": [],
        "end_score": int,
        "winners": [],
        "winner": obj or None,
        "registry": obj,
        "args": args,
        "kwargs": kwargs,
    }

API Reference
=============

.. autofunction:: cubicweb.debug.subscribe_to_debug_channel
.. autofunction:: cubicweb.debug.unsubscribe_to_debug_channel