From 62e2ba95c148982def4931bbe1f174976959da30 Mon Sep 17 00:00:00 2001 From: Andre Onuki Date: Thu, 14 Dec 2023 09:42:44 -0500 Subject: [PATCH] Revert "NEWRELIC-4831 Clean up deprecated attributes (#1125)" This reverts commit 4e36bc58a660d2f50b1f515c512ec055bf25d90e. --- .../agent/instrumentation/akka/http/AkkaHttpRoutesTest.java | 2 +- .../agent/instrumentation/akka/http/AkkaHttpRoutesTest.java | 2 +- .../java/io/grpc/internal/ServerStream_Instrumentation.java | 2 ++ .../grpc-1.22.0/src/test/java/ValidationHelper.java | 4 ++++ .../java/io/grpc/internal/ServerStream_Instrumentation.java | 2 ++ .../grpc-1.30.0/src/test/java/ValidationHelper.java | 4 ++++ .../java/io/grpc/internal/ServerStream_Instrumentation.java | 2 ++ .../grpc-1.4.0/src/test/java/ValidationHelper.java | 4 ++++ .../java/com/nr/agent/instrumentation/grpc/GrpcUtil.java | 4 ++-- .../grpc-1.40.0/src/test/java/ValidationHelper.java | 4 ++++ .../java/com/newrelic/agent/attributes/AttributeNames.java | 2 ++ .../newrelic/agent/dispatchers/WebRequestDispatcher.java | 3 +++ .../newrelic/agent/service/analytics/SpanEventFactory.java | 3 +++ .../agent/service/analytics/TracerToSpanEventTest.java | 6 ++++++ 14 files changed, 40 insertions(+), 4 deletions(-) diff --git a/instrumentation/akka-http-2.11_2.4.5/src/test/java/com/agent/instrumentation/akka/http/AkkaHttpRoutesTest.java b/instrumentation/akka-http-2.11_2.4.5/src/test/java/com/agent/instrumentation/akka/http/AkkaHttpRoutesTest.java index f88a9c51bd..de24a030ce 100644 --- a/instrumentation/akka-http-2.11_2.4.5/src/test/java/com/agent/instrumentation/akka/http/AkkaHttpRoutesTest.java +++ b/instrumentation/akka-http-2.11_2.4.5/src/test/java/com/agent/instrumentation/akka/http/AkkaHttpRoutesTest.java @@ -1650,7 +1650,7 @@ private void assertResponseCodeOnTxEvents(Collection transacti Assert.assertNotNull(transactionEvents); Assert.assertEquals(expectedSize, transactionEvents.size()); for (TransactionEvent transactionEvent : transactionEvents) { - String httpResponseCode = String.valueOf(transactionEvent.getAttributes().get("http.statusCode")); + String httpResponseCode = String.valueOf(transactionEvent.getAttributes().get("httpResponseCode")); Assert.assertNotNull(httpResponseCode); Assert.assertEquals(expectedResponseCode, httpResponseCode); } diff --git a/instrumentation/akka-http-2.13_10.1.8/src/test/java/com/agent/instrumentation/akka/http/AkkaHttpRoutesTest.java b/instrumentation/akka-http-2.13_10.1.8/src/test/java/com/agent/instrumentation/akka/http/AkkaHttpRoutesTest.java index c4089f8fa8..15f5eeed77 100644 --- a/instrumentation/akka-http-2.13_10.1.8/src/test/java/com/agent/instrumentation/akka/http/AkkaHttpRoutesTest.java +++ b/instrumentation/akka-http-2.13_10.1.8/src/test/java/com/agent/instrumentation/akka/http/AkkaHttpRoutesTest.java @@ -1646,7 +1646,7 @@ private void assertResponseCodeOnTxEvents(Collection transacti Assert.assertNotNull(transactionEvents); Assert.assertEquals(expectedSize, transactionEvents.size()); for (TransactionEvent transactionEvent : transactionEvents) { - String httpResponseCode = String.valueOf(transactionEvent.getAttributes().get("http.statusCode")); + String httpResponseCode = String.valueOf(transactionEvent.getAttributes().get("httpResponseCode")); Assert.assertNotNull(httpResponseCode); Assert.assertEquals(expectedResponseCode, httpResponseCode); } diff --git a/instrumentation/grpc-1.22.0/src/main/java/io/grpc/internal/ServerStream_Instrumentation.java b/instrumentation/grpc-1.22.0/src/main/java/io/grpc/internal/ServerStream_Instrumentation.java index 9833b4c404..e6128f7b64 100644 --- a/instrumentation/grpc-1.22.0/src/main/java/io/grpc/internal/ServerStream_Instrumentation.java +++ b/instrumentation/grpc-1.22.0/src/main/java/io/grpc/internal/ServerStream_Instrumentation.java @@ -39,6 +39,7 @@ public void close(Status status, Metadata trailers) { if (status != null) { int statusCode = status.getCode().value(); + NewRelic.addCustomParameter("response.status", statusCode); NewRelic.addCustomParameter("http.statusCode", statusCode); NewRelic.addCustomParameter("http.statusText", status.getDescription()); @@ -69,6 +70,7 @@ public void cancel(Status status) { if (status != null) { int statusCode = status.getCode().value(); + NewRelic.addCustomParameter("response.status", statusCode); NewRelic.addCustomParameter("http.statusCode", statusCode); NewRelic.addCustomParameter("http.statusText", status.getDescription()); if (GrpcConfig.errorsEnabled && status.getCause() != null) { diff --git a/instrumentation/grpc-1.22.0/src/test/java/ValidationHelper.java b/instrumentation/grpc-1.22.0/src/test/java/ValidationHelper.java index a6beb20bce..974bed325e 100644 --- a/instrumentation/grpc-1.22.0/src/test/java/ValidationHelper.java +++ b/instrumentation/grpc-1.22.0/src/test/java/ValidationHelper.java @@ -68,6 +68,7 @@ static void validateGrpcInteraction(TestServer server, String clientTxName, Stri assertTrue(rootSegment.getName().endsWith(fullMethod)); assertEquals(1, rootSegment.getCallCount()); assertEquals(fullMethod, rootSegment.getTracerAttributes().get("request.method")); + assertEquals(0, rootSegment.getTracerAttributes().get("response.status")); assertEquals(0, rootSegment.getTracerAttributes().get("http.statusCode")); assertNull(rootSegment.getTracerAttributes().get("http.statusText")); assertEquals(grpcType, rootSegment.getTracerAttributes().get("grpc.type")); @@ -85,6 +86,7 @@ static void validateGrpcInteraction(TestServer server, String clientTxName, Stri assertEquals(name, serverTxEvent.getAttributes().get("sayHelloAfter")); } + assertEquals(0, serverTxEvent.getAttributes().get("response.status")); assertEquals(0, serverTxEvent.getAttributes().get("http.statusCode")); assertEquals("grpc://localhost:" + server.getPort() + "/" + fullMethod, serverTxEvent.getAttributes().get("request.uri")); } @@ -125,6 +127,7 @@ static void validateExceptionGrpcInteraction(TestServer server, String clientTxN assertTrue(rootSegment.getName().endsWith(fullMethod)); assertEquals(1, rootSegment.getCallCount()); assertEquals(fullMethod, rootSegment.getTracerAttributes().get("request.method")); + assertEquals(status, rootSegment.getTracerAttributes().get("response.status")); assertEquals(status, rootSegment.getTracerAttributes().get("http.statusCode")); assertEquals(grpcType, rootSegment.getTracerAttributes().get("grpc.type")); @@ -133,6 +136,7 @@ static void validateExceptionGrpcInteraction(TestServer server, String clientTxN assertEquals(1, serverTxEvents.size()); TransactionEvent serverTxEvent = serverTxEvents.iterator().next(); assertNotNull(serverTxEvent); + assertEquals(status, serverTxEvent.getAttributes().get("response.status")); assertEquals(status, serverTxEvent.getAttributes().get("http.statusCode")); assertEquals("grpc://localhost:" + server.getPort() + "/" + fullMethod, serverTxEvent.getAttributes().get("request.uri")); } diff --git a/instrumentation/grpc-1.30.0/src/main/java/io/grpc/internal/ServerStream_Instrumentation.java b/instrumentation/grpc-1.30.0/src/main/java/io/grpc/internal/ServerStream_Instrumentation.java index 9833b4c404..e6128f7b64 100644 --- a/instrumentation/grpc-1.30.0/src/main/java/io/grpc/internal/ServerStream_Instrumentation.java +++ b/instrumentation/grpc-1.30.0/src/main/java/io/grpc/internal/ServerStream_Instrumentation.java @@ -39,6 +39,7 @@ public void close(Status status, Metadata trailers) { if (status != null) { int statusCode = status.getCode().value(); + NewRelic.addCustomParameter("response.status", statusCode); NewRelic.addCustomParameter("http.statusCode", statusCode); NewRelic.addCustomParameter("http.statusText", status.getDescription()); @@ -69,6 +70,7 @@ public void cancel(Status status) { if (status != null) { int statusCode = status.getCode().value(); + NewRelic.addCustomParameter("response.status", statusCode); NewRelic.addCustomParameter("http.statusCode", statusCode); NewRelic.addCustomParameter("http.statusText", status.getDescription()); if (GrpcConfig.errorsEnabled && status.getCause() != null) { diff --git a/instrumentation/grpc-1.30.0/src/test/java/ValidationHelper.java b/instrumentation/grpc-1.30.0/src/test/java/ValidationHelper.java index a6beb20bce..974bed325e 100644 --- a/instrumentation/grpc-1.30.0/src/test/java/ValidationHelper.java +++ b/instrumentation/grpc-1.30.0/src/test/java/ValidationHelper.java @@ -68,6 +68,7 @@ static void validateGrpcInteraction(TestServer server, String clientTxName, Stri assertTrue(rootSegment.getName().endsWith(fullMethod)); assertEquals(1, rootSegment.getCallCount()); assertEquals(fullMethod, rootSegment.getTracerAttributes().get("request.method")); + assertEquals(0, rootSegment.getTracerAttributes().get("response.status")); assertEquals(0, rootSegment.getTracerAttributes().get("http.statusCode")); assertNull(rootSegment.getTracerAttributes().get("http.statusText")); assertEquals(grpcType, rootSegment.getTracerAttributes().get("grpc.type")); @@ -85,6 +86,7 @@ static void validateGrpcInteraction(TestServer server, String clientTxName, Stri assertEquals(name, serverTxEvent.getAttributes().get("sayHelloAfter")); } + assertEquals(0, serverTxEvent.getAttributes().get("response.status")); assertEquals(0, serverTxEvent.getAttributes().get("http.statusCode")); assertEquals("grpc://localhost:" + server.getPort() + "/" + fullMethod, serverTxEvent.getAttributes().get("request.uri")); } @@ -125,6 +127,7 @@ static void validateExceptionGrpcInteraction(TestServer server, String clientTxN assertTrue(rootSegment.getName().endsWith(fullMethod)); assertEquals(1, rootSegment.getCallCount()); assertEquals(fullMethod, rootSegment.getTracerAttributes().get("request.method")); + assertEquals(status, rootSegment.getTracerAttributes().get("response.status")); assertEquals(status, rootSegment.getTracerAttributes().get("http.statusCode")); assertEquals(grpcType, rootSegment.getTracerAttributes().get("grpc.type")); @@ -133,6 +136,7 @@ static void validateExceptionGrpcInteraction(TestServer server, String clientTxN assertEquals(1, serverTxEvents.size()); TransactionEvent serverTxEvent = serverTxEvents.iterator().next(); assertNotNull(serverTxEvent); + assertEquals(status, serverTxEvent.getAttributes().get("response.status")); assertEquals(status, serverTxEvent.getAttributes().get("http.statusCode")); assertEquals("grpc://localhost:" + server.getPort() + "/" + fullMethod, serverTxEvent.getAttributes().get("request.uri")); } diff --git a/instrumentation/grpc-1.4.0/src/main/java/io/grpc/internal/ServerStream_Instrumentation.java b/instrumentation/grpc-1.4.0/src/main/java/io/grpc/internal/ServerStream_Instrumentation.java index 1b91851d81..0e84e2c28f 100644 --- a/instrumentation/grpc-1.4.0/src/main/java/io/grpc/internal/ServerStream_Instrumentation.java +++ b/instrumentation/grpc-1.4.0/src/main/java/io/grpc/internal/ServerStream_Instrumentation.java @@ -39,6 +39,7 @@ public void close(Status status, Metadata trailers) { if (status != null) { int statusCode = status.getCode().value(); + NewRelic.addCustomParameter("response.status", statusCode); NewRelic.addCustomParameter("http.statusCode", statusCode); NewRelic.addCustomParameter("http.statusText", status.getDescription()); if (GrpcConfig.errorsEnabled && status.getCause() != null) { @@ -68,6 +69,7 @@ public void cancel(Status status) { if (status != null) { int statusCode = status.getCode().value(); + NewRelic.addCustomParameter("response.status", statusCode); NewRelic.addCustomParameter("http.statusCode", statusCode); NewRelic.addCustomParameter("http.statusText", status.getDescription()); if (GrpcConfig.errorsEnabled && status.getCause() != null) { diff --git a/instrumentation/grpc-1.4.0/src/test/java/ValidationHelper.java b/instrumentation/grpc-1.4.0/src/test/java/ValidationHelper.java index fecbc25596..112a362bc7 100644 --- a/instrumentation/grpc-1.4.0/src/test/java/ValidationHelper.java +++ b/instrumentation/grpc-1.4.0/src/test/java/ValidationHelper.java @@ -69,6 +69,7 @@ static void validateGrpcInteraction(TestServer server, String clientTxName, Stri assertTrue(rootSegment.getName().endsWith(fullMethod)); assertEquals(1, rootSegment.getCallCount()); assertEquals(fullMethod, rootSegment.getTracerAttributes().get("request.method")); + assertEquals(0, rootSegment.getTracerAttributes().get("response.status")); assertEquals(0, rootSegment.getTracerAttributes().get("http.statusCode")); assertNull(rootSegment.getTracerAttributes().get("http.statusText")); assertEquals(grpcType, rootSegment.getTracerAttributes().get("grpc.type")); @@ -86,6 +87,7 @@ static void validateGrpcInteraction(TestServer server, String clientTxName, Stri assertEquals(name, serverTxEvent.getAttributes().get("sayHelloAfter")); } + assertEquals(0, serverTxEvent.getAttributes().get("response.status")); assertEquals(0, serverTxEvent.getAttributes().get(AttributeNames.HTTP_STATUS_CODE)); assertEquals("grpc://localhost:" + server.getPort() + "/" + fullMethod, serverTxEvent.getAttributes().get("request.uri")); } @@ -126,6 +128,7 @@ static void validateExceptionGrpcInteraction(TestServer server, String clientTxN assertTrue(rootSegment.getName().endsWith(fullMethod)); assertEquals(1, rootSegment.getCallCount()); assertEquals(fullMethod, rootSegment.getTracerAttributes().get("request.method")); + assertEquals(status, rootSegment.getTracerAttributes().get("response.status")); assertEquals(status, rootSegment.getTracerAttributes().get(AttributeNames.HTTP_STATUS_CODE)); assertEquals(grpcType, rootSegment.getTracerAttributes().get("grpc.type")); @@ -134,6 +137,7 @@ static void validateExceptionGrpcInteraction(TestServer server, String clientTxN assertEquals(1, serverTxEvents.size()); TransactionEvent serverTxEvent = serverTxEvents.iterator().next(); assertNotNull(serverTxEvent); + assertEquals(status, serverTxEvent.getAttributes().get("response.status")); assertEquals(status, serverTxEvent.getAttributes().get(AttributeNames.HTTP_STATUS_CODE)); assertEquals("grpc://localhost:" + server.getPort() + "/" + fullMethod, serverTxEvent.getAttributes().get("request.uri")); } diff --git a/instrumentation/grpc-1.40.0/src/main/java/com/nr/agent/instrumentation/grpc/GrpcUtil.java b/instrumentation/grpc-1.40.0/src/main/java/com/nr/agent/instrumentation/grpc/GrpcUtil.java index c55a2b94a7..2bb214abf3 100644 --- a/instrumentation/grpc-1.40.0/src/main/java/com/nr/agent/instrumentation/grpc/GrpcUtil.java +++ b/instrumentation/grpc-1.40.0/src/main/java/com/nr/agent/instrumentation/grpc/GrpcUtil.java @@ -34,14 +34,14 @@ public static void finalizeTransaction(Token token, Status status, Metadata meta } /** - * Set the http.statusCode attribute and error cause (if applicable) on the transaction + * Set the response.status attribute and error cause (if applicable) on the transaction * when the ServerStream is closed or cancelled. * * @param status The {@link Status} of the completed/cancelled operation */ public static void setServerStreamResponseStatus(Status status) { if (status != null) { - NewRelic.addCustomParameter("http.statusCode", status.getCode().value()); + NewRelic.addCustomParameter("response.status", status.getCode().value()); if (GrpcConfig.errorsEnabled && status.getCause() != null) { // If an error occurred during the close of this server call we should record it NewRelic.noticeError(status.getCause()); diff --git a/instrumentation/grpc-1.40.0/src/test/java/ValidationHelper.java b/instrumentation/grpc-1.40.0/src/test/java/ValidationHelper.java index 024396f030..0fc1ff5eb8 100644 --- a/instrumentation/grpc-1.40.0/src/test/java/ValidationHelper.java +++ b/instrumentation/grpc-1.40.0/src/test/java/ValidationHelper.java @@ -60,6 +60,7 @@ static void validateGrpcInteraction(TestServer server, String clientTxName, Stri assertTrue(rootSegment.getName().endsWith(fullMethod)); assertEquals(1, rootSegment.getCallCount()); assertEquals(fullMethod, rootSegment.getTracerAttributes().get("request.method")); + assertEquals(0, rootSegment.getTracerAttributes().get("response.status")); assertEquals(grpcType, rootSegment.getTracerAttributes().get("grpc.type")); // Custom attributes (to test tracing into customer code) @@ -75,6 +76,7 @@ static void validateGrpcInteraction(TestServer server, String clientTxName, Stri assertEquals(name, serverTxEvent.getAttributes().get("sayHelloAfter")); } + assertEquals(0, serverTxEvent.getAttributes().get("response.status")); assertEquals("grpc://localhost:" + server.getPort() + "/" + fullMethod, serverTxEvent.getAttributes().get("request.uri")); } @@ -114,6 +116,7 @@ static void validateExceptionGrpcInteraction(TestServer server, String clientTxN assertTrue(rootSegment.getName().endsWith(fullMethod)); assertEquals(1, rootSegment.getCallCount()); assertEquals(fullMethod, rootSegment.getTracerAttributes().get("request.method")); + assertEquals(status, rootSegment.getTracerAttributes().get("response.status")); assertEquals(grpcType, rootSegment.getTracerAttributes().get("grpc.type")); // Custom attributes (to test tracing into customer code) @@ -121,6 +124,7 @@ static void validateExceptionGrpcInteraction(TestServer server, String clientTxN assertEquals(1, serverTxEvents.size()); TransactionEvent serverTxEvent = serverTxEvents.iterator().next(); assertNotNull(serverTxEvent); + assertEquals(status, serverTxEvent.getAttributes().get("response.status")); assertEquals("grpc://localhost:" + server.getPort() + "/" + fullMethod, serverTxEvent.getAttributes().get("request.uri")); } diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/attributes/AttributeNames.java b/newrelic-agent/src/main/java/com/newrelic/agent/attributes/AttributeNames.java index 30984d2e0d..a72876b408 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/attributes/AttributeNames.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/attributes/AttributeNames.java @@ -36,6 +36,8 @@ public final class AttributeNames { public static final String HTTP_METHOD = "http.method"; public static final String HTTP_STATUS_CODE = "http.statusCode"; public static final String HTTP_STATUS_TEXT = "http.statusText"; + public static final String HTTP_STATUS = "httpResponseCode"; + public static final String HTTP_STATUS_MESSAGE = "httpResponseMessage"; public static final String LOCK_THREAD_NAME = "jvm.lock_thread_name"; public static final String THREAD_NAME = "jvm.thread_name"; diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/dispatchers/WebRequestDispatcher.java b/newrelic-agent/src/main/java/com/newrelic/agent/dispatchers/WebRequestDispatcher.java index 93d2b2a707..429da22329 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/dispatchers/WebRequestDispatcher.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/dispatchers/WebRequestDispatcher.java @@ -105,11 +105,14 @@ public void transactionActivityWithResponseFinished() { storeResponseContentType(); if (getStatus() > 0) { + // http status is now being recorded as a string + getTransaction().getAgentAttributes().put(AttributeNames.HTTP_STATUS, String.valueOf(getStatus())); // http.statusCode is supposed to be an int getTransaction().getAgentAttributes().put(AttributeNames.HTTP_STATUS_CODE, getStatus()); } if (getStatusMessage() != null) { + getTransaction().getAgentAttributes().put(AttributeNames.HTTP_STATUS_MESSAGE, getStatusMessage()); getTransaction().getAgentAttributes().put(AttributeNames.HTTP_STATUS_TEXT, getStatusMessage()); } diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/service/analytics/SpanEventFactory.java b/newrelic-agent/src/main/java/com/newrelic/agent/service/analytics/SpanEventFactory.java index 7581304fd4..f3c35f3051 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/service/analytics/SpanEventFactory.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/service/analytics/SpanEventFactory.java @@ -231,6 +231,9 @@ public SpanEventFactory setHttpStatusCode(Integer statusCode) { if (filter.shouldIncludeAgentAttribute(appName, AttributeNames.HTTP_STATUS_CODE)) { builder.putAgentAttribute(AttributeNames.HTTP_STATUS_CODE, statusCode); } + if (filter.shouldIncludeAgentAttribute(appName, AttributeNames.HTTP_STATUS)) { + builder.putAgentAttribute(AttributeNames.HTTP_STATUS, statusCode); + } return this; } diff --git a/newrelic-agent/src/test/java/com/newrelic/agent/service/analytics/TracerToSpanEventTest.java b/newrelic-agent/src/test/java/com/newrelic/agent/service/analytics/TracerToSpanEventTest.java index 97dd485597..4870a274b3 100644 --- a/newrelic-agent/src/test/java/com/newrelic/agent/service/analytics/TracerToSpanEventTest.java +++ b/newrelic-agent/src/test/java/com/newrelic/agent/service/analytics/TracerToSpanEventTest.java @@ -36,6 +36,8 @@ import static com.newrelic.agent.MetricNames.QUEUE_TIME; import static com.newrelic.agent.attributes.AttributeNames.HTTP_REQUEST_PREFIX; +import static com.newrelic.agent.attributes.AttributeNames.HTTP_STATUS; +import static com.newrelic.agent.attributes.AttributeNames.HTTP_STATUS_MESSAGE; import static com.newrelic.agent.attributes.AttributeNames.MESSAGE_REQUEST_PREFIX; import static com.newrelic.agent.attributes.AttributeNames.PORT; import static com.newrelic.agent.attributes.AttributeNames.QUEUE_DURATION; @@ -335,10 +337,14 @@ public void testResponseAttributesAddedToRoot() { int httpResponseCode = 404; String httpResponseMessage = "I cannot find that page, silly"; String contentType = "application/vnd.ms-powerpoint "; + expectedAgentAttributes.put("httpResponseCode", httpResponseCode); + expectedAgentAttributes.put("httpResponseMessage", httpResponseMessage); expectedAgentAttributes.put(RESPONSE_CONTENT_TYPE_PARAMETER_NAME, contentType); SpanEvent expectedSpanEvent = buildExpectedSpanEvent(); + transactionAgentAttributes.put(HTTP_STATUS, httpResponseCode); + transactionAgentAttributes.put(HTTP_STATUS_MESSAGE, httpResponseMessage); transactionAgentAttributes.put(RESPONSE_CONTENT_TYPE_PARAMETER_NAME, contentType); when(txnData.getAgentAttributes()).thenReturn(transactionAgentAttributes);