Skip to main content

It helps to get the context of a frame from the caller's stack. Can be used to improve service and microservice logs.

Project description

Stack Frame Analyzer

This package was created to help improve the quality of application logs.

It's only uses building libraries, therefore, it has no external dependency. It is also lightweight and thread-safe, which makes it ideal for use in services and micro-services.

However, the module has some limitations. The most important thing to note in this scenario is that it only works with the CPython implementation.

The returned context is formatted according to the following pattern: project_name:package_name:module_name:class_name:callable_name(callable_arguments)

An example of the context returned could be: authentication_service:src.domain.user:model:UserModel:has_permission(self=..., permission="add_user")

Typical usage example:

With Caller's Stack Frame Depth 1

stack_frame_analyzer = StackFrameAnalyzer("my_service_name")

def foo(bar):
    try:
        ...
    except Exception as error:
        context = stack_frame_analyzer.get_frame_context()
        logging.error(context)

With Caller's Stack Frame Depth 2

stack_frame_analyzer = StackFrameAnalyzer("my_service_name")

class MyException(Exception):
    def __init__(self):
        self.context = stack_frame_analyzer.get_frame_context(stack_frame_depth=2)
        super().__init__()


def foo(bar):
    try:
        ...
    except MyException as error:
        logging.error(error.context)

With Caller's Stack Frame Depth 3


class ExceptionWithContext(Exception):
    def __init__(self, message: str):
        self.message = message
        self.context = stack_frame_analyzer.get_frame_context(stack_frame_depth=3)
        super().__init__(self.message)


class FooException(ExceptionWithContext):
    '''Foo Exception'''

    def __init__(self, message: str = "message"):
        self.message = message
        super().__init__(self.message)


def foo(bar):
    try:
        raise FooException
    except FooException as error:
        logging.error(error.context)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Stack Frame Analyzer-0.1.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Stack_Frame_Analyzer-0.1.2-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file Stack Frame Analyzer-0.1.2.tar.gz.

File metadata

  • Download URL: Stack Frame Analyzer-0.1.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for Stack Frame Analyzer-0.1.2.tar.gz
Algorithm Hash digest
SHA256 67f38771d52a7368b7aaf6e3bdee49ebb09a0d1fda6884fa30b6d721e4d75451
MD5 46bd60ba39dfb959e760cad5915952a6
BLAKE2b-256 8c8a5acf12e252e8862a61e4a64cfd55fbfd57a21b1a36486423ffbb02d25e5b

See more details on using hashes here.

File details

Details for the file Stack_Frame_Analyzer-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: Stack_Frame_Analyzer-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for Stack_Frame_Analyzer-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b05b40059f7bba3afa9ec436f192ebef88a3ee1818bf287d63be9b19eef99899
MD5 73eef8f7d7f34ba1e4837172fac724be
BLAKE2b-256 df932275e57544f2bee89ddc3c29411e4f24fd3d25e535bc286500a625a7f34a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page