Skip to content

Commit 281ff6b

Browse files
committed
Brute force remove NR shadowed dependencies from spring resource scanning
1 parent 8cc5d6c commit 281ff6b

5 files changed

Lines changed: 90 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
dependencies {
2+
implementation(project(":agent-bridge"))
3+
implementation("org.springframework:spring-core:3.0.0.RELEASE")
4+
}
5+
6+
jar {
7+
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.spring-resource-path' }
8+
}
9+
10+
verifyInstrumentation {
11+
passes 'org.springframework:spring-core:[3.0.0.RELEASE,)'
12+
excludeRegex 'org.springframework:spring-core:.*(RC|SEC|M)[0-9]*$'
13+
}
14+
15+
//This should not go into the site as it is a utility module, rather than an instrumented framework.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.nr.agent.instrumentation;
2+
3+
import org.springframework.core.io.Resource;
4+
5+
import java.util.Arrays;
6+
7+
public class Utils {
8+
private static final String NR_SHADOWED_DEPENDENCIES_URL_PREFIX = "com/newrelic/agent/deps";
9+
10+
/**
11+
* Filters out New Relic agent shadowed dependency resources from the given resource array.
12+
* This forces New Relic agent shadowed dependencies to become undiscoverable by Spring.
13+
*
14+
* @param resources the array of resources to filter, may be null
15+
* @return a new array excluding resources that match the shadowed dependencies pattern,
16+
* or the original array if it was null
17+
*/
18+
public static Resource[] excludeNRShadowedDependencies(Resource[] resources) {
19+
if (resources == null) {
20+
return null;
21+
}
22+
return Arrays.stream(resources)
23+
.filter(resource -> !isShadowedDependency(resource))
24+
.toArray(Resource[]::new);
25+
}
26+
27+
private static boolean isShadowedDependency(Resource resource) {
28+
return resource.getDescription().contains(NR_SHADOWED_DEPENDENCIES_URL_PREFIX);
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
*
3+
* * Copyright 2026 New Relic Corporation. All rights reserved.
4+
* * SPDX-License-Identifier: Apache-2.0
5+
*
6+
*/
7+
package org.springframework.core.io.support;
8+
9+
import com.newrelic.api.agent.Trace;
10+
import com.newrelic.api.agent.weaver.MatchType;
11+
import com.newrelic.api.agent.weaver.Weave;
12+
import com.newrelic.api.agent.weaver.Weaver;
13+
import com.nr.agent.instrumentation.Utils;
14+
import org.springframework.core.io.Resource;
15+
16+
import java.io.IOException;
17+
18+
@Weave(type = MatchType.Interface, originalName = "org.springframework.core.io.support.ResourcePatternResolver")
19+
public class ResourcePatternResolver_Instrumentation {
20+
21+
public Resource[] getResources(String locationPattern) throws IOException {
22+
return Utils.excludeNRShadowedDependencies(Weaver.callOriginal());
23+
}
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.nr.agent.instrumentation;
2+
3+
import org.junit.Test;
4+
import org.springframework.core.io.Resource;
5+
6+
import java.io.File;
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
import java.net.URI;
10+
import java.net.URL;
11+
12+
import static org.junit.Assert.*;
13+
14+
public class UtilsTest {
15+
16+
@Test
17+
public void testExcludeNRShadowedDependencies() throws IOException {
18+
//TODO
19+
}
20+
}

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ include 'instrumentation:spring-handler-method-invoker-3.0.0'
422422
include 'instrumentation:spring-jms-2'
423423
include 'instrumentation:spring-jms-3'
424424
include 'instrumentation:spring-kafka-2.2.0'
425+
include 'instrumentation:spring-resource-path'
425426
include 'instrumentation:spring-resttemplate-6.0.0'
426427
include 'instrumentation:spring-webclient-5.0'
427428
include 'instrumentation:spring-webclient-6.0'

0 commit comments

Comments
 (0)