33import datadog .trace .agent .tooling .InstrumenterModule ;
44import datadog .trace .agent .tooling .InstrumenterState ;
55import datadog .trace .agent .tooling .Utils ;
6- import java .util .Collections ;
76import java .util .List ;
8- import java .util .concurrent .CopyOnWriteArrayList ;
97import net .bytebuddy .matcher .ElementMatcher ;
108import org .slf4j .Logger ;
119import org .slf4j .LoggerFactory ;
1210
1311public class MuzzleCheck implements ElementMatcher <ClassLoader > {
1412 private static final Logger log = LoggerFactory .getLogger (MuzzleCheck .class );
1513
16- private static final List <String > ERRORS = new CopyOnWriteArrayList <>();
17- private static volatile boolean recordErrors = false ;
18-
1914 private final int instrumentationId ;
2015 private final String instrumentationClass ;
2116 private final ReferenceProvider runtimeMuzzleReferences ;
@@ -38,13 +33,9 @@ public boolean matches(ClassLoader classLoader) {
3833 InstrumenterState .applyInstrumentation (classLoader , instrumentationId );
3934 } else {
4035 InstrumenterState .blockInstrumentation (classLoader , instrumentationId );
41- if (recordErrors || log .isDebugEnabled ()) {
36+ if (log .isDebugEnabled ()) {
4237 final List <Reference .Mismatch > mismatches =
4338 muzzle .getMismatchedReferenceSources (classLoader );
44- if (recordErrors ) {
45- recordMuzzleMismatch (
46- InstrumenterState .describe (instrumentationId ), classLoader , mismatches );
47- }
4839 log .debug (
4940 "Muzzled - {} instrumentation.target.classloader={}" ,
5041 InstrumenterState .describe (instrumentationId ),
@@ -70,38 +61,4 @@ private ReferenceMatcher muzzle() {
7061 }
7162 return muzzle ;
7263 }
73-
74- /**
75- * Record a muzzle mismatch error for test visibility.
76- *
77- * @param instrumentationDescription the description of the instrumentation that was blocked
78- * @param classLoader the classloader where the instrumentation was blocked
79- * @param mismatches the list of mismatch details
80- */
81- private static void recordMuzzleMismatch (
82- String instrumentationDescription ,
83- ClassLoader classLoader ,
84- List <Reference .Mismatch > mismatches ) {
85- StringBuilder sb = new StringBuilder ();
86- sb .append ("Muzzled - " )
87- .append (instrumentationDescription )
88- .append (" instrumentation.target.classloader=" )
89- .append (classLoader )
90- .append ("\n " );
91- for (Reference .Mismatch mismatch : mismatches ) {
92- sb .append (" Mismatch: " ).append (mismatch ).append ("\n " );
93- }
94- ERRORS .add (sb .toString ());
95- }
96-
97- // Visible for testing
98- public static void enableRecordingAndReset () {
99- recordErrors = true ;
100- ERRORS .clear ();
101- }
102-
103- // Visible for testing
104- public static List <String > getErrors () {
105- return Collections .unmodifiableList (ERRORS );
106- }
10764}
0 commit comments