12. 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:

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)

12.1. Channels documentation#

The list of sent messages by channels:

12.1.1. Controller#

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

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

12.1.2. RQL#

Emitted for each query.

{
    "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,
}

12.1.3. SQL#

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

{
    "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,
}

12.1.4. vreg#

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

{
    "vreg": vreg,
}

12.1.5. registry_decisions#

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

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

13. API Reference#

cubicweb.debug.subscribe_to_debug_channel(channel, subscriber)[source]#
cubicweb.debug.unsubscribe_to_debug_channel(channel, subscriber)[source]#

Unsubscribe a callable from a channel. It will raise Exception if the channel doesn’t exist nor