From 9da74ab266e9396a2674770ea448fd84ca6ac0a7 Mon Sep 17 00:00:00 2001 From: CI-Bot for Emmanuel Courreges Date: Mon, 2 Mar 2020 16:22:36 +0100 Subject: [PATCH] feat: add http.status_code attribute to all Spans that have at least a low level http response Signed-off-by: CI-Bot for Emmanuel Courreges --- .../src/main/java/com/google/api/client/http/HttpRequest.java | 1 + .../java/com/google/api/client/http/HttpRequestTracingTest.java | 1 + 2 files changed, 2 insertions(+) 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 9124e4906..6d2035ae2 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 5d89f0350..14e37162f 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 @@ -82,6 +82,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());