Repository navigation
HDDS-13679. Add trace and span IDs to log MDC via OpenTelemetry ContextStorageProvider - #11607
Conversation
|
@sravani-revuri , @sumitagrawl can you review this pull-request . |
chihsuan
left a comment
There was a problem hiding this comment.
Thanks for working on this! @rajeshkumarchandolu I found a few cases around the global provider that may need attention. Please see inline comments for details.
…ent applications Co-Authored-By: Claude Code <noreply@anthropic.com>
chihsuan
left a comment
There was a problem hiding this comment.
Thanks @rajeshkumarchandolu! The addWrapper switch and the clearer scope in the description look great. Just two small notes inline.
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
…to the datanode entry point Co-Authored-By: Claude <noreply@anthropic.com>
chihsuan
left a comment
There was a problem hiding this comment.
Thanks for addressing the feedback! @rajeshkumarchandolu LGTM otherwise.
I just noticed each tracing-enabled test in TestMdcContextStorageInstall takes 7-8 seconds, which may slow down CI. Could we fix it before merging?
…lector is running
chihsuan
left a comment
There was a problem hiding this comment.
Thanks @rajeshkumarchandolu LGTM!
|
It seems |
|
@sumitagrawal @chihsuan All review comments have been resolved. Could you take another look and merge if there are no further changes needed? |
|
Merged. Thanks @rajeshkumarchandolu for the patch! Thanks @sumitagrawl for the review! |
What changes were proposed in this pull request?
Ozone services export OpenTelemetry spans, but their log lines don't include the trace context, so it is hard to go from a trace in Jaeger to the matching logs, or the other way round. This change keeps the current span's
trace_idandspan_idin the slf4j MDC, so a log pattern can print them with%X{trace_id}and%X{span_id}.Approach: every
makeCurrent()/Context.wrap(...)in OpenTelemetry goes throughContextStorage.attach().TracingUtil.MdcContextStoragewraps the default storage and updates the MDC from the current span on attach and on scope close. It is added withContextStorage.addWrapperbyTracingUtil.installMdcContextStorage(), which is called only from Ozone startup paths:TracingReconfigurationCallback.initGateway.callozone sh,ozone fs, Freon,ozone ratis):TracingUtil.executeDetails:
RpcClient) never installs it, so applications using the Ozone client keep their own MDC and context storage. NoContextStorageProvideris registered throughMETA-INF/services, so it can't conflict with a provider the application ships.InheritableThreadLocalMDC copies into child threads.Contextis first used in the JVM. If the context is already initialized, it logs a single WARN and the IDs are not added.log4j.propertiespatterns are unchanged. To print the IDs, add e.g.[trace=%X{trace_id} span=%X{span_id}]to the pattern.Scope: this covers log lines written inside an active span, i.e. the synchronous request paths that show up in Jaeger for each command. Asynchronous tasks don't carry the trace context yet. For example, SCM
EventQueue-*threads created during a datanodeRegisterRPC inherit that span's IDs through the MDC and keep them. This will be handled in a follow-up that propagates the trace context to SCMEventQueuehandlers.What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-13679
How was this patch tested?
TestTracingUtil):trace_idin the MDC is left unchanged.checkstyle.sh.ozone+monitoring.yaml) with tracing enabled and Jaeger. The log pattern was changed locally to[trace=%X{trace_id} span=%X{span_id}]; that change is not part of this PR. NoOpenTelemetry context is already initializedwarning appeared in the OM, SCM, S3 Gateway or datanode logs.Verification in local docker compose
Tested with an
ozone sh key put. The SCM and datanode log lines for the request carry the same trace_id, and each span_id matches the span in Jaeger (SCMAllocateScmBlock, datanodeWriteChunk):Tested S3 Gateway with
aws s3apicreate-bucket, put-object and get-object. Each request's S3G log lines carry its own trace_id, matching the request's trace in Jaeger (BucketEndpoint.put,ObjectEndpoint.put,ObjectEndpoint.get):Build:
https://github.com/rajeshkumarchandolu/ozone/actions/runs/40675421635