Skip to main content

A lighweight functional tracer and log enhancer

Project description

PyBreadCrumbs

pybreadcrumbs is a lightweight function tracer and log enhancer for distributed systems written in python.

Inspiration

  • The inspiration for PyBreadCrumbs came to solve the daily trouble that we faced in our organisation in searching and sorting system logs that were generated.
  • It solves this by adding an extra key value pair to the log data which adds tracability to the logs.
  • It also adds an extra key value pair to add simple time taken based profiling as well.
  • It doesn't wish to compete with fully functional tracer or profiler nor it is a replacement for them, It's just there to make your logs more streamlined, readable and tracable.

Getting Started

Prerequisites

A project of course where you want to integrate breadcrumbs.

Installing

  • To be added

Configuring

  • import the breadcrumbs configuration at the root python file from where the execution starts.
  • from breadcrumbs.configuration import breadcrumbs_config
  • breadcrumbs_config is a config dictionary with following options.
  • trace_id_prefix : the prefix which will be appended to system generated trace id.
  • key_prefix : the prefix which will be added to the keys of breadcrumbs log_payload.
  • timezone : the timezone string for datetime in log_payload. default value is UTC
  • datetime_format : The datetime formate to be used in log_payload default value is %Y-%m-%d %H:%M:%S.%f
  • additional_keys : Additional keys that you wish to add to the tracable log payload.
  • extraction_fallback_level: this defines the stack trace level that a trace decorator should look for trace_id before creating a new trace id of it's own.

Using

  • Import the decorators add_bowl using.
  • from breadcrumbs.base import add_bowl
  • use the decorator on any function you would like to trace.
  • the fuction in which it is used needs to accept kwargs in function parameters.
  • to enhance other logging calls inside the function fetch the bowl object using
  • breadcrumbs_bowl = kwargs.get("breadcrumbs_bowl")
  • then whenever logging something pass extra=breadcrumbs_bowl.log_payload in your logging call.
  • eg. logger.info("test message that should be tracable", extra=breadcrumbs_bowl.log_payload)
  • you can also add a trace_text to your log_payload by using below method.
  • eg. logger.info("test message that should be tracable", extra=breadcrumbs_bowl.add_trace_text("CodeEventName"))
  • During the function call if you wish to add some meta data to the next logging call you can store those meta data in the bowl object using add_trace_meta function.
  • eg. breadcrumbs_bowl.add_trace_meta(key1="string_value", key2=45)
  • The next logging call using bowl object in the same function will log this meta as well.

Running the tests

  • will be added

Built With

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Hitesh Jha

  • See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details

Future enhancements

  • Ensure child actions have a refrence to thier parents action.
  • Ensure correct time taken is calculated when in an async environment.

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

pybreadcrumbs-0.0.1.tar.gz (8.7 kB view hashes)

Uploaded Source

Built Distribution

pybreadcrumbs-0.0.1-py3-none-any.whl (8.3 kB view hashes)

Uploaded Python 3

Supported by

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