Skip to main content

Python library to aid consistent configuration of logging, metrics (future) and tracing (further in future). Packaging and wiring existing open tooling to work effortlessly on UIS DevOps managed cloud infrastructure.

Project description

Observability Python Library

Currently a POC in the Wilson team. Python library to aid consistent configuration of logging, metrics (future) and tracing (further in future). Packaging and wiring existing open tooling to work effortlessly on UIS DevOps managed cloud infrastructure.

Install this module

pip install ucam-observe

Usage

Logging

NOTE: Currently only vanilla python is supported, not Django.

Usage is similar to using structlog directly with the function get_structlog_logger returning an object compatible with that returned by structlog's get_logger function. No further configuration is needed.

logger = get_structlog_logger(__name__)

logger.info("some_event")

logger.info("some_other_event", foo=bar)

Metrics and Tracing

raise NotImplemented

Include Gunicorn structlog configuration in your project

Adapt Gunicorn configuration

In the root of your project, create/amend a gunicorn.conf.py. Add the following code to the file.

from ucam_observe.gunicorn import (  # noqa F401 used by gunicorn as magic variable
    logconfig_dict
)

Be sure not to set any log config values via the CLI or config files.

Environment Configuration

Log Level

Set the LOG_LEVEL environment variable to control the logging level (e.g., DEBUG, INFO, WARNING, ERROR, CRITICAL). This setting adjusts the verbosity of the log outputs:

export LOG_LEVEL=DEBUG

Console Logging

Set the CONSOLE_LOGGING environment variable to control whether logs should be output in a console-friendly format. Set it to True to use console-friendly formatting:

export CONSOLE_LOGGING=True

Example Docker Compose Configuration

When using Docker Compose for local development, you can set the environment variables in your docker-compose.yml file:

version: '3.8'
services:
  your_service:
    build: .
    environment:
      - LOG_LEVEL=DEBUG
      - CONSOLE_LOGGING=True

Developer quickstart

Firstly, install docker-compose. Install poethepoet

pip install poethepoet

Then, most tasks can be performed via the poe command.

E.g.

# Build the containers
$ poe build

Run the follow command to see available commands:

$ poe

Optional extras

NOTE: The Django optional extra is currently empty with a ticket open to add the required functionality

This library includes optional extras, e.g. ucam-observe[django]. Some tests will require these optional dependencies to pass. The following command will install all optional dependencies.

$ poe install-all-extras

Some tests require the absence of dependencies and these are excluded by default. See the tox.ini file for how these tests are run.

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

ucam_observe-0.2.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

ucam_observe-0.2.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file ucam_observe-0.2.1.tar.gz.

File metadata

  • Download URL: ucam_observe-0.2.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for ucam_observe-0.2.1.tar.gz
Algorithm Hash digest
SHA256 af903f323b1e431d4f2e470c3e781ebf01c3d485dc0d17d0dddce651feb5ca03
MD5 c875ee56fed7f81f4a20944e3e1eefc4
BLAKE2b-256 409dc933b52d15e2fa13ab2f4bf6e4767b5bd79d8c545b2881ed16beb433b36a

See more details on using hashes here.

File details

Details for the file ucam_observe-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: ucam_observe-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for ucam_observe-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 58106515f13ff2b2ccb4834ddd582e759360d7b714c98dab25a21dcd727b04cd
MD5 144aceda0a8031b4c806194b9c20d2a6
BLAKE2b-256 17e02f124426d2b50dd9b7d2da4e63197d95929ce6ff0aa25e0d8cf2f59b3c05

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