From fb02042ac216379820950879cea45d06eec5278c Mon Sep 17 00:00:00 2001 From: Emmanuel Courreges Date: Tue, 19 Jan 2021 15:45:11 +0100 Subject: [PATCH] feat: add http.status_code attribute to all Spans that have at least a low level http response (#986) 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 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());