Skip to content

Commit

Permalink
Revert "NEWRELIC-4831 Clean up deprecated attributes (#1125)"
Browse files Browse the repository at this point in the history
This reverts commit 4e36bc5.
  • Loading branch information
meiao committed Dec 14, 2023
1 parent 2cbec36 commit 62e2ba9
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ private void assertResponseCodeOnTxEvents(Collection<TransactionEvent> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ private void assertResponseCodeOnTxEvents(Collection<TransactionEvent> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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"));
}
Expand Down Expand Up @@ -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"));

Expand All @@ -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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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"));
}
Expand Down Expand Up @@ -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"));

Expand All @@ -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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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"));
}
Expand Down Expand Up @@ -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"));

Expand All @@ -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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"));
}

Expand Down Expand Up @@ -114,13 +116,15 @@ 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)
Collection<TransactionEvent> serverTxEvents = introspector.getTransactionEvents(serverTxName);
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"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 62e2ba9

Please sign in to comment.