Skip to content

Commit 9c7f131

Browse files
authored
fix: Vertx plugin, 400+ status codes should cause SLA fail (apache#662)
1 parent 4f2f81e commit 9c7f131

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Release Notes.
99
* fix forkjoinpool plugin in JDK11。
1010
* Support for tracing spring-cloud-gateway 4.x in gateway-4.x-plugin.
1111
* Fix re-transform bug when plugin enhanced class proxy parent method.
12+
* Fix error HTTP status codes not recording as SLA failures in Vert.x plugins.
1213

1314
#### Documentation
1415

apm-sniffer/apm-sdk-plugin/vertx-plugins/vertx-core-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpClientRequestImplHandleResponseInterceptor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr
4040
HttpClientRequestContext requestContext = (HttpClientRequestContext) objInst.getSkyWalkingDynamicField();
4141
if (!requestContext.usingWebClient) {
4242
VertxContext context = requestContext.vertxContext;
43-
Tags.HTTP_RESPONSE_STATUS_CODE.set(context.getSpan(), ((HttpClientResponse) allArguments[0]).statusCode());
43+
int statusCode = ((HttpClientResponse) allArguments[0]).statusCode();
44+
Tags.HTTP_RESPONSE_STATUS_CODE.set(context.getSpan(), statusCode);
45+
if (statusCode >= 400) {
46+
context.getSpan().errorOccurred();
47+
}
4448
context.getSpan().asyncFinish();
4549

4650
AbstractSpan span = ContextManager.createLocalSpan("#" + context.getSpan().getOperationName());

apm-sniffer/apm-sdk-plugin/vertx-plugins/vertx-core-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpContextHandleDispatchResponseInterceptor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr
4242
HttpClientRequest clientRequest = httpContext.clientRequest();
4343
VertxContext context = ((HttpClientRequestContext) ((EnhancedInstance) clientRequest)
4444
.getSkyWalkingDynamicField()).vertxContext;
45-
Tags.HTTP_RESPONSE_STATUS_CODE.set(context.getSpan(), httpContext.clientResponse().statusCode());
45+
int statusCode = httpContext.clientResponse().statusCode();
46+
Tags.HTTP_RESPONSE_STATUS_CODE.set(context.getSpan(), statusCode);
47+
if (statusCode >= 400) {
48+
context.getSpan().errorOccurred();
49+
}
4650
context.getSpan().asyncFinish();
4751

4852
AbstractSpan span = ContextManager.createLocalSpan("#" + context.getSpan().getOperationName());

apm-sniffer/apm-sdk-plugin/vertx-plugins/vertx-core-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx3/HttpServerResponseImplInterceptor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr
4343
if (VertxContext.VERTX_VERSION < 36 && allArguments[0] instanceof ByteBuf
4444
|| VertxContext.VERTX_VERSION >= 36 && VertxContext.VERTX_VERSION <= 37 || allArguments.length == 2) {
4545
VertxContext context = (VertxContext) objInst.getSkyWalkingDynamicField();
46-
Tags.HTTP_RESPONSE_STATUS_CODE.set(context.getSpan(), ((HttpServerResponse) objInst).getStatusCode());
46+
int statusCode = ((HttpServerResponse) objInst).getStatusCode();
47+
Tags.HTTP_RESPONSE_STATUS_CODE.set(context.getSpan(), statusCode);
48+
if (statusCode >= 400) {
49+
context.getSpan().errorOccurred();
50+
}
4751
context.getSpan().asyncFinish();
4852
}
4953
}

apm-sniffer/apm-sdk-plugin/vertx-plugins/vertx-core-4.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/vertx4/SWVertxTracer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ public <R> void sendResponse(Context context, R response, AbstractSpan payload,
8888
}
8989

9090
if (response instanceof HttpResponse) {
91-
Tags.HTTP_RESPONSE_STATUS_CODE.set(payload, ((HttpResponse) response).statusCode());
91+
int statusCode = ((HttpResponse) response).statusCode();
92+
Tags.HTTP_RESPONSE_STATUS_CODE.set(payload, statusCode);
93+
if (statusCode >= 400) {
94+
payload.errorOccurred();
95+
}
9296
}
9397
payload.asyncFinish();
9498
}

0 commit comments

Comments
 (0)