Git Product home page Git Product logo

django-tracer's Introduction

django-tracer

Build Status

Generate a UUID for all requests to Django to be used in logging and error reporting for traceability.

Why?

Why would you want to use this silly little thing? Well in a containerized, orchestrated, microservice world with centralized logging it's often hard to figure out where things have gone wrong.

This little middleware adds a UUID to the normal Django request object which you can use to add to add to things like:

  • All of your log messages
  • Error reports to Sentry/Rollbar/etc
  • Pass along to other internal services

Along with generating and attaching a UUID to each request, the middleware also automatically adds the UUID to the response headers as X-Request-ID so anyone consuming your responses, say as an API, can use that as a reference point for reporting errors back to you.

Installation

First you need to install it via pip:

pip install django-tracer

Then just add tracer to INSTALLED_APPS in your settings.

Then add tracer.middleware.RequestID to the top of your MIDDLEWARE settings.

Usage with standard logging

import logging

from django.http import HttpResponse

logger = logging.getLogger(__name__)

def some_view(request):
    """ simple log example """
    logger.info("Whee!", extra={'request_id': request.id})
    return HttpResponse("example content")

Other ways to use this Request ID

There are several other places you may consider wanting to use the ID to improve traceability:

  • Pass it as an argument to any Celery tasks you generate so there is a clear path between the incoming request and the tasks that were generated from it
  • Pass it as a header or argument to other internal APIs or services
  • Attach it to a bound structlog object so it is always included in your log output

Thanks!

Special thanks to Rolf Håvard Blindheim for graciously turning over the name django-tracer to us to be able to use it for this project.

Need help?

REVSYS can help with your Python, Django, and infrastructure projects. If you have a question about this project, please open a GitHub issue. If you love us and want to keep track of our goings-on, here's where you can find us online:

django-tracer's People

Contributors

frankwiles avatar jefftriplett avatar rhblind avatar

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.