-
Notifications
You must be signed in to change notification settings - Fork 584
Enhance MDC to allow mapping a key to a supplier of string; enhance tracing to add trace_id
#10143
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tomas-langer
requested changes
May 23, 2025
logging/common/src/main/java/io/helidon/logging/common/BaseMdcProvider.java
Outdated
Show resolved
Hide resolved
logging/common/src/main/java/io/helidon/logging/common/BaseMdcProvider.java
Outdated
Show resolved
Hide resolved
logging/common/src/main/java/io/helidon/logging/common/BaseMdcProvider.java
Outdated
Show resolved
Hide resolved
logging/common/src/main/java/io/helidon/logging/common/BaseMdcProvider.java
Outdated
Show resolved
Hide resolved
logging/common/src/main/java/io/helidon/logging/common/BaseMdcProvider.java
Outdated
Show resolved
Hide resolved
logging/common/src/main/java/io/helidon/logging/common/BaseMdcProvider.java
Outdated
Show resolved
Hide resolved
logging/common/src/main/java/io/helidon/logging/common/BaseMdcProvider.java
Outdated
Show resolved
Hide resolved
logging/common/src/main/java/io/helidon/logging/common/HelidonMdc.java
Outdated
Show resolved
Hide resolved
49b3ce5 to
159e1e6
Compare
tracing/provider-tests/src/main/java/io/helidon/tracing/providers/tests/TestMdc.java
Outdated
Show resolved
Hide resolved
tomas-langer
approved these changes
May 27, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Resolves #5741
Release note
If you use tracing, Helidon now automatically provides a logging MDC (mapped diagnostic context) key
trace_idwhich you can use in logging messages to display the trace ID of the current span if there is one.Also, Helidon's MDC provider implementation now permits MDC keys to be added with a
Supplier<String>value or aString. (Previously onlyStringvalues could be added.)PR Overview
(simplified since the original PR)
Two parts:
Changes in logging
Previously,
HelidonMdc(the main entry point for Helidon and user code to manage MDC) would simply delegate each method to the corresponding method on allMdcProviderinstances. The providers would use their own context storage or context storage provided by the underlying logging implementation to store key/value pairs.Now,
HelidonMdckeeps its ownMap<String, Supplier<String>>and first tries to resolve a look-up using that. If that map does not contain a supplier for a key,HelidonMdc#getdelegates to the available MDC providers as it used to.The PR also includes changes to tests for the new supplier feature.
Changes in tracing
The Helidon
TracerProviderHelperclass has always been initialized with whatever specific tracing provider library the user adds to her project. This init code now registers thetrace_idMDC key with a supplier that gets the current span (if there is one) and returns the trace ID from it.This code uses the Helidon neutral tracing API to get the current span and, from it, the span context (which contains the trace ID. But this works because the Helidon neutral code to get the current span delegates to the underlying implementation (OpenTelemetry, Zipkin, etc.) so the
Supplier<String>will always retrieve the current span, even if user code has set the current span using the underlying library's API, not the Helidon one.The PR also adds a test to the provider tests that all providers run. It tests the MDC
trace_idfunctionality.Documentation
Depending on timing, PR #10137 could include a note about this or the new logging page that PR creates could be separately updated to describe the new
tracer_idsupported added by this PR.