newrelic / newrelic-java-agent

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

AWS MQ span attributes #1977

Closed obenkenobi closed 3 months ago

obenkenobi commented 3 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. In addition, otel compatible attributes are also added (some are experimental) for routing keys and queues for RabbitMQ.

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 3 months ago

Codecov Report

Attention: Patch coverage is 37.93103% with 36 lines in your changes missing coverage. Please review.

Project coverage is 70.61%. Comparing base (85e2eea) to head (a7c7b9b). Report is 11 commits behind head on main.

Files Patch % Lines
...java/com/newrelic/agent/tracers/DefaultTracer.java 0.00% 10 Missing :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:
...ewrelic/agent/bridge/DefaultCollectionFactory.java 0.00% 5 Missing :warning:
...om/newrelic/agent/util/AgentCollectionFactory.java 0.00% 5 Missing :warning:
...newrelic/agent/bridge/messaging/JmsProperties.java 0.00% 1 Missing :warning:
...elic/agent/service/analytics/SpanEventFactory.java 94.11% 0 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1977 +/- ## ========================================= Coverage 70.61% 70.61% - Complexity 9860 9873 +13 ========================================= Files 827 829 +2 Lines 39857 39914 +57 Branches 6068 6077 +9 ========================================= + Hits 28144 28185 +41 - Misses 8983 8999 +16 Partials 2730 2730 ```

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