|
1 | | -/* |
2 | | - * Copyright The OpenTelemetry Authors |
3 | | - * SPDX-License-Identifier: Apache-2.0 |
4 | | - */ |
5 | | - |
6 | | -package io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server.base; |
7 | | - |
8 | | -import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; |
9 | | -import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND; |
10 | | -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; |
11 | | -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; |
12 | | -import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_MESSAGE; |
13 | | -import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_STACKTRACE; |
14 | | -import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_TYPE; |
15 | | - |
16 | | -import io.opentelemetry.api.trace.SpanKind; |
17 | | -import io.opentelemetry.instrumentation.api.internal.HttpConstants; |
18 | | -import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions; |
19 | | -import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; |
20 | | -import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; |
21 | | -import io.opentelemetry.sdk.trace.data.StatusData; |
22 | | - |
23 | | -public abstract class HandlerSpringWebFluxServerTest extends SpringWebFluxServerTest { |
24 | | - |
25 | | - @Override |
26 | | - protected SpanDataAssert assertHandlerSpan( |
27 | | - SpanDataAssert span, String method, ServerEndpoint endpoint) { |
28 | | - String handlerSpanName = ServerTestRouteFactory.class.getSimpleName() + "$$Lambda.handle"; |
29 | | - if (endpoint == NOT_FOUND) { |
30 | | - handlerSpanName = "ResourceWebHandler.handle"; |
31 | | - } |
32 | | - span.hasName(handlerSpanName).hasKind(SpanKind.INTERNAL); |
33 | | - if (endpoint == EXCEPTION) { |
34 | | - span.hasStatus(StatusData.error()); |
35 | | - span.hasEventsSatisfyingExactly( |
36 | | - event -> |
37 | | - event |
38 | | - .hasName("exception") |
39 | | - .hasAttributesSatisfyingExactly( |
40 | | - equalTo(EXCEPTION_TYPE, "java.lang.IllegalStateException"), |
41 | | - equalTo(EXCEPTION_MESSAGE, EXCEPTION.getBody()), |
42 | | - satisfies(EXCEPTION_STACKTRACE, val -> val.isInstanceOf(String.class)))); |
43 | | - } else if (endpoint == NOT_FOUND) { |
44 | | - span.hasStatus(StatusData.error()); |
45 | | - if (Boolean.getBoolean("testLatestDeps")) { |
46 | | - span.hasEventsSatisfyingExactly( |
47 | | - event -> |
48 | | - event |
49 | | - .hasName("exception") |
50 | | - .hasAttributesSatisfyingExactly( |
51 | | - equalTo( |
52 | | - EXCEPTION_TYPE, |
53 | | - "org.springframework.web.reactive.resource.NoResourceFoundException"), |
54 | | - equalTo( |
55 | | - EXCEPTION_MESSAGE, "404 NOT_FOUND \"No static resource notFound.\""), |
56 | | - satisfies(EXCEPTION_STACKTRACE, val -> val.isInstanceOf(String.class)))); |
57 | | - } else { |
58 | | - span.hasEventsSatisfyingExactly( |
59 | | - event -> |
60 | | - event |
61 | | - .hasName("exception") |
62 | | - .hasAttributesSatisfyingExactly( |
63 | | - equalTo( |
64 | | - EXCEPTION_TYPE, |
65 | | - "org.springframework.web.server.ResponseStatusException"), |
66 | | - equalTo(EXCEPTION_MESSAGE, "Response status 404"), |
67 | | - satisfies(EXCEPTION_STACKTRACE, val -> val.isInstanceOf(String.class)))); |
68 | | - } |
69 | | - } |
70 | | - return span; |
71 | | - } |
72 | | - |
73 | | - @Override |
74 | | - protected void configure(HttpServerTestOptions options) { |
75 | | - super.configure(options); |
76 | | - // TODO (trask) it seems like in this case ideally the controller span (which ends when the |
77 | | - // Mono that the controller returns completes) should end before the server span (which needs |
78 | | - // the result of the Mono) |
79 | | - options.setVerifyServerSpanEndTime(false); |
80 | | - |
81 | | - options.setResponseCodeOnNonStandardHttpMethod(404); |
82 | | - } |
83 | | - |
84 | | - @Override |
85 | | - public String expectedHttpRoute(ServerEndpoint endpoint, String method) { |
86 | | - if (HttpConstants._OTHER.equals(method)) { |
87 | | - return getContextPath() + "/**"; |
88 | | - } |
89 | | - return super.expectedHttpRoute(endpoint, method); |
90 | | - } |
91 | | -} |
| 1 | +///* |
| 2 | +// * Copyright The OpenTelemetry Authors |
| 3 | +// * SPDX-License-Identifier: Apache-2.0 |
| 4 | +// */ |
| 5 | +// |
| 6 | +//package io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server.base; |
| 7 | +// |
| 8 | +//import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; |
| 9 | +//import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND; |
| 10 | +//import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; |
| 11 | +//import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; |
| 12 | +//import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_MESSAGE; |
| 13 | +//import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_STACKTRACE; |
| 14 | +//import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_TYPE; |
| 15 | +// |
| 16 | +//import io.opentelemetry.api.trace.SpanKind; |
| 17 | +//import io.opentelemetry.instrumentation.api.internal.HttpConstants; |
| 18 | +//import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions; |
| 19 | +//import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; |
| 20 | +//import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; |
| 21 | +//import io.opentelemetry.sdk.trace.data.StatusData; |
| 22 | +// |
| 23 | +//public abstract class HandlerSpringWebFluxServerTest extends SpringWebFluxServerTest { |
| 24 | +// |
| 25 | +// @Override |
| 26 | +// protected SpanDataAssert assertHandlerSpan( |
| 27 | +// SpanDataAssert span, String method, ServerEndpoint endpoint) { |
| 28 | +// String handlerSpanName = ServerTestRouteFactory.class.getSimpleName() + "$$Lambda.handle"; |
| 29 | +// if (endpoint == NOT_FOUND) { |
| 30 | +// handlerSpanName = "ResourceWebHandler.handle"; |
| 31 | +// } |
| 32 | +// span.hasName(handlerSpanName).hasKind(SpanKind.INTERNAL); |
| 33 | +// if (endpoint == EXCEPTION) { |
| 34 | +// span.hasStatus(StatusData.error()); |
| 35 | +// span.hasEventsSatisfyingExactly( |
| 36 | +// event -> |
| 37 | +// event |
| 38 | +// .hasName("exception") |
| 39 | +// .hasAttributesSatisfyingExactly( |
| 40 | +// equalTo(EXCEPTION_TYPE, "java.lang.IllegalStateException"), |
| 41 | +// equalTo(EXCEPTION_MESSAGE, EXCEPTION.getBody()), |
| 42 | +// satisfies(EXCEPTION_STACKTRACE, val -> val.isInstanceOf(String.class)))); |
| 43 | +// } else if (endpoint == NOT_FOUND) { |
| 44 | +// span.hasStatus(StatusData.error()); |
| 45 | +// if (Boolean.getBoolean("testLatestDeps")) { |
| 46 | +// span.hasEventsSatisfyingExactly( |
| 47 | +// event -> |
| 48 | +// event |
| 49 | +// .hasName("exception") |
| 50 | +// .hasAttributesSatisfyingExactly( |
| 51 | +// equalTo( |
| 52 | +// EXCEPTION_TYPE, |
| 53 | +// "org.springframework.web.reactive.resource.NoResourceFoundException"), |
| 54 | +// equalTo( |
| 55 | +// EXCEPTION_MESSAGE, "404 NOT_FOUND \"No static resource notFound.\""), |
| 56 | +// satisfies(EXCEPTION_STACKTRACE, val -> val.isInstanceOf(String.class)))); |
| 57 | +// } else { |
| 58 | +// span.hasEventsSatisfyingExactly( |
| 59 | +// event -> |
| 60 | +// event |
| 61 | +// .hasName("exception") |
| 62 | +// .hasAttributesSatisfyingExactly( |
| 63 | +// equalTo( |
| 64 | +// EXCEPTION_TYPE, |
| 65 | +// "org.springframework.web.server.ResponseStatusException"), |
| 66 | +// equalTo(EXCEPTION_MESSAGE, "Response status 404"), |
| 67 | +// satisfies(EXCEPTION_STACKTRACE, val -> val.isInstanceOf(String.class)))); |
| 68 | +// } |
| 69 | +// } |
| 70 | +// return span; |
| 71 | +// } |
| 72 | +// |
| 73 | +// @Override |
| 74 | +// protected void configure(HttpServerTestOptions options) { |
| 75 | +// super.configure(options); |
| 76 | +// // TODO (trask) it seems like in this case ideally the controller span (which ends when the |
| 77 | +// // Mono that the controller returns completes) should end before the server span (which needs |
| 78 | +// // the result of the Mono) |
| 79 | +// options.setVerifyServerSpanEndTime(false); |
| 80 | +// |
| 81 | +// options.setResponseCodeOnNonStandardHttpMethod(404); |
| 82 | +// } |
| 83 | +// |
| 84 | +// @Override |
| 85 | +// public String expectedHttpRoute(ServerEndpoint endpoint, String method) { |
| 86 | +// if (HttpConstants._OTHER.equals(method)) { |
| 87 | +// return getContextPath() + "/**"; |
| 88 | +// } |
| 89 | +// return super.expectedHttpRoute(endpoint, method); |
| 90 | +// } |
| 91 | +//} |
0 commit comments