From 228b8eb8e4285cb79549e27842cf705acb6c69e9 Mon Sep 17 00:00:00 2001 From: Jonatan Ivanov Date: Thu, 22 Jun 2023 14:43:55 -0700 Subject: [PATCH] Polish log correlation docs 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 --- .../src/docs/asciidoc/actuator/tracing.adoc | 14 +++++++++----- .../spring-boot-smoke-test-actuator/build.gradle | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/tracing.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/tracing.adoc index 0b9378d1acd..53ab1290e23 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/tracing.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/tracing.adoc @@ -69,22 +69,26 @@ Press the "Show" button to see the details of that trace. [[actuator.micrometer-tracing.logging]] === Logging Correlation IDs -Correlation IDs provide a helpful way to link lines in your log files to distributed traces. -By default, as long as configprop:management.tracing.enabled[] has not been set to `false`, Spring Boot will include correlation IDs in your logs whenever you are using Micrometer tracing. +Correlation IDs provide a helpful way to link lines in your log files to spans/traces. +By default, as long as configprop:management.tracing.enabled[] has not been set to `false`, Spring Boot will include correlation IDs in your logs whenever you are using Micrometer Tracing. The default correlation ID is built from `traceId` and `spanId` https://logback.qos.ch/manual/mdc.html[MDC] values. -For example, if Micrometer tracing has added an MDC `traceId` of `803B448A0489F84084905D3093480352` and an MDC `spanId` of `3425F23BB2432450` the log output will include the correlation ID `[803B448A0489F84084905D3093480352-3425F23BB2432450]`. +For example, if Micrometer Tracing has added an MDC `traceId` of `803B448A0489F84084905D3093480352` and an MDC `spanId` of `3425F23BB2432450` the log output will include the correlation ID `[803B448A0489F84084905D3093480352-3425F23BB2432450]`. If you prefer to use a different format for your correlation ID, you can use the configprop:logging.pattern.correlation[] property to define one. -For example, the following will provide a correlation ID for Logback in format previously used by Spring Sleuth: +For example, the following will provide a correlation ID for Logback in format previously used by Spring Cloud Sleuth: [source,yaml,indent=0,subs="verbatim",configprops,configblocks] ---- logging: pattern: - correlation: "[${spring.application.name:},%X{traceId:-},%X{spanId:-}]" + correlation: "[${spring.application.name:},%X{traceId:-},%X{spanId:-}] " + include-application-name: false ---- +NOTE: In the example above, configprop:logging.include-application-name[] is set to `false` to avoid the application name being duplicated in the log messages (configprop:logging.pattern.correlation[] already contains it). +It's also worth mentioning that configprop:logging.pattern.correlation[] contains a trailing space so that it is separated from the logger name that comes right after it by default. + [[actuator.micrometer-tracing.tracer-implementations]] diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/build.gradle index b616d3a9697..656ad05a752 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/build.gradle @@ -11,6 +11,7 @@ dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-security")) implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-validation")) + implementation 'io.micrometer:micrometer-tracing-bridge-brave' runtimeOnly("com.h2database:h2")