|
18 | 18 | import io.opentelemetry.sdk.common.InstrumentationScopeInfo; |
19 | 19 | import io.opentelemetry.sdk.logs.data.LogRecordData; |
20 | 20 | import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes; |
| 21 | +import io.opentelemetry.testing.internal.armeria.common.annotation.Nullable; |
21 | 22 | import java.util.logging.Level; |
22 | 23 | import java.util.logging.Logger; |
23 | 24 | import java.util.stream.Stream; |
|
27 | 28 | import org.junit.jupiter.params.provider.MethodSource; |
28 | 29 |
|
29 | 30 | class JavaUtilLoggingTest { |
| 31 | + private static final boolean isExperimentalAttributesEnabled = |
| 32 | + Boolean.getBoolean("otel.instrumentation.java-util-logging.experimental-log-attributes"); |
30 | 33 |
|
31 | 34 | private static final Logger logger = Logger.getLogger("abc"); |
32 | 35 |
|
@@ -117,17 +120,25 @@ private static void test( |
117 | 120 | if (logException) { |
118 | 121 | assertThat(log) |
119 | 122 | .hasAttributesSatisfyingExactly( |
120 | | - equalTo(ThreadIncubatingAttributes.THREAD_NAME, Thread.currentThread().getName()), |
121 | | - equalTo(ThreadIncubatingAttributes.THREAD_ID, Thread.currentThread().getId()), |
| 123 | + equalTo( |
| 124 | + ThreadIncubatingAttributes.THREAD_NAME, |
| 125 | + experimental(Thread.currentThread().getName())), |
| 126 | + equalTo( |
| 127 | + ThreadIncubatingAttributes.THREAD_ID, |
| 128 | + experimental(Thread.currentThread().getId())), |
122 | 129 | equalTo(EXCEPTION_TYPE, IllegalStateException.class.getName()), |
123 | 130 | equalTo(EXCEPTION_MESSAGE, "hello"), |
124 | 131 | satisfies( |
125 | 132 | EXCEPTION_STACKTRACE, v -> v.contains(JavaUtilLoggingTest.class.getName()))); |
126 | 133 | } else { |
127 | 134 | assertThat(log) |
128 | 135 | .hasAttributesSatisfyingExactly( |
129 | | - equalTo(ThreadIncubatingAttributes.THREAD_NAME, Thread.currentThread().getName()), |
130 | | - equalTo(ThreadIncubatingAttributes.THREAD_ID, Thread.currentThread().getId())); |
| 136 | + equalTo( |
| 137 | + ThreadIncubatingAttributes.THREAD_NAME, |
| 138 | + experimental(Thread.currentThread().getName())), |
| 139 | + equalTo( |
| 140 | + ThreadIncubatingAttributes.THREAD_ID, |
| 141 | + experimental(Thread.currentThread().getId()))); |
131 | 142 | } |
132 | 143 |
|
133 | 144 | if (withParent) { |
@@ -164,4 +175,20 @@ private static void performLogging( |
164 | 175 | interface LoggerMethod { |
165 | 176 | void call(Logger logger, String msg); |
166 | 177 | } |
| 178 | + |
| 179 | + @Nullable |
| 180 | + public static String experimental(String value) { |
| 181 | + if (isExperimentalAttributesEnabled) { |
| 182 | + return value; |
| 183 | + } |
| 184 | + return null; |
| 185 | + } |
| 186 | + |
| 187 | + @Nullable |
| 188 | + public static Long experimental(long value) { |
| 189 | + if (isExperimentalAttributesEnabled) { |
| 190 | + return value; |
| 191 | + } |
| 192 | + return null; |
| 193 | + } |
167 | 194 | } |
0 commit comments