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

Automatically log correlation IDs when Micrometer tracing is being used #33280

Closed
Tracked by #35776
mhalbritter opened this issue Nov 21, 2022 · 3 comments
Closed
Tracked by #35776
Assignees
Labels
theme: observability Issues related to observability type: enhancement A general enhancement
Milestone

Comments

@mhalbritter
Copy link
Contributor

Right now, as documented users have to set this in their config to get span id and trace ids in logs:

logging.pattern.level=%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]

Besides that it abuses the logging level pattern, it is not a good developer experience.

I would prefer it to be auto-configured in the case a Tracer bean is available. Not sure if this is technically feasible.

We should additionally introduce a logging.pattern.correlation property which can be used.

@mhalbritter mhalbritter added type: enhancement A general enhancement theme: observability Issues related to observability labels Nov 21, 2022
@mhalbritter mhalbritter added this to the 3.1.x milestone Nov 21, 2022
@wilkinsona wilkinsona changed the title Improve span and trace id display in logs Make is easier to add span and trace id to logs Nov 21, 2022
@mentallurg
Copy link

@mhalbritter : I agree that the current for using trace ID and span ID in the logging format is bad and should be improved.
But I don't agree that it should be added to the format automatically. It may help in some cases, but it can make logs worse readable in many other cases.
Besides, new features should not break the current behaviour whenever possible.

@welsh
Copy link

welsh commented Dec 5, 2022

@mentallurg previous behaviour that I experienced was that adding:

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
        </dependency>

Did add it automatically to the default logging, so it was a surprise that I needed to manually add it back in when migrating to Spring Boot 3.

@jonatan-ivanov jonatan-ivanov changed the title Make is easier to add span and trace id to logs Make it easier to add span and trace id to logs Mar 1, 2023
@philwebb philwebb modified the milestones: 3.1.x, 2.7.x, 3.2.x May 16, 2023
@philwebb
Copy link
Member

A few of us discussed this issue again today and we'd like to default to the following format if tracing is enabled:

When a correlation ID is present we'll use traceId dash spanId as recommended by w3c:

2023-05-22T08:53:19.665-07:00 DEBUG 7704 --- [nio-8080-exec-5] [646b8fef796a9e022e983eb44cb82a2f-fe26c1e3afcf59c5] o.s.web.servlet.DispatcherServlet        : Completed 200 OK

If the correlation is missing, we'll pad with spaces:

2023-05-22T08:53:19.665-07:00 DEBUG 7704 --- [nio-8080-exec-5] [                                                 ] o.s.web.servlet.DispatcherServlet        : Completed 200 OK```

If one part of the correlation ID is missing, we'll pad with spaces and include the dash. This is considered a bug and we want the logs to look strange:

2023-05-22T08:53:19.665-07:00 DEBUG 7704 --- [nio-8080-exec-5] [646b8fef796a9e022e983eb44cb82a2f-                ] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
2023-05-22T08:53:19.665-07:00 DEBUG 7704 --- [nio-8080-exec-5] [                                -fe26c1e3afcf59c5] o.s.web.servlet.DispatcherServlet        : Completed 200 OK

We think showing the application name in the logs is a useful feature outside of correlation IDs. We'll open a new issue to support it and enable it by default when correlation IDs are shown.

We also discussed that it's important that slueth style correlation IDs can be used if the user wishes to do so.

@philwebb philwebb mentioned this issue Jun 7, 2023
31 tasks
@philwebb philwebb changed the title Make it easier to add span and trace id to logs Automatically log correlation IDs when Micrometer tracing is being used Jun 22, 2023
@philwebb philwebb modified the milestones: 3.2.x, 3.2.0-M1 Jun 22, 2023
jonatan-ivanov added a commit that referenced this issue Jun 22, 2023
Docs related to gh-33280 (log correlation) and
gh-35593 (application name in each log line) need some polishing:
- Fix project names
- Show how to avoid having the application name duplicated in logs
- Call out that a trailing space is needed in the correlation pattern

Closes gh-36035
See gh-33280
See gh-35593
izeye added a commit to izeye/spring-boot that referenced this issue Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: observability Issues related to observability type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants