Giter Club home page Giter Club logo

Comments (3)

mattbennett avatar mattbennett commented on July 23, 2024 9

This is a great question that we don't touch on in the docs (but should).

Short answer:

Nameko does't dictate any particular tool. At onefinestay we log exceptions to sentry, timing stats to graphite and entrypoint invocation (service and method name, arguments, call stack, success/error status, result bytes, response time etc.) to elasticsearch/logstash. This is a really powerful setup for debugging across multiple services.

Each of these loggers are service dependencies, and we intend to open source each of them as community extensions.

Longer answer:

One of the nice things about nameko's dependency injection pattern is the integration with the worker lifecycle. DependencyProvider extensions are notified when workers are setup, torn down, and generate a result. A trivial logging dependency might look like:

class LoggingDependency(DependencyProvider):

    def __init__(self):
        self.timestamps = WeakKeyDictionary()

    def worker_setup(self, worker_ctx):

        self.timestamps[worker_ctx] = datetime.datetime.now()

        service_name = worker_ctx.service_name
        method_name = worker_ctx.entrypoint.method_name

        log.info("Worker %s.%s starting", service_name, method_name)

    def worker_result(self, worker_ctx, result=None, exc_info=None):

        service_name = worker_ctx.service_name
        method_name = worker_ctx.entrypoint.method_name

        if exc_info is None:
            status = "completed"
        else:
            status = "errored"

        now = datetime.datetime.now()
        worker_started = self.timestamps.pop(worker_ctx)
        elapsed = (now - worker_started).seconds

        log.info("Worker %s.%s %s after %ss",
                 service_name, method_name, status, elapsed)

Then you can add it to your service in a nicely decoupled way:

class Service(object):
    name = "myservice"

    logger = LoggingDependency()  # << just add this line

    @rpc
    def method(self, arg):
        ...

from nameko.

dAnjou avatar dAnjou commented on July 23, 2024

Really nice answer, thank you very much!

from nameko.

mattbennett avatar mattbennett commented on July 23, 2024

This issue was moved to https://discourse.nameko.io/t/how-do-you-do-monitoring/319

from nameko.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.