Skip to main content

README

Disclaimer

The Kieker language pack for Python is in an early stage. Thus, it may not operate as expected in all scenarios. We applied it to the Spyder IDE and other programs successfully and to parts of Tensorflow with limited results.

Installation

Prerequisites:

  • python >=3.15
  • build package (pip install build)
  1. clone this repository
  2. cd ./kieker-lang-pack-python
  3. run python3 -m build
  4. pip install dist/kieker-monitoring-for-python-0.0.3.tar.gz

Instrumentation

Invasive Approach

This is the most basic and invasive approach. Currently, it also offers the most control over the instrumentation. Let's assume that you want to log following function every time it is called.

example.py

def some_function():
      print('Hello World!')
example.py

import tools.const as con

def some_function():
      print('Hello World!')

Now we have everything we need to log the function execution. At the current stage of development there are three record types with following entries.

  • BeforeOperationEvent: timestamp in ms, traceId, traceOrder, function_name, fully qualified name of caller class
  • AfterOperationEvent: timestamp in ms, traceId, traceOrder, function_name, fully qualified name of caller class
  • AfterOPerationFailedEvent: timestamp in ms, traceId, traceOrder, function_name, fully qualified name of caller class, error name

Create a record object and pass it to the monitoring controler via new_monitoring_record(). In our example we use BeforeExecutionRecord and AfterExecutionRecord.

example.py

import const as con
from monitoring.record.trace.operation.operationevent import (BeforeOperationEvent,
                                                              AfterOperationEvent, 
                                                              AfterOperationFailedEvent, 
                                                              )
                           
ctrl = MonitoringController('/path/to/config.ini')

def some_function():
      trace_reg = con.trace_reg
      trace = trace_reg.get_trace()
        if(trace is None):
            trace = trace_reg.register_trace()
            monitoring_controller.new_monitoring_record(trace)
      trace_id = trace.trace_id
      timestamp = ctrl.timesource_ctrl.get_time()
      before_record = BeforeOperationevent(timestamp, trace_id, trace.get_next_order_id(), 'some_function','example.some_function')
      ctrl.new_monitoring_record(before_record)
      print('Hello World!')
      timestamp = ctrl.timesource_ctrl.get_time()
      after_record = AfterOperationEvent(timestamp, trace_id, trace.get_next_order_id(), 'some_function','example.some_function')
      ctrl.new_monitoring_record(after_record)

Semi Invasive Approach

The above method gives us full control over program instrumentation, but it also requieres a lot of manual work. But this approach alters your own code logic, which might not be a problem for small projects, but for larger code basis it becomes a tedious job to keep an overview. To minimize the grade of source code manipulation you can use an Instrument decorator. By anotation a function or method with @Instrument you can save a lot of typing. Consider the following example.

example.py
from tools.aspect import instrument
from monitoring.controller import MonitoringController

monitoring_controller = MonitoringController('/path/to/config.ini') # Always instatiate a controller

@instrument
def some_function():
      print('Hello World!')

Import Hooks

We also provide two import Hooks. They are used in similar manner. All you have to do is to add either PostImportFinder or InstrumentOnImportFinder to the sys.meta_path in the module which is a an entry point for your python program. Bellow we show all the necessary API to do that.

Post Import Hook

from tools.importhook import PostImportFinder
from monitoring.controller import MonitoringController

pattern_object = re.compile('YOUR REGEX') # Some regex to describe which modules should be instrumented
exclude_modules = list() # List with explicit strings of modules which should be excluded from the instrumentations
some_var = MonitoringController('/path/to/config.ini')
sys.meta_path.insert(0, PostImportFinder(pattern_object, exclude_modules))

Pre Import Hook

import re
from tools.aspect import decorate_find_spec
from tools.importhookast import  InstrumentOnImportFinder

ex=list()
sys.meta_path.insert(0, InstrumentOnImportFinder(ignore_list=ex, empty=False,  debug_on=True))

Metadata

Release files for kieker-monitoring-for-python 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kieker-monitoring-for-python 0.0.3
File Size Uploaded Provenance Actions
kieker_monitoring_for_python-0.0.3.tar.gz 17.5 kB Without provenance Details for kieker_monitoring_for_python-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kieker-monitoring-for-python 0.0.3
File Interpreter ABI Platform Actions
kieker_monitoring_for_python-0.0.3-py3-none-any.whl Python 3 none any Details for kieker_monitoring_for_python-0.0.3-py3-none-any.whl

Total release size: 40.4 kB

Release files / kieker_monitoring_for_python-0.0.3.tar.gz

Download URL kieker_monitoring_for_python-0.0.3.tar.gz
Size 17.5 kB
Tags Source
SHA-256 checksum
How to use checksums
09f71a7afba40b2ba428a11faef541bc590ef945140b2d90fce3eb0d4ed5f31b
BLAKE2b-256 checksum
How to use checksums
dac994c0bb01443cba7dbb6c73eff7d5de3cb00085183a1d2089f86325f8f77e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Release files / kieker_monitoring_for_python-0.0.3-py3-none-any.whl

Download URL kieker_monitoring_for_python-0.0.3-py3-none-any.whl
Size 23.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ae83c34d690db6a9866404952a25f11088ee2bc4d8a75a49cee0b2c317d6a4f
BLAKE2b-256 checksum
How to use checksums
fe98c788def3a14dc6c5c509d3073695fd50b880f6c589a39765135d2266892c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Security for kieker-monitoring-for-python 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page