diff --git a/google-http-client/src/main/java/com/google/api/client/http/HttpRequest.java b/google-http-client/src/main/java/com/google/api/client/http/HttpRequest.java index 0b9b2abbb..7a28ec515 100644 --- a/google-http-client/src/main/java/com/google/api/client/http/HttpRequest.java +++ b/google-http-client/src/main/java/com/google/api/client/http/HttpRequest.java @@ -1012,6 +1012,7 @@ public HttpResponse execute() throws IOException { LowLevelHttpResponse lowLevelHttpResponse = lowLevelHttpRequest.execute(); if (lowLevelHttpResponse != null) { OpenCensusUtils.recordReceivedMessageEvent(span, lowLevelHttpResponse.getContentLength()); + span.putAttribute(HttpTraceAttributeConstants.HTTP_STATUS_CODE, AttributeValue.longAttributeValue(lowLevelHttpResponse.getStatusCode())); } // Flag used to indicate if an exception is thrown before the response is constructed. boolean responseConstructed = false; diff --git a/google-http-client/src/test/java/com/google/api/client/http/HttpRequestTracingTest.java b/google-http-client/src/test/java/com/google/api/client/http/HttpRequestTracingTest.java index d2d2df5d1..6fc9cb37d 100644 --- a/google-http-client/src/test/java/com/google/api/client/http/HttpRequestTracingTest.java +++ b/google-http-client/src/test/java/com/google/api/client/http/HttpRequestTracingTest.java @@ -80,6 +80,7 @@ public void executeCreatesSpan() throws IOException { assertAttributeEquals(span, "http.host", "google.com"); assertAttributeEquals(span, "http.url", "https://google.com/"); assertAttributeEquals(span, "http.method", "GET"); + assertAttributeEquals(span, "http.status_code", "200"); // Ensure we have a single annotation for starting the first attempt assertEquals(1, span.getAnnotations().getEvents().size());