Skip to content

Enabling debug

Return debug info in backend responses

By default, server does not add error details to response bodies, to avoid exposing instance-specific information to end users.

With debug disabled:

config.yml
server:
  debug: false
$ curl -XPOST http://localhost:8000/failing/endpoint ...
{
    "error": {
        "code": "unknown",
        "message": "Got unhandled exception. Please contact support",
        "details": null,
    },
}

With debug enabled:

config.yml
server:
  debug: true
$ curl -XPOST http://localhost:8000/failing/endpoint ...
Traceback (most recent call last):
File ".../uvicorn/protocols/http/h11_impl.py", line 408, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
    return await self.app(scope, receive, send)

Warning

This is only for development environment only. Do NOT use on production!

See Logging settings, but replace log level INFO with DEBUG.

Fill up X-Request-ID header on backend

Server can add X-Request-ID header to responses, which allows to match request on client with backend response.

This is done by request_id middleware, which is enabled by default and can configured as described below:

RequestIDSettings

X-Request-ID Middleware Settings.

See asgi-correlation-id documentation.

Examples:

config.yml
server:
  request_id:
    enabled: true
    update_request_header: true

Parameters:

  • enabled

    (bool, default: True ) –

    Set to True to enable middleware

  • header_name

    (str, default: 'X-Request-ID' ) –

    Name of response header which is filled up with request ID value

  • update_request_header

    (bool, default: False ) –

    If False, bypass header value from request to response as-is.

    If True, always set new value of specific header.

This is done by adding a specific filter to logging handler:

config.yml
logging:
    filters:
        correlation_id:
            (): asgi_correlation_id.CorrelationIdFilter
            uuid_length: 32
            default_value: '-'

Resulting logs look like:

2023-12-18 17:14:11.711 uvicorn.access:498 [INFO] 018c15e97a068ae09484f8c25e2799dd 127.0.0.1:34884 - "GET /monitoring/ping HTTP/1.1" 200

Use X-Request-ID header on client

If client got X-Request-ID header from backend, it is printed to logs with DEBUG level:

>>> import logging
>>> logging.basicConfig(level=logging.DEBUG)
>>> client.ping()
DEBUG:urllib3.connectionpool:http://localhost:8000 "GET /monitoring/ping HTTP/1.1" 200 15
DEBUG:horizon.client.base:Request ID: '018c15e97a068ae09484f8c25e2799dd'

Also, if backend response was not successful, Request ID is added to exception message:

>>> client.get_namespace("unknown")
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http://localhost:8000/v1/namespaces/unknown
Request ID: '018c15eb80fa81a6b38c9eaa519cd322'

Fill up X-Application-Version header on backend

Server can add X-Application-Version header to responses, which allows to determine which version of backend is deployed.

This is done by application_version middleware, which is enabled by default and can configured as described below:

ApplicationVersionSettings

X-Application-Version Middleware Settings.

Examples:

config.yml
server:
  application_version:
    enabled: true
    header_name: X-Application-Version

Parameters:

  • enabled

    (bool, default: True ) –

    Set to True to enable middleware

  • header_name

    (str, default: 'X-Application-Version' ) –

    Name of response header which is filled up with application version number

Use X-Application-Version header on client

If client got X-Application-Version header from backend, it is compared with client version.

If versions do not match, a warning is shown:

>>> client.ping()
UserWarning: Horizon client version '0.0.9' does not match backend version '1.0.0'. Please upgrade.