Skip to main content

opentelemetry formatter for python logging module.

Project description

logging-opentelemetry-format

a simple logging formatter which can be used to format logs to opentelemetry specification coming out from a system. it also provides some additional size control over log body and log attributes

Installation

  • from pypi
pip install logging_opentelemetry_format

Usage

  • check example for a complete example
  • the formatter is available as
from logging_opentelemetry_format.utils import OpentelemetryLogFormatter
  • on a basic level this formatter can be added to a logging handler
  • it takes following optional keyword arguments
  • use_traces: use the traces information to enrich logs or not(trace_id and span_id)
  • restrict_attributes_to: list of attributes to which log's attributes should be restricted, any extra attributes passed inside extra keywords in logs will be added against _meta inside attributes.
  • meta_character_limit: the max length of value for _meta in output logs' attributes, if the length of log's meta exceeds this limit the value of log's meta will be trimmed to specified length. also an attribute _meta_original_length is added with value as the length of original log meta and _meta_too_large with value true for debugging purpose.
  • body_character_limit: the max length of value for log body, if the length of log body exceeds this limit the value of log body will be trimmed to specified value. also an attribute _body_original_length is added with value as the length of original log body and _body_too_large with value true for debugging purpose.
  • discard_attributes_from: an array of attributes which needs to be skipped when exporting logs

Local development and testing

  • build the docker-image of the package docker-compose build --no-cache
  • run the image docker-compose up
  • go to the container docker exec -it loggingoplttester sh
  • to run tests pytest tests/ to run the actual tests.

License

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

logging_opentelemetry_format-0.0.3.tar.gz (4.9 kB view details)

Uploaded Source

File details

Details for the file logging_opentelemetry_format-0.0.3.tar.gz.

File metadata

File hashes

Hashes for logging_opentelemetry_format-0.0.3.tar.gz
Algorithm Hash digest
SHA256 fd563fa5514cc68674e7e849d2cbdc8fb1cff118cfc1c9e59d79043a22798215
MD5 a9cc7e10eb785642136b90b9dbe312bd
BLAKE2b-256 85c9d92bf5f2e2dee4690b36ca59084cc63005e57bf52917b2c67cc3f4886dbe

See more details on using hashes here.

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