Skip to main content

Nameko extension exposing a structlog dependency injector

Project description

Structlog as nameko extension

  • Free software: Apache Software License 2.0

Extension for nameko that replaces python logging module with structlog. The idea behind this module is to use JSONRenderer to be able to use advanced log aggregation and analysis tools like Logstash.

Apart from JSONRenderer structlog processor, it’s also supported KeyValueRenderer processor.


To install nameko-structlog, simply use pip.

pip install nameko-structlog


Add Structlog log level to your nameko config file:

 # config.yml when using JSONRenderer
      sort_keys: true
       pin: 1234
       env: dev

  version: 1
      format: "%(message)s"

      class: logging.StreamHandler
      formatter: simple

    level: DEBUG
    handlers: [console]

Option INCLUDE_WORKER_NAME will add or not worker_ctx.call_id to every log entry. Option INCLUDE_LOG_TRANSACTON_ID will group all logs that refer to same nameko entrypoint, with a unique log_transaction_id. Doing so may be useful to follow request/data flow on a log aggregation tool. Option EXTRA_PARAMETERS can contain any keys that you want to appear on every log entry.

Include the StructlogDependency dependency in your service class:

from nameko.rpc import rpc

from nameko_structlog import StructlogDependency

class MyService(object):
   name = "demo"

   log = StructlogDependency()

   def my_method(self, name):"Your name is {name}", type="greeting")

Run your service, providing the config file:

$ nameko run service --config config.yaml

$ nameko shell --config config.yaml
>>> n.rpc.demo.my_method("Alice")
{"level": "info", "log_transaction_id": "b2cd5506-339e-4e59-9a14-a3cd7548bfe5", "logger": "demo", "env": "dev", message": "Your name is Alice", "pin": "1234", "timestamp": "2020-09-27T11:24:30.379918Z", "type": "greeting"}


This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.


0.2.1 (2020-12-28)

  • Fix bug #8.

0.2.0 (2020-12-28)

  • Drop indent=2 for log records
  • Drop colorama and development mode.
  • Support two structlog processors, JSONRenderer and KeyValueRenderer.
  • Configuration is more clean now.
  • Decouple Structlog configuration from nameko dependency.

0.1.1 (2018-10-29)

  • First release on PyPI.

Project details

Download files

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

Files for nameko-structlog, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size nameko_structlog-0.2.1-py2.py3-none-any.whl (5.4 kB) File type Wheel Python version py2.py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page