Skip to content

Commit

Permalink
Deprecate the 2-arg variant of HttpCommonAttributesGeter#statusCode() (
Browse files Browse the repository at this point in the history
…open-telemetry#6466)

* Deprecate the 2-arg variant of HttpCommonAttributesGeter#statusCode()

* fix liberty
  • Loading branch information
Mateusz Rzeszutek authored and LironKS committed Dec 4, 2022
1 parent 3273c25 commit e054fcc
Show file tree
Hide file tree
Showing 54 changed files with 92 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ default Long requestContentLengthUncompressed(REQUEST request, @Nullable RESPONS
*
* <p>This is called from {@link Instrumenter#end(Context, Object, Object, Throwable)}, only when
* {@code response} is non-{@code null}.
*
* @deprecated This method is deprecated and will be removed in the next release.
*/
// TODO: deprecate this method and use the new one everywhere
@Deprecated
@Nullable
Integer statusCode(REQUEST request, RESPONSE response);
default Integer statusCode(REQUEST request, RESPONSE response) {
throw new UnsupportedOperationException("This method is deprecated and will be removed");
}

/**
* Extracts the {@code http.status_code} span attribute.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.junit.jupiter.api.Test;

class HttpClientAttributesExtractorTest {
Expand All @@ -43,7 +44,8 @@ public List<String> requestHeader(Map<String, String> request, String name) {
}

@Override
public Integer statusCode(Map<String, String> request, Map<String, String> response) {
public Integer statusCode(
Map<String, String> request, Map<String, String> response, @Nullable Throwable error) {
return Integer.parseInt(response.get("statusCode"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import javax.annotation.Nullable;
import org.junit.jupiter.api.Test;

class HttpServerAttributesExtractorTest {
Expand Down Expand Up @@ -59,7 +60,8 @@ public List<String> requestHeader(Map<String, String> request, String name) {
}

@Override
public Integer statusCode(Map<String, String> request, Map<String, String> response) {
public Integer statusCode(
Map<String, String> request, Map<String, String> response, @Nullable Throwable error) {
String value = response.get("statusCode");
return value == null ? null : Integer.parseInt(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public String flavor(Void unused, @Nullable Void unused2) {
}

@Override
public Integer statusCode(Void unused, Void unused2) {
public Integer statusCode(Void unused, Void unused2, @Nullable Throwable error) {
return 200;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public List<String> requestHeader(HttpRequest httpRequest, String name) {
}

@Override
public Integer statusCode(HttpRequest httpRequest, HttpResponse httpResponse) {
public Integer statusCode(
HttpRequest httpRequest, HttpResponse httpResponse, @Nullable Throwable error) {
return httpResponse.status().intValue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public Long requestContentLength(HttpRequest request, @Nullable HttpResponse htt
}

@Override
public Integer statusCode(HttpRequest request, HttpResponse httpResponse) {
public Integer statusCode(
HttpRequest request, HttpResponse httpResponse, @Nullable Throwable error) {
return httpResponse.status().intValue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public List<String> requestHeader(ApacheHttpClientRequest request, String name)

@Override
@Nullable
public Integer statusCode(ApacheHttpClientRequest request, HttpResponse response) {
public Integer statusCode(
ApacheHttpClientRequest request, HttpResponse response, @Nullable Throwable error) {
StatusLine statusLine = response.getStatusLine();
return statusLine != null ? statusLine.getStatusCode() : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public List<String> requestHeader(HttpMethod request, String name) {

@Override
@Nullable
public Integer statusCode(HttpMethod request, HttpMethod response) {
public Integer statusCode(HttpMethod request, HttpMethod response, @Nullable Throwable error) {
StatusLine statusLine = response.getStatusLine();
return statusLine == null ? null : statusLine.getStatusCode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public List<String> requestHeader(ApacheHttpClientRequest request, String name)
}

@Override
public Integer statusCode(ApacheHttpClientRequest request, HttpResponse response) {
public Integer statusCode(
ApacheHttpClientRequest request, HttpResponse response, @Nullable Throwable error) {
return response.getStatusLine().getStatusCode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public List<String> requestHeader(ApacheHttpClientRequest request, String name)
}

@Override
public Integer statusCode(ApacheHttpClientRequest request, HttpResponse response) {
public Integer statusCode(
ApacheHttpClientRequest request, HttpResponse response, @Nullable Throwable error) {
return response.getStatusLine().getStatusCode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public List<String> requestHeader(HttpRequest request, String name) {
}

@Override
public Integer statusCode(HttpRequest request, HttpResponse response) {
public Integer statusCode(HttpRequest request, HttpResponse response, @Nullable Throwable error) {
return response.getCode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public List<String> requestHeader(RequestContext ctx, String name) {

@Override
@Nullable
public Integer statusCode(RequestContext ctx, RequestLog requestLog) {
public Integer statusCode(RequestContext ctx, RequestLog requestLog, @Nullable Throwable error) {
HttpStatus status = requestLog.responseHeaders().status();
if (!status.equals(HttpStatus.UNKNOWN)) {
return status.code();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public List<String> requestHeader(RequestContext ctx, String name) {

@Override
@Nullable
public Integer statusCode(RequestContext ctx, RequestLog requestLog) {
public Integer statusCode(RequestContext ctx, RequestLog requestLog, @Nullable Throwable error) {
HttpStatus status = requestLog.responseHeaders().status();
if (!status.equals(HttpStatus.UNKNOWN)) {
return status.code();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public List<String> requestHeader(Request request, String name) {
}

@Override
public Integer statusCode(Request request, Response response) {
public Integer statusCode(Request request, Response response, @Nullable Throwable error) {
return response.getStatusCode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public List<String> requestHeader(RequestContext requestContext, String name) {
}

@Override
public Integer statusCode(RequestContext requestContext, Response response) {
public Integer statusCode(
RequestContext requestContext, Response response, @Nullable Throwable error) {
return response.getStatusCode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public List<String> requestHeader(Request<?> request, String name) {
}

@Override
public Integer statusCode(Request<?> request, Response<?> response) {
public Integer statusCode(Request<?> request, Response<?> response, @Nullable Throwable error) {
return response.getHttpResponse().getStatusCode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public List<String> requestHeader(ExecutionAttributes request, String name) {
}

@Override
public Integer statusCode(ExecutionAttributes request, SdkHttpResponse response) {
public Integer statusCode(
ExecutionAttributes request, SdkHttpResponse response, @Nullable Throwable error) {
return response.statusCode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public String flavor(HttpRequest httpRequest, @Nullable HttpResponse httpRespons
}

@Override
public Integer statusCode(HttpRequest httpRequest, HttpResponse httpResponse) {
public Integer statusCode(
HttpRequest httpRequest, HttpResponse httpResponse, @Nullable Throwable error) {
return httpResponse.getStatusCode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ private static List<String> toHeaderList(Iterable<String> values) {
}

@Override
public Integer statusCode(HttpRequestPacket request, HttpResponsePacket response) {
public Integer statusCode(
HttpRequestPacket request, HttpResponsePacket response, @Nullable Throwable error) {
return response.getStatus();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public String flavor(HttpURLConnection connection, @Nullable Integer statusCode)
}

@Override
public Integer statusCode(HttpURLConnection connection, Integer statusCode) {
public Integer statusCode(
HttpURLConnection connection, Integer statusCode, @Nullable Throwable error) {
return statusCode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public List<String> requestHeader(HttpRequest httpRequest, String name) {
}

@Override
public Integer statusCode(HttpRequest httpRequest, HttpResponse<?> httpResponse) {
public Integer statusCode(
HttpRequest httpRequest, HttpResponse<?> httpResponse, @Nullable Throwable error) {
return httpResponse.statusCode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public String flavor(ClientRequest httpRequest, @Nullable ClientResponse httpRes
}

@Override
public Integer statusCode(ClientRequest httpRequest, ClientResponse httpResponse) {
public Integer statusCode(
ClientRequest httpRequest, ClientResponse httpResponse, @Nullable Throwable error) {
return httpResponse.getStatus();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public String flavor(Request request, @Nullable Response response) {
}

@Override
public Integer statusCode(Request request, Response response) {
public Integer statusCode(Request request, Response response, @Nullable Throwable error) {
return response.getStatus();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public void end(
throwable = errorException(request);
}

ServletResponseContext<RESPONSE> responseContext =
new ServletResponseContext<>(response, throwable);
ServletResponseContext<RESPONSE> responseContext = new ServletResponseContext<>(response);
if (throwable != null || mustEndOnHandlerMethodExit(request)) {
instrumenter.end(context, requestContext, responseContext, throwable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal enum class KtorHttpServerAttributesGetter :
return request.headers.getAll(name) ?: emptyList()
}

override fun statusCode(request: ApplicationRequest, response: ApplicationResponse): Int? {
override fun statusCode(request: ApplicationRequest, response: ApplicationResponse, error: Throwable?): Int? {
return response.status()?.value
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal enum class KtorHttpServerAttributesGetter :
return request.headers.getAll(name) ?: emptyList()
}

override fun statusCode(request: ApplicationRequest, response: ApplicationResponse): Int? {
override fun statusCode(request: ApplicationRequest, response: ApplicationResponse, error: Throwable?): Int? {
return response.status()?.value
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public String flavor(Request request, @Nullable ApiResponse<?> apiResponse) {
}

@Override
public Integer statusCode(Request request, ApiResponse<?> apiResponse) {
public Integer statusCode(
Request request, ApiResponse<?> apiResponse, @Nullable Throwable error) {
return apiResponse.getStatusCode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public void end(
throwable = AppServerBridge.getException(context);
}

ServletResponseContext<RESPONSE> responseContext =
new ServletResponseContext<>(response, throwable);
ServletResponseContext<RESPONSE> responseContext = new ServletResponseContext<>(response);
if (throwable != null || mustEndOnHandlerMethodExit(request)) {
instrumenter.end(context, requestContext, responseContext, throwable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public String flavor(LibertyRequest libertyRequest) {

@Override
@Nullable
public Integer statusCode(LibertyRequest libertyRequest, LibertyResponse libertyResponse) {
public Integer statusCode(
LibertyRequest libertyRequest, LibertyResponse libertyResponse, @Nullable Throwable error) {
return libertyResponse.getStatus();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public List<String> requestHeader(HttpRequestAndChannel requestAndChannel, Strin
}

@Override
public Integer statusCode(HttpRequestAndChannel requestAndChannel, HttpResponse response) {
public Integer statusCode(
HttpRequestAndChannel requestAndChannel, HttpResponse response, @Nullable Throwable error) {
return response.getStatus().getCode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public List<String> requestHeader(HttpRequestAndChannel requestAndChannel, Strin
}

@Override
public Integer statusCode(HttpRequestAndChannel requestAndChannel, HttpResponse response) {
public Integer statusCode(
HttpRequestAndChannel requestAndChannel, HttpResponse response, @Nullable Throwable error) {
return response.getStatus().getCode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public List<String> requestHeader(HttpRequestAndChannel requestAndChannel, Strin
}

@Override
public Integer statusCode(HttpRequestAndChannel requestAndChannel, HttpResponse response) {
public Integer statusCode(
HttpRequestAndChannel requestAndChannel, HttpResponse response, @Nullable Throwable error) {
return response.getStatus().code();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public List<String> requestHeader(HttpRequestAndChannel requestAndChannel, Strin
}

@Override
public Integer statusCode(HttpRequestAndChannel requestAndChannel, HttpResponse response) {
public Integer statusCode(
HttpRequestAndChannel requestAndChannel, HttpResponse response, @Nullable Throwable error) {
return response.getStatus().code();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public List<String> requestHeader(Request request, String name) {
}

@Override
public Integer statusCode(Request request, Response response) {
public Integer statusCode(Request request, Response response, @Nullable Throwable error) {
return response.code();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String flavor(Request request, @Nullable Response response) {
}

@Override
public Integer statusCode(Request request, Response response) {
public Integer statusCode(Request request, Response response, @Nullable Throwable error) {
return response.code();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public List<String> requestHeader(String s, String name) {

@Nullable
@Override
public Integer statusCode(String s, Void unused) {
public Integer statusCode(String s, Void unused, @Nullable Throwable error) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public List<String> requestHeader(Request request, String name) {
}

@Override
public Integer statusCode(Request request, Response response) {
public Integer statusCode(Request request, Response response, @Nullable Throwable error) {
return response.getStatusCode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public String serverName(Request request) {
}

@Override
public Integer statusCode(Request request, Response response) {
public Integer statusCode(Request request, Response response, @Nullable Throwable error) {
return response.getStatus().getCode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public List<String> requestHeader(RequestSpec requestSpec, String name) {
}

@Override
public Integer statusCode(RequestSpec requestSpec, HttpResponse httpResponse) {
public Integer statusCode(
RequestSpec requestSpec, HttpResponse httpResponse, @Nullable Throwable error) {
return httpResponse.getStatusCode();
}

Expand Down
Loading

0 comments on commit e054fcc

Please sign in to comment.