-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1977 from newrelic/aws-mq-rebased
AWS MQ span attributes
- Loading branch information
Showing
77 changed files
with
2,665 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
agent-bridge/src/main/java/com/newrelic/agent/bridge/messaging/BrokerInstance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* | ||
* * Copyright 2024 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
package com.newrelic.agent.bridge.messaging; | ||
|
||
public class BrokerInstance { | ||
private final String hostName; | ||
private final Integer port; | ||
|
||
public static BrokerInstance empty() { | ||
return new BrokerInstance(null, null); | ||
} | ||
|
||
public BrokerInstance(String host, Integer port) { | ||
this.hostName = host; | ||
this.port = port; | ||
} | ||
|
||
public String getHostName() { | ||
return hostName; | ||
} | ||
|
||
public Integer getPort() { | ||
return port; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
agent-bridge/src/main/java/com/newrelic/agent/bridge/messaging/JmsProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* | ||
* * Copyright 2024 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
package com.newrelic.agent.bridge.messaging; | ||
|
||
public class JmsProperties { | ||
public static final String NR_JMS_BROKER_INSTANCE_PROPERTY = "NR_JMS_BROKER_INSTANCE_PROPERTY"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
dependencies { | ||
implementation(project(":agent-bridge")) | ||
implementation("org.apache.activemq:activemq-client:5.16.7") | ||
testImplementation("org.slf4j:slf4j-simple:1.7.30") | ||
} | ||
|
||
|
||
jar { | ||
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.activemq-client-5.8.0' } | ||
} | ||
|
||
|
||
verifyInstrumentation { | ||
passesOnly 'org.apache.activemq:activemq-client:[5.8.0,)' | ||
} | ||
|
||
|
||
site { | ||
title 'ActiveMQClient' | ||
type 'Messaging' | ||
} |
57 changes: 57 additions & 0 deletions
57
...ient-5.8.0/src/main/java/com/nr/agent/instrumentation/activemqclient580/ActiveMQUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* | ||
* * Copyright 2024 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
package com.nr.agent.instrumentation.activemqclient580; | ||
|
||
import com.newrelic.agent.bridge.AgentBridge; | ||
import com.newrelic.agent.bridge.messaging.BrokerInstance; | ||
|
||
import java.util.function.Function; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class ActiveMQUtil { | ||
|
||
private static final ActiveMQUtil INSTANCE = ActiveMQUtil.create(); | ||
|
||
public static ActiveMQUtil get() { | ||
return INSTANCE; | ||
} | ||
|
||
private static final Pattern ADDRESS_PATTERN = Pattern.compile("^\\w+://(.+)/.+:(\\d+)"); | ||
private final Function<String, BrokerInstance> DO_PARSE_HOST_REF = this::doParseHostAndPort; | ||
private final Function<String, BrokerInstance> CACHE = AgentBridge.collectionFactory.memorize(DO_PARSE_HOST_REF, 32); | ||
|
||
public BrokerInstance parseHostAndPort(String address) { | ||
return CACHE.apply(address); | ||
} | ||
public BrokerInstance doParseHostAndPort(String address) { | ||
|
||
Matcher m = ADDRESS_PATTERN.matcher(address); | ||
if(!m.find()) { | ||
return BrokerInstance.empty(); | ||
} | ||
|
||
String hostName = m.group(1); | ||
int port; | ||
|
||
try { | ||
String portStr = m.group(2); | ||
port = Integer.parseInt(portStr); | ||
} catch (NumberFormatException e) { | ||
return BrokerInstance.empty(); | ||
} | ||
return new BrokerInstance(hostName, port); | ||
} | ||
|
||
private ActiveMQUtil() { | ||
// prevent instantiation of utility class | ||
} | ||
|
||
private static ActiveMQUtil create() { | ||
return new ActiveMQUtil(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ient-5.8.0/src/main/java/org/apache/activemq/command/ActiveMQMessage_Instrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* | ||
* * Copyright 2024 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
package org.apache.activemq.command; | ||
|
||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
import com.nr.agent.instrumentation.activemqclient580.ActiveMQUtil; | ||
import org.apache.activemq.ActiveMQConnection; | ||
|
||
import static com.newrelic.agent.bridge.messaging.JmsProperties.NR_JMS_BROKER_INSTANCE_PROPERTY; | ||
|
||
@Weave(type = MatchType.BaseClass, originalName = "org.apache.activemq.command.ActiveMQMessage") | ||
public abstract class ActiveMQMessage_Instrumentation { | ||
public abstract ActiveMQConnection getConnection(); | ||
|
||
// This is so the JMS instrumentation can grab host and port of the Active MQ instance | ||
public Object getObjectProperty(String name) { | ||
if (NR_JMS_BROKER_INSTANCE_PROPERTY.equals(name)) { | ||
return ActiveMQUtil.get().parseHostAndPort(getConnection().getTransport().toString()); | ||
} | ||
return Weaver.callOriginal(); | ||
} | ||
} |
Oops, something went wrong.