1414import static com .datadog .debugger .instrumentation .Types .CAPTURED_VALUE ;
1515import static com .datadog .debugger .instrumentation .Types .CAPTURE_THROWABLE_TYPE ;
1616import static com .datadog .debugger .instrumentation .Types .CLASS_TYPE ;
17- import static com .datadog .debugger .instrumentation .Types .CORRELATION_ACCESS_TYPE ;
1817import static com .datadog .debugger .instrumentation .Types .DEBUGGER_CONTEXT_TYPE ;
1918import static com .datadog .debugger .instrumentation .Types .METHOD_LOCATION_TYPE ;
2019import static com .datadog .debugger .instrumentation .Types .OBJECT_TYPE ;
3433import com .datadog .debugger .sink .Snapshot ;
3534import com .datadog .debugger .util .ClassFileLines ;
3635import datadog .trace .api .Config ;
37- import datadog .trace .bootstrap .debugger .CorrelationAccess ;
3836import datadog .trace .bootstrap .debugger .Limits ;
3937import datadog .trace .bootstrap .debugger .MethodLocation ;
4038import datadog .trace .bootstrap .debugger .ProbeId ;
@@ -778,8 +776,6 @@ private InsnList collectCapturedContext(Snapshot.Kind kind, AbstractInsnNode loc
778776 // stack: [capturedcontext]
779777 collectStaticFields (insnList );
780778 // stack: [capturedcontext]
781- collectCorrelationInfo (insnList );
782- // stack: [capturedcontext]
783779 /*
784780 * It makes no sense collecting local variables for exceptions - the ones contributing to the exception
785781 * are most likely to be outside of the scope in the exception handler block and there is no way to figure
@@ -1096,42 +1092,6 @@ private void collectStaticFields(InsnList insnList) {
10961092 // stack: [capturedcontext]
10971093 }
10981094
1099- private void collectCorrelationInfo (InsnList insnList ) {
1100- // expected stack top: [capturedcontext]
1101- /*
1102- * We are cheating a bit with CorrelationAccess - utilizing the knowledge that it is a singleton loaded by the
1103- * bootstrap class loader we can assume that the availability will not change during the app life time.
1104- * As a side effect, we happen to initialize the access here and not from the injected code.
1105- */
1106- boolean correlationAvailable = CorrelationAccess .instance ().isAvailable ();
1107- if (isStatic && !correlationAvailable ) {
1108- // static method and no correlation info, no need to capture fields
1109- return ;
1110- }
1111- extractSpecialId (insnList , "dd.trace_id" , "getTraceId" , "addTraceId" );
1112- // stack: [capturedcontext]
1113- extractSpecialId (insnList , "dd.span_id" , "getSpanId" , "addSpanId" );
1114- // stack: [capturedcontext]
1115- }
1116-
1117- private void extractSpecialId (
1118- InsnList insnList , String fieldName , String getMethodName , String addMethodName ) {
1119- insnList .add (new InsnNode (Opcodes .DUP ));
1120- // stack: [capturedcontext, capturedcontext]
1121- ldc (insnList , fieldName );
1122- // stack: [capturedcontext, capturedcontext, name]
1123- ldc (insnList , STRING_TYPE .getClassName ());
1124- // stack: [capturedcontext, capturedcontext, name, type_name]
1125- invokeStatic (insnList , CORRELATION_ACCESS_TYPE , "instance" , CORRELATION_ACCESS_TYPE );
1126- // stack: [capturedcontext, capturedcontext, name, type_name, access]
1127- invokeVirtual (insnList , CORRELATION_ACCESS_TYPE , getMethodName , STRING_TYPE );
1128- // stack: [capturedcontext, capturedcontext, name, type_name, id]
1129- addCapturedValueOf (insnList , limits );
1130- // stack: [capturedcontext, capturedcontext, captured_value]
1131- invokeVirtual (insnList , CAPTURED_CONTEXT_TYPE , addMethodName , Type .VOID_TYPE , CAPTURED_VALUE );
1132- // stack: [capturedcontext]
1133- }
1134-
11351095 private static boolean isAccessible (FieldNode fieldNode ) {
11361096 Object value = fieldNode .value ;
11371097 if (value instanceof Field ) {
@@ -1140,67 +1100,6 @@ private static boolean isAccessible(FieldNode fieldNode) {
11401100 return true ;
11411101 }
11421102
1143- private static List <FieldNode > extractInstanceField (
1144- ClassNode classNode , boolean isStatic , ClassLoader classLoader , Limits limits ) {
1145- List <FieldNode > results = new ArrayList <>();
1146- if (CorrelationAccess .instance ().isAvailable ()) {
1147- results .add (
1148- new FieldNode (
1149- Opcodes .ACC_PRIVATE , "dd.trace_id" , STRING_TYPE .getDescriptor (), null , null ));
1150- results .add (
1151- new FieldNode (
1152- Opcodes .ACC_PRIVATE , "dd.span_id" , STRING_TYPE .getDescriptor (), null , null ));
1153- }
1154- if (isStatic ) {
1155- return results ;
1156- }
1157- int fieldCount = 0 ;
1158- for (FieldNode fieldNode : classNode .fields ) {
1159- if (isStaticField (fieldNode )) {
1160- continue ;
1161- }
1162- results .add (fieldNode );
1163- fieldCount ++;
1164- if (fieldCount > limits .maxFieldCount ) {
1165- return results ;
1166- }
1167- }
1168- addInheritedFields (classNode , classLoader , limits , results , fieldCount );
1169- return results ;
1170- }
1171-
1172- private static void addInheritedFields (
1173- ClassNode classNode ,
1174- ClassLoader classLoader ,
1175- Limits limits ,
1176- List <FieldNode > results ,
1177- int fieldCount ) {
1178- String superClassName = extractSuperClass (classNode );
1179- while (!superClassName .equals (Object .class .getTypeName ())) {
1180- Class <?> clazz ;
1181- try {
1182- clazz = Class .forName (superClassName , false , classLoader );
1183- } catch (ClassNotFoundException ex ) {
1184- break ;
1185- }
1186- for (Field field : clazz .getDeclaredFields ()) {
1187- if (isStaticField (field )) {
1188- continue ;
1189- }
1190- String desc = Type .getDescriptor (field .getType ());
1191- FieldNode fieldNode =
1192- new FieldNode (field .getModifiers (), field .getName (), desc , null , field );
1193- results .add (fieldNode );
1194- fieldCount ++;
1195- if (fieldCount > limits .maxFieldCount ) {
1196- return ;
1197- }
1198- }
1199- clazz = clazz .getSuperclass ();
1200- superClassName = clazz .getTypeName ();
1201- }
1202- }
1203-
12041103 private static List <FieldNode > extractStaticFields (
12051104 ClassNode classNode , ClassLoader classLoader , Limits limits ) {
12061105 int fieldCount = 0 ;
0 commit comments