88using System . Runtime . CompilerServices ;
99using Datadog . Trace . Debugger . Expressions ;
1010using Datadog . Trace . Debugger . Helpers ;
11+ using Datadog . Trace . Debugger . Instrumentation . Registry ;
1112using Datadog . Trace . Debugger . RateLimiting ;
1213using Datadog . Trace . Logging ;
1314
@@ -53,7 +54,8 @@ public static void LogLocal<TLocal>(ref TLocal local, int index, ref AsyncLineDe
5354 }
5455
5556 var captureInfo = new CaptureInfo < TLocal > ( value : local , type : typeof ( TLocal ) , methodState : MethodState . LogLocal , name : localName , memberKind : ScopeMemberKind . Local ) ;
56- if ( ! ProbeExpressionsProcessor . Instance . Process ( state . ProbeId , ref captureInfo , state . SnapshotCreator ) )
57+
58+ if ( ! state . ProbeData . Processor . Process ( ref captureInfo , state . SnapshotCreator ) )
5759 {
5860 state . IsActive = false ;
5961 }
@@ -104,6 +106,7 @@ public static void LogException(Exception exception, ref AsyncLineDebuggerState
104106 /// </summary>
105107 /// <typeparam name="TTarget">Target type</typeparam>
106108 /// <param name="probeId">The id of the probe</param>
109+ /// <param name="probeMetadataIndex">The index used to lookup for the <see cref="ProbeData"/></param>
107110 /// <param name="instance">Instance value</param>
108111 /// <param name="methodHandle">The handle of the executing method</param>
109112 /// <param name="typeHandle">The handle of the type</param>
@@ -112,7 +115,7 @@ public static void LogException(Exception exception, ref AsyncLineDebuggerState
112115 /// <param name="probeFilePath">The path to the file of the probe</param>
113116 /// <returns>Live debugger state</returns>
114117 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
115- public static AsyncLineDebuggerState BeginLine < TTarget > ( string probeId , TTarget instance , RuntimeMethodHandle methodHandle , RuntimeTypeHandle typeHandle , int methodMetadataIndex , int lineNumber , string probeFilePath )
118+ public static AsyncLineDebuggerState BeginLine < TTarget > ( string probeId , int probeMetadataIndex , TTarget instance , RuntimeMethodHandle methodHandle , RuntimeTypeHandle typeHandle , int methodMetadataIndex , int lineNumber , string probeFilePath )
116119 {
117120 try
118121 {
@@ -125,7 +128,7 @@ public static AsyncLineDebuggerState BeginLine<TTarget>(string probeId, TTarget
125128 }
126129
127130 // Assess if we have metadata associated with the given index
128- if ( ! MethodMetadataProvider . IsIndexExists ( methodMetadataIndex ) )
131+ if ( ! MethodMetadataCollection . Instance . IsIndexExists ( methodMetadataIndex ) )
129132 {
130133 // State machine is null when we run in Optimized code and the original async method was generic,
131134 // in which case the state machine is a generic value type.
@@ -137,25 +140,32 @@ public static AsyncLineDebuggerState BeginLine<TTarget>(string probeId, TTarget
137140 Log . Warning ( $ "{ nameof ( BeginLine ) } : hoisted 'this' has not found. { kickoffInfo . KickoffParentType . Name } .{ kickoffInfo . KickoffMethod . Name } ") ;
138141 }
139142
140- if ( ! MethodMetadataProvider . TryCreateAsyncMethodMetadataIfNotExists ( instance , methodMetadataIndex , in methodHandle , in typeHandle , kickoffInfo ) )
143+ if ( ! MethodMetadataCollection . Instance . TryCreateAsyncMethodMetadataIfNotExists ( instance , methodMetadataIndex , in methodHandle , in typeHandle , kickoffInfo ) )
141144 {
142- Log . Warning ( $ "BeginMethod_StartMarker : Failed to receive the InstrumentedMethodInfo associated with the executing method. type = { typeof ( TTarget ) } , instance type name = { instance . GetType ( ) . Name } , methodMetadataId = { methodMetadataIndex } ") ;
145+ Log . Warning ( $ "([Async]BeginLine : Failed to receive the InstrumentedMethodInfo associated with the executing method. type = { typeof ( TTarget ) } , instance type name = { instance . GetType ( ) . Name } , methodMetadataId = { methodMetadataIndex } , probeId = { probeId } ") ;
143146 return CreateInvalidatedAsyncLineDebuggerState ( ) ;
144147 }
145148 }
146149
150+ if ( ! ProbeMetadataCollection . Instance . TryCreateProbeMetadataIfNotExists ( probeMetadataIndex , probeId ) )
151+ {
152+ Log . Warning ( $ "[Async]BeginLine: Failed to receive the ProbeData associated with the executing probe. type = { typeof ( TTarget ) } , instance type name = { instance ? . GetType ( ) . Name } , probeMetadataIndex = { probeMetadataIndex } , probeId = { probeId } ") ;
153+ return CreateInvalidatedAsyncLineDebuggerState ( ) ;
154+ }
155+
147156 var kickoffParentObject = AsyncHelper . GetAsyncKickoffThisObject ( instance ) ;
148- var state = new AsyncLineDebuggerState ( probeId , scope : default , DateTimeOffset . UtcNow , methodMetadataIndex , lineNumber , probeFilePath , instance , kickoffParentObject ) ;
157+ var state = new AsyncLineDebuggerState ( probeId , scope : default , DateTimeOffset . UtcNow , methodMetadataIndex , probeMetadataIndex , lineNumber , probeFilePath , instance , kickoffParentObject ) ;
149158
150159 if ( ! state . SnapshotCreator . ProbeHasCondition &&
151- ! ProbeRateLimiter . Instance . Sample ( probeId ) )
160+ ! state . ProbeData . Sampler . Sample ( ) )
152161 {
153162 return CreateInvalidatedAsyncLineDebuggerState ( ) ;
154163 }
155164
156165 var asyncInfo = new AsyncCaptureInfo ( state . MoveNextInvocationTarget , state . KickoffInvocationTarget , state . MethodMetadataInfo . KickoffInvocationTargetType , hoistedLocals : state . MethodMetadataInfo . AsyncMethodHoistedLocals , hoistedArgs : state . MethodMetadataInfo . AsyncMethodHoistedArguments ) ;
157166 var captureInfo = new CaptureInfo < Type > ( value : null , type : state . MethodMetadataInfo . DeclaringType , methodState : MethodState . BeginLineAsync , localsCount : state . MethodMetadataInfo . LocalVariableNames . Length , argumentsCount : state . MethodMetadataInfo . ParameterNames . Length , lineCaptureInfo : new LineCaptureInfo ( lineNumber , probeFilePath ) , asyncCaptureInfo : asyncInfo ) ;
158- if ( ! ProbeExpressionsProcessor . Instance . Process ( probeId , ref captureInfo , state . SnapshotCreator ) )
167+
168+ if ( ! state . ProbeData . Processor . Process ( ref captureInfo , state . SnapshotCreator ) )
159169 {
160170 state . IsActive = false ;
161171 }
@@ -191,7 +201,7 @@ public static void EndLine(ref AsyncLineDebuggerState state)
191201 state . HasLocalsOrReturnValue = false ;
192202 var asyncCaptureInfo = new AsyncCaptureInfo ( state . MoveNextInvocationTarget , state . KickoffInvocationTarget , state . MethodMetadataInfo . KickoffInvocationTargetType , kickoffMethod : state . MethodMetadataInfo . KickoffMethod , hoistedArgs : state . MethodMetadataInfo . AsyncMethodHoistedArguments , hoistedLocals : state . MethodMetadataInfo . AsyncMethodHoistedLocals ) ;
193203 var captureInfo = new CaptureInfo < object > ( memberKind : ScopeMemberKind . This , methodState : MethodState . EndLineAsync , hasLocalOrArgument : hasArgumentsOrLocals , asyncCaptureInfo : asyncCaptureInfo , lineCaptureInfo : new LineCaptureInfo ( state . LineNumber , state . ProbeFilePath ) ) ;
194- ProbeExpressionsProcessor . Instance . Process ( state . ProbeId , ref captureInfo , state . SnapshotCreator ) ;
204+ state . ProbeData . Processor . Process ( ref captureInfo , state . SnapshotCreator ) ;
195205 }
196206 catch ( Exception e )
197207 {
0 commit comments