Skip to content
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

Support custom MDC key with otel.bridge.Slf4JEventListener #158

Closed
ShenFeng312 opened this issue Feb 8, 2023 · 2 comments · Fixed by #160
Closed

Support custom MDC key with otel.bridge.Slf4JEventListener #158

ShenFeng312 opened this issue Feb 8, 2023 · 2 comments · Fixed by #160
Labels
enhancement New feature or request
Milestone

Comments

@ShenFeng312
Copy link
Contributor

ShenFeng312 commented Feb 8, 2023

like this

        private static final String DEFAULT_TRACE_ID_KEY = "traceId";

	private static final String DEFAULT_SPAN_ID_KEY = "spanId";

	private final String traceIdKey;

	private final String spanIdKey;

	public Slf4JEventListener()
	{
		this(DEFAULT_TRACE_ID_KEY,DEFAULT_SPAN_ID_KEY);
	}
	public Slf4JEventListener(String traceIdKey, String spanIdKey)
	{
		this.traceIdKey = traceIdKey;
		this.spanIdKey = spanIdKey;
	}

	private void onScopeAttached(EventPublishingContextWrapper.ScopeAttachedEvent event)
	{
		log.trace("Got scope changed event [{}]", event);
		Span span = event.getSpan();
		if (span != null) {
			MDC.put(traceIdKey, span.getSpanContext().getTraceId());
			MDC.put(spanIdKey, span.getSpanContext().getSpanId());
		}
	}
@marcingrzejszczak
Copy link
Contributor

Makes sense! Are you willing to file a pr?

@ShenFeng312
Copy link
Contributor Author

Makes sense! Are you willing to file a pr?

yes

@jonatan-ivanov jonatan-ivanov added the enhancement New feature or request label Feb 8, 2023
@jonatan-ivanov jonatan-ivanov added this to the 1.1.x milestone Feb 8, 2023
@jonatan-ivanov jonatan-ivanov linked a pull request Feb 9, 2023 that will close this issue
@jonatan-ivanov jonatan-ivanov modified the milestones: 1.1.x, 1.1.0-M1 Feb 9, 2023
@shakuzen shakuzen changed the title io.micrometer.tracing.otel.bridge.Slf4JEventListener support custom key Support custom MDC key with otel.bridge.Slf4JEventListener Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants