Skip to content

Commit

Permalink
Merge branch 'main' of github.com:newrelic/newrelic-java-agent into s…
Browse files Browse the repository at this point in the history
…axon/replace-otel-spans2
  • Loading branch information
jasonjkeller committed Jan 6, 2025
2 parents c308a60 + 13ad7f1 commit 61bf958
Show file tree
Hide file tree
Showing 208 changed files with 8,687 additions and 634 deletions.
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Dependabot Configuration
#
# This configuration file specifies the settings for Dependabot Scanning.
# It monitors the Gradle dependencies in the specified subproject and runs checks
# on a weekly basis. This will not create pull requests for version updates, but
# can be updated to create pull requests.

version: 2
updates:
- package-ecosystem: "gradle"
directories:
- "/newrelic-agent"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
11 changes: 9 additions & 2 deletions .github/workflows/Test-AITs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ jobs:
echo "server/weblogic.py" >> $excluded_tests
echo "basic_features/inf_tracing_test.py" >> $excluded_tests
echo "security/lasp_msg_params.py" >> $excluded_tests
echo "framework/pekko/pekko.py" >> $excluded_tests
echo "framework/pekko/pekkohttp.py" >> $excluded_tests
# The files below are not tests
echo "trace/client.py" >> $excluded_tests
echo "trace/server.py" >> $excluded_tests
Expand Down Expand Up @@ -179,6 +177,15 @@ jobs:
path: appcache4
lfs: true

- name: Checkout Cache 5
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # pin@v4
with:
repository: newrelic/java-ait-cache-5
ref: ${{ inputs.cache-ref || 'main' }}
token: ${{ secrets.AITPAT }}
path: appcache5
lfs: true

# Consolidate caches into one directory
- name: Consolidate caches into Apps directory
run: |
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/dependency-submission.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
# Purpose: It generates and submits a dependency graph to the GitHub Dependency Submission API. The graph is used to
# trigger Dependabot Alerts for vulnerable dependencies, and to populate the Dependency Graph insights view in GitHub.
#
# Excludes:
# - Test-only dependencies

name: Dependency Submission

Expand Down Expand Up @@ -43,8 +41,8 @@ jobs:
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@d156388eb19639ec20ade50009f3d199ce1e2808 # pin@v4
with:
dependency-graph-exclude-configurations: '.*[Tt]est(Compile|Runtime)Classpath|instrumentation.*'
dependency-graph-include-configurations: '.*(includeInJar|shadowIntoJar).*'
build-scan-publish: true
build-scan-terms-of-use-url: "https://gradle.com/help/legal-terms-of-use"
build-scan-terms-of-use-agree: "yes"
dependency-graph-exclude-projects: ':instrumentation'
dependency-graph-include-configurations: '.*(shadowIntoJar|jarIntoJar)'
98 changes: 85 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,100 @@ Noteworthy changes to the agent are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Version 8.17.0
## New features and improvements

- Add support for jdbc-mariadb 3.0.0 till latest and r2dbc-mariadb 1.1.2 till latest - credit to @dhilpipre - clone of 2142 by @jtduffy in [2146](https://github.com/newrelic/newrelic-java-agent/pull/2146)
- Auto discover AWS account ID in the DynamoDB instrumentation by @meiao in [2148](https://github.com/newrelic/newrelic-java-agent/pull/2148)
- Auto discover AWS account ID in the Lambda sdk instrumentation by @meiao in [2167](https://github.com/newrelic/newrelic-java-agent/pull/2167)
- Support pekko-http on scala 3 for versions 1.0.0 till latest by @kanderson250 in [2163](https://github.com/newrelic/newrelic-java-agent/pull/2163)
- Allow JFR queue size and harvest interval to be configured via agent config by @jtduffy in [2168](https://github.com/newrelic/newrelic-java-agent/pull/2168)
New configs are:
```
jfr:
# The time interval, in seconds, of how often JFR data is sent to New Relic.
# The default is 10 seconds.
harvest_interval: 10
# The size of the queue used to store JFR events. Increasing this can reduce gaps in JFR reported data
# but can also cause resource issues in the agent or cause data to be dropped if backend pipeline
# limits are exceeded.
# See: https://docs.newrelic.com/docs/data-apis/ingest-apis/event-api/introduction-event-api/#limits
# https://docs.newrelic.com/docs/data-apis/ingest-apis/metric-api/metric-api-limits-restricted-attributes/
# Default is 250000
queue_size: 250000
```
- Add AWS Firehose SDK Instrumentation for versions 2.1.0 till latest by @obenkenobi in [2149](https://github.com/newrelic/newrelic-java-agent/pull/2149)
- Implement a new instrumentation module for r2dbc-mysql 1.1.3+ by @jbedell-newrelic in [2169](https://github.com/newrelic/newrelic-java-agent/pull/2169)
- Memory usage reduced for the r2dbc-mssql and m2dbc-mysql modules by @jbedell-newrelic in [2169](https://github.com/newrelic/newrelic-java-agent/pull/2169)
- Log when multiple, different, traceparent headers found on inbound request and only report `invalid parent header count` supportability metric when that scenario occurs by @jtduffy in [2154](https://github.com/newrelic/newrelic-java-agent/pull/2154)
- Expected NPE in noticeTracer no longer logs full stack trace by @jasonjkeller in [2143](https://github.com/newrelic/newrelic-java-agent/pull/2143)

## Fixes

- Resolved a potential token timeout issue with the reactor-3.3.0 module by @jbedell-newrelic in [2169](https://github.com/newrelic/newrelic-java-agent/pull/2169)

## IAST

- CSEC version bump to 1.6.0 [2173](https://github.com/newrelic/newrelic-java-agent/pull/2173)
- Changelog: https://github.com/newrelic/csec-java-agent/releases/tag/1.6.0


## Version 8.16.0
## New features and improvements

- Obfuscate JVM properties [2114](https://github.com/newrelic/newrelic-java-agent/pull/2114)
The Java agent will now obfuscate values passed to JVM properties. For example: `-Dprop=12345` will now be sent as `-Dprop=obfuscated`. The [documentation](https://docs.newrelic.com/docs/apm/agents/java-agent/configuration/java-agent-configuration-config-file/#jvm-properties-obfuscation) has information on how to disable obfuscation and how to add exceptions.

- Cloud API [2081](https://github.com/newrelic/newrelic-java-agent/pull/2081)
The Cloud API allows cloud provider account information to be provided to the agent. This will allow the agent to populate the `cloud.resource_id` attribute in calls to select cloud services.
The [API documentation](https://docs.newrelic.com/docs/apm/agents/java-agent/api-guides/guide-using-java-agent-api/#additional) has information on how to use it programmatically.
This information can also be provided using a [configuration option](https://docs.newrelic.com/docs/apm/agents/java-agent/configuration/java-agent-configuration-config-file/#aws-account_id).

- Support distributed tracing for Kafka Stream 3.7.x [2095](https://github.com/newrelic/newrelic-java-agent/pull/2095)
- Report if agent was installed via Azure site extension [2094](https://github.com/newrelic/newrelic-java-agent/pull/2094)
- Lazy initialization of GUIDs on DefaultTracers [2088](https://github.com/newrelic/newrelic-java-agent/pull/2088)
- Java HttpClient: Addition of status code to reported externals [2089](https://github.com/newrelic/newrelic-java-agent/pull/2089)
- AWS Lambda: populate `cloud.resource_id` using data from Cloud API [2115](https://github.com/newrelic/newrelic-java-agent/pull/2115)
- Kinesis Data Streams: populate `cloud.resource_id` [2112](https://github.com/newrelic/newrelic-java-agent/pull/2112)
- DynamoDB: populate `cloud.resource_id` [2113](https://github.com/newrelic/newrelic-java-agent/pull/2113)

## Fixes

- Use recordResponseTimeMetric instead of recordMetric [2128](https://github.com/newrelic/newrelic-java-agent/pull/2128)
- Use WeakReference HttpUrlConnection instrumentation [2082](https://github.com/newrelic/newrelic-java-agent/pull/2082)
- Fix a bug where Jetty 12 would not properly link distributed traces [2140](https://github.com/newrelic/newrelic-java-agent/pull/2140)
- Update to JFR daemon 1.13.0 [2129](https://github.com/newrelic/newrelic-java-agent/pull/2129)
This update changes the HTTP client used, which caused problems with some proxies.

## IAST

- CSEC version bump to 1.5.1 [2076](https://github.com/newrelic/newrelic-java-agent/pull/2076)
- Changelog: https://github.com/newrelic/csec-java-agent/releases/tag/1.5.1


## Version 8.15.0
## New features and improvements

- Addition of AWS Lambda SDK instrumentation by @meiao in [1998](https://github.com/newrelic/newrelic-java-agent/pull/1998)
- Reporting of Flyway migration events by @jtduffy in [2021](https://github.com/newrelic/newrelic-java-agent/pull/2021)
- Add support for using an environment variable for config file location by @jtduffy in [2022](https://github.com/newrelic/newrelic-java-agent/pull/2022)
- Support AWS Kinesis V1 and V2 SDKs by @obenkenobi in [2031](https://github.com/newrelic/newrelic-java-agent/pull/2031)
- Addition of kafka-clients-node-metrics-3.7.0 Instrumentation module by @deleonenriqueta in [2039](https://github.com/newrelic/newrelic-java-agent/pull/2039)
- Add instrumentation for glassfish-jul-extension logging library by @jasonjkeller in [2049](https://github.com/newrelic/newrelic-java-agent/pull/2049)
- Java 23 support by @jasonjkeller in [2055](https://github.com/newrelic/newrelic-java-agent/pull/2055)
- Support reporting of ECS Fargate Docker ids by @jtduffy in [2050](https://github.com/newrelic/newrelic-java-agent/pull/2050)
- Actuator endpoint transaction naming for Spring Boot 3 by @jtduffy in [2077](https://github.com/newrelic/newrelic-java-agent/pull/2077)
- Addition of AWS Lambda SDK instrumentation [1998](https://github.com/newrelic/newrelic-java-agent/pull/1998)
- Reporting of Flyway migration events [2021](https://github.com/newrelic/newrelic-java-agent/pull/2021)
- Add support for using an environment variable for config file location [2022](https://github.com/newrelic/newrelic-java-agent/pull/2022)
- Support AWS Kinesis V1 and V2 SDKs [2031](https://github.com/newrelic/newrelic-java-agent/pull/2031)
- Addition of kafka-clients-node-metrics-3.7.0 Instrumentation module [2039](https://github.com/newrelic/newrelic-java-agent/pull/2039)
- Add instrumentation for glassfish-jul-extension logging library [2049](https://github.com/newrelic/newrelic-java-agent/pull/2049)
- Java 23 support [2055](https://github.com/newrelic/newrelic-java-agent/pull/2055)
- Support reporting of ECS Fargate Docker ids [2050](https://github.com/newrelic/newrelic-java-agent/pull/2050)
- Actuator endpoint transaction naming for Spring Boot 3 [2077](https://github.com/newrelic/newrelic-java-agent/pull/2077)

## Fixes

- Slick 3.5.0 instrumentation bug fix by @kanderson250 in [2025](https://github.com/newrelic/newrelic-java-agent/pull/2025)
- Protect against Http2Headers methods throwing exceptions in Netty instrumentation by @jasonjkeller in [2042](https://github.com/newrelic/newrelic-java-agent/pull/2042)
- Fix an issue where the Kinesis instrumentation is generating ERROR logs due to a NullPointerException by @obenkenobi in [2052](https://github.com/newrelic/newrelic-java-agent/pull/2052)
- Slick 3.5.0 instrumentation bug fix [2025](https://github.com/newrelic/newrelic-java-agent/pull/2025)
- Protect against Http2Headers methods throwing exceptions in Netty instrumentation [2042](https://github.com/newrelic/newrelic-java-agent/pull/2042)
- Fix an issue where the Kinesis instrumentation is generating ERROR logs due to a NullPointerException [2052](https://github.com/newrelic/newrelic-java-agent/pull/2052)

## IAST

- CSEC version bump to 1.5 by @jtduffy in [2076](https://github.com/newrelic/newrelic-java-agent/pull/2076)
- CSEC version bump to 1.5 [2076](https://github.com/newrelic/newrelic-java-agent/pull/2076)
- Changelog: https://github.com/newrelic/csec-java-agent/releases/tag/1.5.0

## Version 8.14.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ public interface CloudApi extends Cloud {
* If no data was recorded for the SDK client, the general account information will be returned.
*/
String getAccountInfo(Object sdkClient, CloudAccountInfo cloudAccountInfo);

/**
* Decode the account id from the given access key.
* This method becomes a noop and always returns null if the config "cloud.aws.account_decoding" is set to false.
*/
String decodeAwsAccountId(String accessKey);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

/**
* This implementation of {@link CollectionFactory} will only be used if the agent-bridge
* is being used by an application and the agent is NOT being loaded. Thus, it is unlikely
* that the objects created by this implementation are going to receive much use.
* So methods in this implementation do not need to implement all functional requirements
* of the methods in the interface, but they should not break under low use.
*/
public class DefaultCollectionFactory implements CollectionFactory {

@Override
public <K, V> Map<K, V> createConcurrentWeakKeyedMap() {
return Collections.synchronizedMap(new WeakHashMap<K, V>());
return Collections.synchronizedMap(new WeakHashMap<>());
}

/**
Expand All @@ -36,12 +43,14 @@ public <K, V> Map<K, V> createConcurrentTimeBasedEvictionMap(long ageInSeconds)
@Override
public <K, V> Function<K, V> memorize(Function<K, V> loader, int maxSize) {
Map<K, V> map = new ConcurrentHashMap<>();
return k -> map.computeIfAbsent(k, k1 -> {

return k -> {
if (map.size() >= maxSize) {
map.remove(map.keySet().iterator().next());
V value = map.get(k);
return value == null ? loader.apply(k) : value;
}
return loader.apply(k1);
});
return map.computeIfAbsent(k, loader);
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ public String getAccountInfo(CloudAccountInfo cloudAccountInfo) {
public String getAccountInfo(Object sdkClient, CloudAccountInfo cloudAccountInfo) {
return null;
}

@Override
public String decodeAwsAccountId(String accessKey) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
*
* * Copyright 2024 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/

package com.newrelic.agent.bridge;

import org.junit.Test;
import org.mockito.Mockito;

import java.util.Map;
import java.util.function.Function;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
* This implementation of {@link CollectionFactory} is not really meant to be used.
* It is only implemented in case the agent-bridge is used without the agent, which is an unsupported use case.
*
* Therefore, the implementation does not keep the contract from the interface, but returns functional objects
* so the application will still run.
*/
public class DefaultCollectionFactoryTest {

@Test
public void createConcurrentWeakKeyedMap() {
Map<Object, Object> concurrentWeakKeyedMap = new DefaultCollectionFactory().createConcurrentWeakKeyedMap();
assertThat(concurrentWeakKeyedMap, instanceOf(Map.class));
}

@Test
public void createConcurrentTimeBasedEvictionMap() {
Map<Object, Object> concurrentTimeBasedEvictionMap = new DefaultCollectionFactory().createConcurrentTimeBasedEvictionMap(1L);
assertThat(concurrentTimeBasedEvictionMap, instanceOf(Map.class));
}

@Test
public void memorize() {
Function<Object, Object> f = mock(Function.class);
when(f.apply("1")).thenReturn("1");
when(f.apply("2")).thenReturn("2");
Function<Object, Object> cache = new DefaultCollectionFactory().memorize(f, 1);
cache.apply("1");
cache.apply("1");
cache.apply("2");
cache.apply("2");

// the first call should have been cached, so the function should only have been called once
Mockito.verify(f, Mockito.times(1)).apply("1");
// max cache size is 1, so second call should not be cached
Mockito.verify(f, Mockito.times(2)).apply("2");
}

@Test
public void createAccessTimeBasedCache() {
Function<Object, Object> accessTimeBasedCache = new DefaultCollectionFactory().createAccessTimeBasedCache(1L, 1, k -> k);
assertThat(accessTimeBasedCache, instanceOf(Function.class));
}
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The agent version.
agentVersion=8.16.0
securityAgentVersion=1.5.1
agentVersion=8.18.0
securityAgentVersion=1.6.0

newrelicDebug=false
org.gradle.jvmargs=-Xmx2048m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import com.newrelic.agent.InstrumentationProxy;
import com.newrelic.agent.core.CoreService;
import com.newrelic.agent.service.AbstractService;
import com.newrelic.agent.superagent.HealthDataChangeListener;
import com.newrelic.agent.superagent.HealthDataProducer;
import com.newrelic.agent.agentcontrol.HealthDataChangeListener;
import com.newrelic.agent.agentcontrol.HealthDataProducer;

class IntrospectorCoreService extends AbstractService implements CoreService, HealthDataProducer {
private InstrumentationProxy instrumentation = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.newrelic.agent.service.module.JarData;
import com.newrelic.agent.sql.SqlTrace;
import com.newrelic.agent.stats.StatsEngine;
import com.newrelic.agent.superagent.HealthDataProducer;
import com.newrelic.agent.agentcontrol.HealthDataProducer;
import com.newrelic.agent.trace.TransactionTrace;
import com.newrelic.agent.transaction.TransactionNamingScheme;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.apache.logging.log4j.core.LogEvent;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.newrelic.agent.bridge.logging.AppLoggingUtils.BLOB_PREFIX;
import static com.newrelic.agent.bridge.logging.AppLoggingUtils.getLinkingMetadataBlob;
Expand All @@ -18,6 +20,8 @@
import static com.newrelic.agent.bridge.logging.AppLoggingUtils.isApplicationLoggingLocalDecoratingEnabled;

public class AgentUtils {
private static final Pattern JSON_MESSAGE_VALUE_END = Pattern.compile("\"message\".+?[^\\\\]((\",)|(\"}))");

/**
* Checks pretty or compact JSON layout strings for a series of characters and returns the index of
* the characters or -1 if they were not found. This is used to find the log "message" substring
Expand All @@ -27,17 +31,14 @@ public class AgentUtils {
* @return positive int if index was found, else -1
*/
public static int getIndexToModifyJson(String writerString) {
int msgIndex = writerString.indexOf("message");
if (msgIndex < 0) {
return msgIndex;
}
// If the "message" field is before other fields in the json string
int index = writerString.indexOf("\",", msgIndex);
int index = -1;
Matcher matcher = JSON_MESSAGE_VALUE_END.matcher(writerString);

if (index < 0 ) {
// If "message" is the last field in the json string
index = writerString.indexOf("\"}", msgIndex);
if (matcher.find()) {
// Group 1 in the match is the ", char sequence
index = matcher.start(1);
}

return index;
}

Expand Down
Loading

0 comments on commit 61bf958

Please sign in to comment.