Skip to content

structlog integration - TypeError when passing object #41

Closed
@scibi

Description

@scibi

Right now when you add an object to your log like this:

            logger.info(
                "request_started",
                request=request,
                user_agent=request.META.get("HTTP_USER_AGENT"),
            )

You end up with TypeError like this: <WSGIRequest: GET '/healthcheck/'> is not JSON serializable in json_dumps (ecs_logging/_utils.py):

        if value:
            return "{%s,%s" % (
                ordered_json,
                json.dumps(value, sort_keys=True, separators=(",", ":"))[1:],
            )

You should use a default argument for json.dumps and provide fallback mechanism to handle this situation. See https://www.structlog.org/en/stable/_modules/structlog/processors.html#JSONRenderer and _json_fallback_handler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions