semvec/pypi-packages huggingface dataset:
django-newrelic-middleware 0.0.4
New Relic middleware for Django
License: BSD
Keywords: Django,middleware,newrelic,log,logs,logging

# django-newrelic-middleware
forked from [django-newrelic-extensions](https://github.com/SheepDogInc/django-newrelic-extensions) see [LICENSE](LICENSE)

This package provides a Django middleware class that attaches custom attributes
to the stack trace that the New Relic agent sends to your console.  For
example, if a server error occurs you may wish to know the username of the user
who received it.


## Installation
Install via pip:
```shell
pip install django-newrelic-middleware
```

Or from GitHub:
```
pip install git+https://github.com/robotstech/django-newrelic-middleware.git
```

Add the middleware class to your ``MIDDLEWARE_CLASSES``:
```python
MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django_newrelic_middleware.middleware.NewRelicMiddleware',
)
```

## Settings
* ``NEW_RELIC_EXTENSIONS_ENABLED``: This allows you to disable the extensions
  during development. (Default: ``False``)

* ``NEW_RELIC_EXTENSIONS_DEBUG``: This enables the extensions but instead of
  sending trace backs to New Relic, it prints them out to the console.
  (Default: ``True``)

* ``NEW_RELIC_EXTENSIONS_ATTRIBUTES``: This is how you specify what attributes
  of the Django ``HttpRequest`` instance you care about.  This should be a ``dict``.
  Please see below for examples.

## Examples
```python
NEW_RELIC_EXTENSIONS_ATTRIBUTES = {
    'user': {
        'username': 'Django username',
        'is_superuser': 'Django super user'
    },
    'is_secure': 'Django secure connection',
    'something random': 'Name'
}
```

This will log the user's username under the key of ``Django username`` and so
on.  If a variable is callable (like ``is_secure`` above), it will be called.
If it doesn't exist, it will silently die (unless you have `DEBUG` on).

For a list of examples attributes that you can log, see the `HttpRequest docs
<https://docs.djangoproject.com/en/dev/ref/request-response/#httprequest-objects>`_.

### Ideas
* View decorator
* Regex-based URL matcher (e.g. only log stuff on certain URLs)
* Execute a function and log the result


## License
BSD, short and sweet.