Skip to content

Commit

Permalink
Merge pull request #70 from newrelic/addCustomParameter_boolean_api
Browse files Browse the repository at this point in the history
Fixes #69 by adding addCustomParameter(String, Boolean) api
  • Loading branch information
tspring authored Sep 22, 2020
2 parents 1e5fe34 + c224d2a commit ea17334
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public void addCustomParameter(String key, String value) {

}

@Override
public void addCustomParameter(String key, boolean value) {

}

@Override
public void addCustomParameters(Map<String, Object> params) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ public interface PublicApi {
*/
void addCustomParameter(String key, String value);

/**
* Add a key/value pair to the current transaction. These are reported in errors and transaction traces.
*
* @param key Custom parameter key.
* @param value Custom parameter value.
*/
void addCustomParameter(String key, boolean value);

/**
* Add key/value pairs to the current transaction. These are reported in errors and transaction traces.
*
Expand Down
14 changes: 12 additions & 2 deletions agent-bridge/src/main/java/com/newrelic/api/agent/NewRelic.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public static void noticeError(String message, boolean expected) {
* Add a key/value pair to the current transaction. These are reported in errors and transaction traces.
*
* @param key Custom parameter key.
* @param value Custom parameter value. @
* @param value Custom parameter value.
*/
public static void addCustomParameter(String key, Number value) {
AgentBridge.publicApi.addCustomParameter(key, value);
Expand All @@ -193,12 +193,22 @@ public static void addCustomParameter(String key, Number value) {
* Add a key/value pair to the current transaction. These are reported in errors and transaction traces.
*
* @param key Custom parameter key.
* @param value Custom parameter value. @
* @param value Custom parameter value.
*/
public static void addCustomParameter(String key, String value) {
AgentBridge.publicApi.addCustomParameter(key, value);
}

/**
* Add a key/value pair to the current transaction. These are reported in errors and transaction traces.
*
* @param key Custom parameter key.
* @param value Custom parameter value.
*/
public static void addCustomParameter(String key, boolean value) {
AgentBridge.publicApi.addCustomParameter(key, value);
}

/**
* Add a key/value pairs to the current transaction. These are reported in errors and transaction traces.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,21 @@ private void runTestAddCustomStringParameterOverLimit() {
Assert.assertNull(Transaction.getTransaction().getUserAttributes().get("str"));
}

@Test
public void testAddCustomBoolParameter() {
try {
runTestAddCustomBoolParameter();
} finally {
Transaction.clearTransaction();
}
}

@Trace(dispatcher = true)
private void runTestAddCustomBoolParameter() {
NewRelic.addCustomParameter("bool", true);
Assert.assertEquals(true, Transaction.getTransaction().getUserAttributes().get("bool"));
}

@Test
public void testIgnoreApdexNotSet() {
Transaction tx = Transaction.getTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private static int getNumberOfErrorAttsLeft() {
* Add a key/value pair to the current transaction. These are reported in errors and transaction traces.
*
* @param key
* @param value @
* @param value
*/
@Override
public void addCustomParameter(String key, String value) {
Expand All @@ -230,13 +230,24 @@ public void addCustomParameter(String key, String value) {
* Add a key/value pair to the current transaction. These are reported in errors and transaction traces.
*
* @param key
* @param value @
* @param value
*/
@Override
public void addCustomParameter(String key, Number value) {
attributeSender.addAttribute(key, value, "addCustomParameter");
}

/**
* Add a key/value pair to the current transaction. These are reported in errors and transaction traces.
*
* @param key
* @param value
*/
@Override
public void addCustomParameter(String key, boolean value) {
attributeSender.addAttribute(key, value, "addCustomParameter");
}

/**
* Add key/value pairs to the current transaction. These are reported in errors and transaction traces.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void testCustomAttributesInTransaction() {
impl.addCustomParameter("abc.thread", "1");
impl.addCustomParameter("request.many", "1");
impl.addCustomParameter("message.many", "1");
impl.addCustomParameter("message.bool", true);

Map<String, Object> customParamMap = new HashMap<>();
customParamMap.put("key1", "val1");
Expand All @@ -92,7 +93,7 @@ public void testCustomAttributesInTransaction() {
customParamMap.put("key5", null);
impl.addCustomParameters(customParamMap);

Set<String> expected = Sets.newHashSet("abc.thread", "request.many", "message.many", "key1", "key2", "key4");
Set<String> expected = Sets.newHashSet("abc.thread", "request.many", "message.many", "key1", "key2", "key4", "message.bool");

verifyOutput(t.getUserAttributes(), expected);

Expand Down
15 changes: 15 additions & 0 deletions newrelic-api/src/main/java/com/newrelic/api/agent/NewRelic.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,21 @@ public static void addCustomParameter(String key, Number value) {
public static void addCustomParameter(String key, String value) {
}

/**
* Add a key/value pair to the current transaction. These are reported in errors, transaction traces, and
* transaction events. The key and value will only be reported if this call is made within a New Relic transaction.
* <p>
* <b>Note:</b> The key and value pair will only be reported if the key argument can be represented in 255 bytes
* when encoded with UTF-8 encoding.
* </p>
*
* @param key Custom parameter key.
* @param value Custom parameter value.
* @since 6.1.0
*/
public static void addCustomParameter(String key, boolean value) {
}

/**
* Add key/value pairs to the current transaction. These are reported in errors, transaction traces, and
* transaction events. The key and value will only be reported if this call is made within a New Relic transaction.
Expand Down

0 comments on commit ea17334

Please sign in to comment.