|
9 | 9 | import static io.opentelemetry.instrumentation.api.internal.SemconvExceptionSignal.emitExceptionAsSpanEvents; |
10 | 10 | import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; |
11 | 11 | import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; |
12 | | -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; |
13 | | -import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_MESSAGE; |
14 | | -import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_STACKTRACE; |
15 | | -import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_TYPE; |
16 | 12 | import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_INVOCATION_ID; |
17 | | -import static java.util.stream.Collectors.toList; |
18 | 13 | import static org.assertj.core.api.Assertions.catchThrowable; |
19 | 14 | import static org.mockito.Mockito.when; |
20 | 15 |
|
|
23 | 18 | import io.opentelemetry.api.logs.Severity; |
24 | 19 | import io.opentelemetry.api.trace.SpanKind; |
25 | 20 | import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; |
26 | | -import io.opentelemetry.sdk.logs.data.LogRecordData; |
27 | 21 | import io.opentelemetry.sdk.trace.data.StatusData; |
28 | | -import java.util.List; |
29 | | -import org.awaitility.Awaitility; |
30 | 22 | import org.junit.jupiter.api.AfterEach; |
31 | 23 | import org.junit.jupiter.api.BeforeEach; |
32 | 24 | import org.junit.jupiter.api.Test; |
@@ -100,29 +92,17 @@ void handlerTracedWithException() { |
100 | 92 | })); |
101 | 93 |
|
102 | 94 | if (emitExceptionAsLogs()) { |
103 | | - assertInvocationExceptionLog(); |
| 95 | + testing() |
| 96 | + .waitAndAssertLogRecords( |
| 97 | + logRecord -> |
| 98 | + logRecord |
| 99 | + .hasSeverity(Severity.ERROR) |
| 100 | + .hasEventName("faas.invocation.exception") |
| 101 | + .hasException(thrown) |
| 102 | + .hasTotalAttributeCount(3)); |
104 | 103 | } |
105 | 104 | } |
106 | 105 |
|
107 | | - private void assertInvocationExceptionLog() { |
108 | | - Awaitility.await() |
109 | | - .untilAsserted( |
110 | | - () -> { |
111 | | - List<LogRecordData> logs = |
112 | | - testing().logRecords().stream() |
113 | | - .filter(log -> "faas.invocation.exception".equals(log.getEventName())) |
114 | | - .collect(toList()); |
115 | | - assertThat(logs).hasSize(1); |
116 | | - assertThat(logs.get(0)) |
117 | | - .hasSeverity(Severity.ERROR) |
118 | | - .hasEventName("faas.invocation.exception") |
119 | | - .hasAttributesSatisfyingExactly( |
120 | | - satisfies(EXCEPTION_TYPE, val -> val.isNotNull()), |
121 | | - satisfies(EXCEPTION_MESSAGE, val -> val.isNotNull()), |
122 | | - satisfies(EXCEPTION_STACKTRACE, val -> val.isNotNull())); |
123 | | - }); |
124 | | - } |
125 | | - |
126 | 106 | /** |
127 | 107 | * For more details about active tracing see |
128 | 108 | * https://docs.aws.amazon.com/lambda/latest/dg/services-xray.html |
|
0 commit comments