7
7
8
8
import io .opentelemetry .instrumentation .api .caching .Cache ;
9
9
import io .opentelemetry .javaagent .bootstrap .HelperResources ;
10
+ import io .opentelemetry .javaagent .tooling .muzzle .HelperResource ;
10
11
import java .io .File ;
11
12
import java .io .IOException ;
12
13
import java .lang .instrument .Instrumentation ;
@@ -63,7 +64,7 @@ public String toString() {
63
64
private final String requestingName ;
64
65
65
66
private final Set <String > helperClassNames ;
66
- private final Map < String , String > helperResourcePathMappings ;
67
+ private final List < HelperResource > helperResources ;
67
68
@ Nullable private final ClassLoader helpersSource ;
68
69
@ Nullable private final Instrumentation instrumentation ;
69
70
private final Map <String , byte []> dynamicTypeMap = new LinkedHashMap <>();
@@ -87,14 +88,14 @@ public String toString() {
87
88
public HelperInjector (
88
89
String requestingName ,
89
90
List <String > helperClassNames ,
90
- Map < String , String > helperResourcePathMappings ,
91
+ List < HelperResource > helperResources ,
91
92
// TODO can this be replaced with the context classloader?
92
93
ClassLoader helpersSource ,
93
94
Instrumentation instrumentation ) {
94
95
this .requestingName = requestingName ;
95
96
96
97
this .helperClassNames = new LinkedHashSet <>(helperClassNames );
97
- this .helperResourcePathMappings = helperResourcePathMappings ;
98
+ this .helperResources = helperResources ;
98
99
this .helpersSource = helpersSource ;
99
100
this .instrumentation = instrumentation ;
100
101
}
@@ -106,7 +107,7 @@ private HelperInjector(
106
107
this .helperClassNames = helperMap .keySet ();
107
108
this .dynamicTypeMap .putAll (helperMap );
108
109
109
- this .helperResourcePathMappings = Collections .emptyMap ();
110
+ this .helperResources = Collections .emptyList ();
110
111
this .helpersSource = null ;
111
112
this .instrumentation = instrumentation ;
112
113
}
@@ -149,19 +150,20 @@ public DynamicType.Builder<?> transform(
149
150
classLoader = injectHelperClasses (typeDescription , classLoader , module );
150
151
}
151
152
152
- if (helpersSource != null && !helperResourcePathMappings .isEmpty ()) {
153
- for (Map .Entry <String , String > entry : helperResourcePathMappings .entrySet ()) {
154
- String agentResourcePath = entry .getValue ();
155
- String applicationResourcePath = entry .getKey ();
156
- URL resource = helpersSource .getResource (agentResourcePath );
153
+ if (helpersSource != null && !helperResources .isEmpty ()) {
154
+ for (HelperResource helperResource : helperResources ) {
155
+ URL resource = helpersSource .getResource (helperResource .getAgentPath ());
157
156
if (resource == null ) {
158
- logger .debug ("Helper resource {} requested but not found." , agentResourcePath );
157
+ logger .debug (
158
+ "Helper resource {} requested but not found." , helperResource .getAgentPath ());
159
159
continue ;
160
160
}
161
161
162
162
logger .debug (
163
- "Injecting resource onto classloader {} -> {}" , classLoader , applicationResourcePath );
164
- HelperResources .register (classLoader , applicationResourcePath , resource );
163
+ "Injecting resource onto classloader {} -> {}" ,
164
+ classLoader ,
165
+ helperResource .getApplicationPath ());
166
+ HelperResources .register (classLoader , helperResource .getApplicationPath (), resource );
165
167
}
166
168
}
167
169
0 commit comments