|
10 | 10 | import static io.opentelemetry.instrumentation.api.log.LoggingContextConstants.TRACE_ID; |
11 | 11 |
|
12 | 12 | import ch.qos.logback.classic.spi.ILoggingEvent; |
| 13 | +import ch.qos.logback.classic.spi.LoggerContextVO; |
13 | 14 | import ch.qos.logback.core.Appender; |
14 | 15 | import ch.qos.logback.core.UnsynchronizedAppenderBase; |
15 | 16 | import ch.qos.logback.core.spi.AppenderAttachable; |
16 | 17 | import ch.qos.logback.core.spi.AppenderAttachableImpl; |
17 | 18 | import io.opentelemetry.api.trace.Span; |
18 | 19 | import io.opentelemetry.api.trace.SpanContext; |
19 | 20 | import io.opentelemetry.instrumentation.logback.mdc.v1_0.internal.UnionMap; |
| 21 | +import java.lang.reflect.Proxy; |
20 | 22 | import java.util.HashMap; |
21 | 23 | import java.util.Iterator; |
22 | 24 | import java.util.Map; |
@@ -49,8 +51,25 @@ public static ILoggingEvent wrapEvent(ILoggingEvent event) { |
49 | 51 | } else { |
50 | 52 | eventContext = new UnionMap<>(eventContext, contextData); |
51 | 53 | } |
52 | | - |
53 | | - return new LoggingEventWrapper(event, eventContext); |
| 54 | + Map<String, String> eventContextMap = eventContext; |
| 55 | + LoggerContextVO oldVo = event.getLoggerContextVO(); |
| 56 | + LoggerContextVO vo = |
| 57 | + oldVo != null |
| 58 | + ? new LoggerContextVO(oldVo.getName(), eventContextMap, oldVo.getBirthTime()) |
| 59 | + : null; |
| 60 | + |
| 61 | + return (ILoggingEvent) |
| 62 | + Proxy.newProxyInstance( |
| 63 | + ILoggingEvent.class.getClassLoader(), |
| 64 | + new Class<?>[] {ILoggingEvent.class}, |
| 65 | + (proxy, method, args) -> { |
| 66 | + if ("getMDCPropertyMap".equals(method.getName())) { |
| 67 | + return eventContextMap; |
| 68 | + } else if ("getLoggerContextVO".equals(method.getName())) { |
| 69 | + return vo; |
| 70 | + } |
| 71 | + return method.invoke(event, args); |
| 72 | + }); |
54 | 73 | } |
55 | 74 |
|
56 | 75 | @Override |
|
0 commit comments