Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature parity for structlog #73

Open
as42sl opened this issue Dec 1, 2021 · 5 comments
Open

Feature parity for structlog #73

as42sl opened this issue Dec 1, 2021 · 5 comments
Labels

Comments

@as42sl
Copy link

as42sl commented Dec 1, 2021

The structlog logger only sets the log level, timestamp and log message while the stdlib logger is setting a lot of more stuff like exceptions, stack infos, thread/process infos. It would be great to have a feature parity here.

@basepi basepi added enhancement New feature or request and removed triage labels Dec 1, 2021
@basepi
Copy link
Contributor

basepi commented Dec 1, 2021

Thanks for the request! structlog is awesome and we should definitely make sure our support there is every bit as good as the stdlib version.

@HenrikOssipoff
Copy link

Just came by here. Maybe I'm mistaken, but it also appears that the structlog processor doesn't add correlation data from Elastic APM, even though the docs sounds like this is automatic for both stdlib logger and structlog: https://www.elastic.co/guide/en/ecs-logging/python/current/installation.html#correlation

@basepi
Copy link
Contributor

basepi commented Aug 4, 2022

@HenrikOssipoff the structlog processor just takes the whole event dict. So if you're using the structlog handler then it should have all that data.

@jasperjonker
Copy link

I had some issues using structlog and ecs_logging together with their processors. Apparently the order of the structlog.configure(processors=[...]) list matters. The ecs_logging.StructlogFormatter() needs to be last in the list.

Example:

structlog.configure(
    processors=[
        structlog.contextvars.merge_contextvars,
        structlog.processors.CallsiteParameterAdder(
            {
                structlog.processors.CallsiteParameter.FILENAME,
                structlog.processors.CallsiteParameter.FUNC_NAME,
                structlog.processors.CallsiteParameter.LINENO,
            }
        ),
        ecs_logging.StructlogFormatter(),
    ],
    wrapper_class=structlog.stdlib.BoundLogger,
    logger_factory=structlog.PrintLoggerFactory(),
    cache_logger_on_first_use=True,
)

@basepi
Copy link
Contributor

basepi commented Oct 5, 2022

@jasperjonker correct -- typically you wouldn't want a processor that both enriches and converts to JSON -- you would want those to be separate processors. But in this case we have a custom json_dumps() function which enforces some ordered fields in the resulting json string to match the ECS spec. Apologies for the lack of clarity! I have clarified in #83

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants