|
5 | 5 |
|
6 | 6 | package io.opentelemetry.instrumentation.spring.webflux.server; |
7 | 7 |
|
| 8 | +import static io.opentelemetry.instrumentation.api.internal.SemconvExceptionSignal.emitExceptionAsLogs; |
| 9 | +import static io.opentelemetry.instrumentation.api.internal.SemconvExceptionSignal.emitExceptionAsSpanEvents; |
8 | 10 | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; |
9 | 11 | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND; |
10 | 12 | import static io.opentelemetry.instrumentation.testing.util.TestLatestDeps.testLatestDeps; |
@@ -35,44 +37,65 @@ protected SpanDataAssert assertHandlerSpan( |
35 | 37 | span.hasName(handlerSpanName).hasKind(SpanKind.INTERNAL); |
36 | 38 | if (endpoint == EXCEPTION) { |
37 | 39 | span.hasStatus(StatusData.error()); |
38 | | - span.hasEventsSatisfyingExactly( |
39 | | - event -> |
40 | | - event |
41 | | - .hasName("exception") |
42 | | - .hasAttributesSatisfyingExactly( |
43 | | - equalTo(EXCEPTION_TYPE, "java.lang.IllegalStateException"), |
44 | | - equalTo(EXCEPTION_MESSAGE, EXCEPTION.getBody()), |
45 | | - satisfies(EXCEPTION_STACKTRACE, val -> val.isInstanceOf(String.class)))); |
46 | | - } else if (endpoint == NOT_FOUND) { |
47 | | - span.hasStatus(StatusData.error()); |
48 | | - if (testLatestDeps()) { |
49 | | - span.hasEventsSatisfyingExactly( |
50 | | - event -> |
51 | | - event |
52 | | - .hasName("exception") |
53 | | - .hasAttributesSatisfyingExactly( |
54 | | - equalTo( |
55 | | - EXCEPTION_TYPE, |
56 | | - "org.springframework.web.reactive.resource.NoResourceFoundException"), |
57 | | - equalTo( |
58 | | - EXCEPTION_MESSAGE, "404 NOT_FOUND \"No static resource notFound.\""), |
59 | | - satisfies(EXCEPTION_STACKTRACE, val -> val.isInstanceOf(String.class)))); |
60 | | - } else { |
| 40 | + if (emitExceptionAsSpanEvents()) { |
61 | 41 | span.hasEventsSatisfyingExactly( |
62 | 42 | event -> |
63 | 43 | event |
64 | 44 | .hasName("exception") |
65 | 45 | .hasAttributesSatisfyingExactly( |
66 | | - satisfies( |
67 | | - EXCEPTION_TYPE, |
68 | | - val -> |
69 | | - val.isIn( |
70 | | - "org.springframework.web.server.ResponseStatusException", |
71 | | - // Changed in spring 7+ |
72 | | - "org.springframework.web.reactive.resource.NoResourceFoundException")), |
73 | | - satisfies(EXCEPTION_MESSAGE, val -> val.contains("404")), |
| 46 | + equalTo(EXCEPTION_TYPE, "java.lang.IllegalStateException"), |
| 47 | + equalTo(EXCEPTION_MESSAGE, EXCEPTION.getBody()), |
74 | 48 | satisfies(EXCEPTION_STACKTRACE, val -> val.isInstanceOf(String.class)))); |
75 | 49 | } |
| 50 | + } else if (endpoint == NOT_FOUND) { |
| 51 | + span.hasStatus(StatusData.error()); |
| 52 | + if (emitExceptionAsSpanEvents()) { |
| 53 | + if (testLatestDeps()) { |
| 54 | + span.hasEventsSatisfyingExactly( |
| 55 | + event -> |
| 56 | + event |
| 57 | + .hasName("exception") |
| 58 | + .hasAttributesSatisfyingExactly( |
| 59 | + equalTo( |
| 60 | + EXCEPTION_TYPE, |
| 61 | + "org.springframework.web.reactive.resource.NoResourceFoundException"), |
| 62 | + equalTo( |
| 63 | + EXCEPTION_MESSAGE, |
| 64 | + "404 NOT_FOUND \"No static resource notFound.\""), |
| 65 | + satisfies(EXCEPTION_STACKTRACE, val -> val.isInstanceOf(String.class)))); |
| 66 | + } else { |
| 67 | + span.hasEventsSatisfyingExactly( |
| 68 | + event -> |
| 69 | + event |
| 70 | + .hasName("exception") |
| 71 | + .hasAttributesSatisfyingExactly( |
| 72 | + satisfies( |
| 73 | + EXCEPTION_TYPE, |
| 74 | + val -> |
| 75 | + val.isIn( |
| 76 | + "org.springframework.web.server.ResponseStatusException", |
| 77 | + // Changed in spring 7+ |
| 78 | + "org.springframework.web.reactive.resource.NoResourceFoundException")), |
| 79 | + satisfies(EXCEPTION_MESSAGE, val -> val.contains("404")), |
| 80 | + satisfies(EXCEPTION_STACKTRACE, val -> val.isInstanceOf(String.class)))); |
| 81 | + } |
| 82 | + } |
| 83 | + if (emitExceptionAsLogs()) { |
| 84 | + if (testLatestDeps()) { |
| 85 | + assertHandlerExceptionLog( |
| 86 | + type -> |
| 87 | + type.isEqualTo( |
| 88 | + "org.springframework.web.reactive.resource.NoResourceFoundException"), |
| 89 | + message -> message.isEqualTo("404 NOT_FOUND \"No static resource notFound.\"")); |
| 90 | + } else { |
| 91 | + assertHandlerExceptionLog( |
| 92 | + type -> |
| 93 | + type.isIn( |
| 94 | + "org.springframework.web.server.ResponseStatusException", |
| 95 | + "org.springframework.web.reactive.resource.NoResourceFoundException"), |
| 96 | + message -> message.contains("404")); |
| 97 | + } |
| 98 | + } |
76 | 99 | } |
77 | 100 | return span; |
78 | 101 | } |
|
0 commit comments