Skip to content

Conversation

@tjquinno
Copy link
Member

@tjquinno tjquinno commented May 21, 2025

Description

Resolves #5741

Release note


If you use tracing, Helidon now automatically provides a logging MDC (mapped diagnostic context) key trace_id which 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 a String. (Previously only String values 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 all MdcProvider instances. The providers would use their own context storage or context storage provided by the underlying logging implementation to store key/value pairs.

Now, HelidonMdc keeps its own Map<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#get delegates 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 TracerProviderHelper class has always been initialized with whatever specific tracing provider library the user adds to her project. This init code now registers the trace_id MDC 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_id functionality.

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_id supported added by this PR.

@tjquinno tjquinno self-assigned this May 21, 2025
@tjquinno tjquinno requested a review from Verdent May 21, 2025 22:21
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label May 21, 2025
@tjquinno tjquinno force-pushed the 4.x-mdc-trace-id branch from 49b3ce5 to 159e1e6 Compare May 23, 2025 16:31
@tjquinno tjquinno requested a review from tomas-langer May 23, 2025 18:06
@tjquinno tjquinno requested a review from tomas-langer May 27, 2025 11:59
@tjquinno tjquinno merged commit 3e52305 into helidon-io:main May 27, 2025
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logging and tracing correlation

2 participants