Skip to content

Commit c0d0f8f

Browse files
committed
Add info for traceid
1 parent fd31181 commit c0d0f8f

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

docs/src/main/asciidoc/se/guides/logging.adoc

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ For more information see link:{helidon-github-examples-url}/logging/slf4j[Helido
149149
150150
== Mapped Diagnostic Context (MDC) support
151151
152-
The Mapped Diagnostic Context provides a mechanism for application code to store
153-
values in a context that are then included in log output. These values could
152+
The Mapped Diagnostic Context provides a mechanism for Helidon and application code to store
153+
values in a context that can then be included in log output. These values could
154154
be a tracing ID, the current user, or a similar contextual value, and they are
155155
propagated by Helidon across threads.
156156
@@ -161,21 +161,26 @@ but also works with the other supported frameworks (slf4j or log4j).
161161
162162
To use Helidon MDC, you need to do three things:
163163
164-
1. Add a dependencies on one of the supported logging frameworks. See previous sections.
164+
1. Add a dependency on one of the supported logging frameworks. See previous sections.
165165
2. Store values in the MDC in your code.
166166
3. Configure logging to display the values in its output.
167167
168+
=== MDC values provided by Helidon
169+
If you include tracing in your project, Helidon automatically provides the MDC key `trace_id`. Logging inserts the trace ID of the current span (if there is one) or the string "none" if no span is active.
170+
168171
=== Storing values in MDC
169172
170-
To set values in the MDC you can use `io.helidon.logging.common.HelidonMdc` class:
173+
To set your own values in the MDC you can use `io.helidon.logging.common.HelidonMdc` class:
171174
172-
[source]
175+
[source,java]
173176
----
174-
HelidonMdc.set("name", "Joe");
177+
HelidonMdc.set("name", "Joe"); // <1>
178+
HelidonMdc.set("otherName", () -> retrieveStringValue()); // <2>
175179
----
180+
<1> Stores an attribute named "name" with the fixed value "Joe" in the MDC.
181+
<2> Stores an attribute named "otherName" with the given `Supplier<String>`.
176182
177-
This will store an attribute named "name" with the value "Joe" in the MDC so that it can be
178-
extracted later in log output.
183+
The `set(<String, String>`) method associates the name with a fixed value. The `set(<String>, <Supplier<String>>) form associates the name with a lambda or method reference. This second form might be useful if your code (or Helidon) maintains the value you want to log in some context that your code can access and if that value changes as the server runs. In both cases, when your logging format refers to the name logging extracts the corresponding fixed value or invoked the supplier to obtain the value, using the result in log output.
179184
180185
`HelidonMdc` works with the supported logging frameworks. But if you prefer, you can
181186
use a logging framework specific API. Such as `org.slf4j.MDC` or `org.apache.logging.log4j.ThreadContext` instead.
@@ -231,4 +236,4 @@ for MDC is you can use the token `%X{name}` to reference MDC values in the log o
231236
232237
* link:{helidon-github-examples-url}/logging[Helidon logging examples]
233238
* link:{https://medium.com/helidon/helidon-logging-and-mdc-5de272cf085d}[Helidon, Logging, and MDC Blog]
234-
* link:{javadoc-base-url}/io.helidon.logging.common/io/helidon/logging/common/HelidonMdc.html[HelidonMdc Javadoc]
239+
* link:{javadoc-base-url}/io.helidon.logging.common/io/helidon/logging/common/HelidonMdc.html[HelidonMdc Javadoc]

0 commit comments

Comments
 (0)