Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Debug ID in MDC #207

Closed
wants to merge 3 commits into from
Closed

Conversation

mabn
Copy link
Contributor

@mabn mabn commented Oct 19, 2017

An example of keeping Span's debug_id inside MDC - for version 0.31.0+

Puts active Spans's debug_id when scope is activated and cleans it
afterwards.

see also: #206

Puts active Spans's debug_id when scope is activated and cleans it
afterwards.
@mabn mabn mentioned this pull request Oct 19, 2017
@coveralls
Copy link

Coverage Status

Coverage remained the same at 78.598% when pulling 8230a90 on futuresimple:debug_id_in_mdc into cdc9601 on opentracing:v0.31.0.

private static class MockSpanDebugId implements SimpleMdcScopeManager.DebugIdProvider {
@Override
public String get(Span span) {
MockSpan.MockContext ctx = ((MockSpan) span).context();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Real implementation will also require casting so other libs that wrap Span will make it fail :|

@coveralls
Copy link

Coverage Status

Coverage remained the same at 78.598% when pulling 8230a90 on futuresimple:debug_id_in_mdc into cdc9601 on opentracing:v0.31.0.

@Override
public Scope activate(Span span, boolean finishSpanOnClose) {
Scope scope = wrapped.activate(span, finishSpanOnClose);
String debugId = MDC.get(mdcKey);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call it something other than debugId so you don't have to use this.debugId for the instance field? (same name but different types, etc)

@carlosalberto
Copy link
Collaborator

Out of curiosity: is this something you would foresee being implemented as a wrapper class? I ask because if the user does scopeManager.active().close(), the logic you used for MDC will not be called, i.e.

            } finally {
                 MDC.put(mdcKey, previousDebugId);
            }

@mabn
Copy link
Contributor Author

mabn commented Oct 23, 2017

Oh, you're right. I should pass my MdcScope when calling wrapped.activate(..)

If this wouldn't be a wrapper then it wouldn't be possible to use it with another scope manager (e.g. AutoFinishScopeManager). Until there is an API to register observers/listeners/extensions then wrapping is the only way :|

@sudr
Copy link

sudr commented Apr 26, 2018

Wondering when this feature will become available.

@whiskeysierra
Copy link

@yurishkuro
Copy link
Member

I haven't tried api-extensions, but subclassed the scope manager to add trace IDs to logs.

https://github.com/PacktPublishing/Mastering-Distributed-Tracing/blob/master/Chapter11/exercise1/lib/src/main/java/lib/MDCScopeManager.java

@whiskeysierra
Copy link

As long as 0.32.0 is not released there is no way to get this done without being implementation-specific, right?

https://github.com/PacktPublishing/Mastering-Distributed-Tracing/blob/master/Chapter11/exercise1/lib/src/main/java/lib/MDCScopeManager.java#L29

@yurishkuro
Copy link
Member

@whiskeysierra yeah. Even with 0.32, the traceSampled field cannot be logged generically.

@mabn
Copy link
Contributor Author

mabn commented Jun 24, 2019

@whiskeysierra yes, java-api-extensions would be suitable, but IIRC at the time they didn't have some of the callbacks I needed

I'm closing this PR as I haven't worked on this for quite a while.

@mabn mabn closed this Jun 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants