Skip to content

Commit b165d41

Browse files
committed
diff
1 parent 1dae678 commit b165d41

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

instrumentation/logback/logback-appender-1.0/library/src/test/java/io/opentelemetry/instrumentation/logback/appender/v1_0/AbstractOpenTelemetryAppenderTest.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,28 @@ static void setupAll() {
3636
resource = Resource.getDefault();
3737
instrumentationScopeInfo = InstrumentationScopeInfo.create("TestLogger");
3838
// by default LoggerContext contains HOSTNAME property we clear it to start with empty context
39-
AbstractOpenTelemetryAppenderTest.resetLoggerContext();
39+
resetLoggerContext();
40+
}
41+
42+
static void resetLoggerContext() {
43+
try {
44+
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
45+
Field field = ContextBase.class.getDeclaredField("propertyMap");
46+
field.setAccessible(true);
47+
Map<?, ?> map = (Map<?, ?>) field.get(loggerContext);
48+
map.clear();
49+
50+
Method method;
51+
try {
52+
method = LoggerContext.class.getDeclaredMethod("syncRemoteView");
53+
} catch (NoSuchMethodException noSuchMethodException) {
54+
method = LoggerContext.class.getDeclaredMethod("updateLoggerContextVO");
55+
}
56+
method.setAccessible(true);
57+
method.invoke(loggerContext);
58+
} catch (Exception exception) {
59+
throw new IllegalStateException("Failed to reset logger context", exception);
60+
}
4061
}
4162

4263
protected abstract InstrumentationExtension getTesting();
@@ -49,7 +70,7 @@ void logLoggerContext() {
4970
logger.info("log message 1");
5071
executeAfterLogsExecution();
5172
} finally {
52-
AbstractOpenTelemetryAppenderTest.resetLoggerContext();
73+
resetLoggerContext();
5374
}
5475

5576
getTesting()
@@ -63,25 +84,4 @@ void logLoggerContext() {
6384
.hasAttributesSatisfying(
6485
equalTo(AttributeKey.stringKey("test-property"), "test-value")));
6586
}
66-
67-
static void resetLoggerContext() {
68-
try {
69-
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
70-
Field field = ContextBase.class.getDeclaredField("propertyMap");
71-
field.setAccessible(true);
72-
Map<?, ?> map = (Map<?, ?>) field.get(loggerContext);
73-
map.clear();
74-
75-
Method method;
76-
try {
77-
method = LoggerContext.class.getDeclaredMethod("syncRemoteView");
78-
} catch (NoSuchMethodException noSuchMethodException) {
79-
method = LoggerContext.class.getDeclaredMethod("updateLoggerContextVO");
80-
}
81-
method.setAccessible(true);
82-
method.invoke(loggerContext);
83-
} catch (Exception exception) {
84-
throw new IllegalStateException("Failed to reset logger context", exception);
85-
}
86-
}
8787
}

0 commit comments

Comments
 (0)