Search code examples
pythonloggingtracelttng

Logging + Lttng framework logs not available


I am using logging + lttng as logging and tracing framework but I am not able to view the logs using lttng view it just gives me the path of the logs

I am using the following example

Python Example

import lttngust
import logging
import time


def example():
    logging.basicConfig()
    logger = logging.getLogger('my-logger')

    while True:
        logger.debug('debug message')
        logger.info('info message')
        logger.warn('warn message')
        logger.error('error message')
        logger.critical('critical message')
        time.sleep(1)


if __name__ == '__main__':
    example()

Following commands are executed to enable lttng

Steps

lttng create
lttng enable-event --python my-logger
lttng start

Run the Python script:

python test.py

Stop tracing and inspect the recorded events:

lttng stop
lttng view //Not working as expected

On running lttng view

vinay@root:~/lttng-traces/auto-20180917-121542/ust/uid/1003/64-bit/index$ lttng view
Trace directory: /home/vinay/lttng-traces/auto-20180917-121542

Solution

  • You mentioned in the comments that you are running on lttng-tools 2.10.2. This version affected by a bug with the Python tracing agent.

    The bug makes it impossible to trace python applications when the user is not part of the tracing group and the lttng session daemon is running as root. This requirement normally only exists for kernel tracing. You are encountering this bug because systemd launches a root lttng session daemon at startup.

    You can easily test if it's indeed this bug by logging in as root and killing the root lttng session daemon and running a session daemon as your own non-root user like this:

    As root:

    pkill lttng-sessiond
    

    As your non-root user:

    lttng-sessiond -d
    lttng create
    lttng enable-event --python my-logger
    lttng start
    python test.py
    ...
    <ctrl + c>
    lttng stop
    lttng view
    

    If you get events now then your are affected by the bug. This bug has been fixed in the 2.10 branch and will make it to the Ubuntu packages.

    Until the package gets updated, you can add yourself to the tracing group or prevent systemd from launch a root lttng session daemon on startup.