newrelic / newrelic-java-agent

The New Relic Java agent
Apache License 2.0
202 stars 143 forks source link

Linking AWS MQ infrastructure entities #1898

Closed obenkenobi closed 3 months ago

obenkenobi commented 5 months ago

Overview

This PR uses the changes from the DynamoDB PR. Merge the DynamoDB PR first before merging this PR.

This PR adds new span attributes containing endpoint information from a message broker. This is so the Java Agent can properly link with infrastructure entities generated from AWS MQ.

The new span attributes are the following:

The externals API has new optional parameters to add host and port for message broker spans, via the method instance(host,port).

For example

ExternalParameters messageProduceParameters = MessageProduceParameters
    .library("JMS")
    .destinationType(DestinationType.NAMED_QUEUE)
    .destinationName("MessageQueue")
    .outboundHeaders(outboundMessageHeaders)
    .instance("localhost", 8088)
    .build();
NewRelic.getAgent().getTracedMethod().reportAsExternal(messageProduceParameters);

ExternalParameters messageConsumeParameters = MessageConsumeParameters
    .library("JMS")
    .destinationType(DestinationType.NAMED_TOPIC)
    .destinationName("MessageTopic")
    .inboundHeaders(inboundMessageHeaders)
    .instance("localhost", 8088)
    .build();
NewRelic.getAgent().getTracedMethod().reportAsExternal(messageConsumeParameters);

Our JMS (if ActiveMQ is used) and RabbitMQ instrumentation automatically add the span attributes.

To get host and port from ActiveMQ, a new instrumentation module was added called activemq-client-5.8.0

On top of that, therabbit-amqp and jms instrumentation was altered to automatically include host and port span attributes.

For our RabbitMQ instrumentation, the existing agent attributes message.routingKey and message.queueName are also added to spans.

In addition the instrumentation was revised so instrumentation module names better match the versions they apply to and to allow host and port information to be reported.

Related Github Issue

https://github.com/newrelic/newrelic-java-agent/issues/1876 https://github.com/newrelic/newrelic-java-agent/issues/1832

codecov-commenter commented 5 months ago

Codecov Report

Attention: Patch coverage is 60.19417% with 41 lines in your changes missing coverage. Please review.

Project coverage is 69.76%. Comparing base (464aa44) to head (cae16b6). Report is 423 commits behind head on main.

Files Patch % Lines
...java/com/newrelic/agent/tracers/DefaultTracer.java 30.43% 15 Missing and 1 partial :warning:
...ewrelic/agent/bridge/messaging/BrokerInstance.java 0.00% 7 Missing :warning:
...ava/com/newrelic/agent/tracers/AbstractTracer.java 36.36% 5 Missing and 2 partials :warning:
...om/newrelic/agent/util/AgentCollectionFactory.java 0.00% 5 Missing :warning:
...ewrelic/agent/bridge/DefaultCollectionFactory.java 60.00% 1 Missing and 1 partial :warning:
...n/java/com/newrelic/agent/util/AwsAccountUtil.java 90.47% 0 Missing and 2 partials :warning:
...newrelic/agent/bridge/messaging/JmsProperties.java 0.00% 1 Missing :warning:
...elic/agent/service/analytics/SpanEventFactory.java 96.42% 0 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1898 +/- ## ============================================ - Coverage 70.68% 69.76% -0.92% + Complexity 9861 9775 -86 ============================================ Files 826 829 +3 Lines 39792 39882 +90 Branches 6061 6078 +17 ============================================ - Hits 28127 27824 -303 - Misses 8946 9370 +424 + Partials 2719 2688 -31 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

obenkenobi commented 3 months ago

aws-mq-rebased is where the MQ changes are pulled to to prevent pollution from dynamo db changes