|
11 | 11 | import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_MESSAGE; |
12 | 12 | import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_STACKTRACE; |
13 | 13 | import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_TYPE; |
14 | | -import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_FILEPATH; |
15 | | -import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_FUNCTION; |
16 | | -import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_LINENO; |
17 | | -import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_NAMESPACE; |
18 | 14 | import static io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes.THREAD_ID; |
19 | 15 | import static io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes.THREAD_NAME; |
20 | 16 | import static java.util.concurrent.TimeUnit.MILLISECONDS; |
|
24 | 20 | import io.opentelemetry.api.trace.SpanContext; |
25 | 21 | import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; |
26 | 22 | import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; |
| 23 | +import io.opentelemetry.instrumentation.testing.junit.code.SemconvCodeStabilityUtil; |
27 | 24 | import io.opentelemetry.sdk.common.InstrumentationScopeInfo; |
28 | 25 | import io.opentelemetry.sdk.logs.data.LogRecordData; |
29 | 26 | import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; |
|
37 | 34 | import org.apache.log4j.Logger; |
38 | 35 | import org.apache.log4j.MDC; |
39 | 36 | import org.apache.log4j.helpers.Loader; |
40 | | -import org.assertj.core.api.AbstractLongAssert; |
41 | 37 | import org.assertj.core.api.AssertAccess; |
42 | 38 | import org.junit.jupiter.api.Test; |
43 | 39 | import org.junit.jupiter.api.extension.RegisterExtension; |
@@ -78,20 +74,21 @@ private static Stream<Arguments> provideParameters() { |
78 | 74 | @Test |
79 | 75 | public void testCodeAttributes() { |
80 | 76 | logger.info("this is test message"); |
| 77 | + List<AttributeAssertion> assertions = |
| 78 | + SemconvCodeStabilityUtil.codeFileAndLineAssertions("Log4j1Test.java"); |
| 79 | + assertions.addAll( |
| 80 | + SemconvCodeStabilityUtil.codeFunctionAssertions(Log4j1Test.class, "testCodeAttributes")); |
| 81 | + assertions.add(equalTo(THREAD_NAME, Thread.currentThread().getName())); |
| 82 | + assertions.add(equalTo(THREAD_ID, Thread.currentThread().getId())); |
| 83 | + |
81 | 84 | testing.waitAndAssertLogRecords( |
82 | 85 | logRecord -> |
83 | 86 | logRecord |
84 | 87 | .hasBody("this is test message") |
85 | 88 | .hasInstrumentationScope(InstrumentationScopeInfo.builder("abc").build()) |
86 | 89 | .hasSeverity(Severity.INFO) |
87 | 90 | .hasSeverityText("INFO") |
88 | | - .hasAttributesSatisfyingExactly( |
89 | | - equalTo(THREAD_NAME, Thread.currentThread().getName()), |
90 | | - equalTo(THREAD_ID, Thread.currentThread().getId()), |
91 | | - equalTo(CODE_NAMESPACE, Log4j1Test.class.getName()), |
92 | | - equalTo(CODE_FUNCTION, "testCodeAttributes"), |
93 | | - satisfies(CODE_LINENO, AbstractLongAssert::isPositive), |
94 | | - equalTo(CODE_FILEPATH, "Log4j1Test.java"))); |
| 91 | + .hasAttributesSatisfyingExactly(assertions)); |
95 | 92 | } |
96 | 93 |
|
97 | 94 | @ParameterizedTest |
|
0 commit comments