Skip to content

Commit

Permalink
Merge pull request #35 from nameko/pretty-json-formatter
Browse files Browse the repository at this point in the history
Pretty json formatter and health check filter
  • Loading branch information
iky committed Dec 3, 2020
2 parents 31d7ba0 + 89ae68a commit 0f9e321
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 103 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ jobs:
env: DEPS="nameko>=2.12.0"
- python: 3.5
env: DEPS="nameko>=2.12.0"

matrix:
allow_failures:
- python: 3.6
env: DEPS="--pre nameko"
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ Release Notes
=============


Version 1.3.0
-------------

Release 2020-12-02

* Add PrettyJSONFormatter useful for development of Nameko services
* Add HealthCheckTraceFilter useful for filtering out healthcheck entrypoint traces


Version 1.2.0
-------------

Expand Down
2 changes: 0 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
Nameko Entrypoint Tracer
========================

TODO introduction ...

Usage
=====

Expand Down
12 changes: 12 additions & 0 deletions nameko_tracer/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,15 @@ def truncate(self, data):


TruncateRequestFilter = TruncateCallArgsFilter


class HealthCheckTraceFilter(logging.Filter):
def filter(self, record):
try:
return record.worker_ctx.entrypoint.url not in [
"/health-check",
"/health_check",
"/healthcheck",
]
except AttributeError:
return True
11 changes: 8 additions & 3 deletions nameko_tracer/formatters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
from functools import partial

from nameko_tracer import constants

Expand All @@ -8,16 +9,20 @@ def default(obj):
return str(obj)


def serialise(obj):
return json.dumps(obj, default=default)
serialise = partial(json.dumps, default=default)


class JSONFormatter(logging.Formatter):
""" Format trace data as JSON string
"""
def __init__(self, **option):
self.option = option

def format(self, record):
return serialise(getattr(record, constants.TRACE_KEY))
return serialise(getattr(record, constants.TRACE_KEY), **self.option)


PrettyJSONFormatter = partial(JSONFormatter, indent=4, sort_keys=True)


class ElasticsearchDocumentFormatter(JSONFormatter):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='nameko-tracer',
version='1.2.0',
version='1.3.0',
description='Nameko extension logging entrypoint processing metrics',
author='student.com',
author_email='[email protected]',
Expand Down
Loading

0 comments on commit 0f9e321

Please sign in to comment.