1
1
using System ;
2
+ using System . Reflection ;
2
3
using System . Threading . Tasks ;
3
4
using Datadog . Trace . ClrProfiler . Emit ;
5
+ using Datadog . Trace . Logging ;
4
6
5
7
namespace Datadog . Trace . ClrProfiler . Integrations . StackExchange . Redis
6
8
{
@@ -16,6 +18,8 @@ public static class RedisBatch
16
18
private const string Major1 = "1" ;
17
19
private const string Major2 = "2" ;
18
20
21
+ private static readonly ILog Log = LogProvider . GetLogger ( typeof ( RedisBatch ) ) ;
22
+
19
23
/// <summary>
20
24
/// Execute an asynchronous redis operation.
21
25
/// </summary>
@@ -69,6 +73,27 @@ private static async Task<T> ExecuteAsyncInternal<T>(object redisBase, object me
69
73
var processorType = asm . GetType ( "StackExchange.Redis.ResultProcessor`1" ) . MakeGenericType ( genericType ) ;
70
74
var serverType = asm . GetType ( "StackExchange.Redis.ServerEndPoint" ) ;
71
75
76
+ Action < object , object , object , object > instrumentedMethod = null ;
77
+
78
+ instrumentedMethod =
79
+ MethodBuilder < Action < object , object , object , object > >
80
+ . Start ( Assembly . GetCallingAssembly ( ) , mdToken , opCode , nameof ( BeforeAction ) )
81
+ . WithConcreteTypeName ( DiagnosticSource )
82
+ . WithParameters ( diagnosticSource , actionDescriptor , httpContext , routeData )
83
+ . Build ( ) ;
84
+
85
+ try
86
+ {
87
+ // call the original method, catching and rethrowing any unhandled exceptions
88
+ instrumentedMethod ? . Invoke ( diagnosticSource , actionDescriptor , httpContext , routeData ) ;
89
+ }
90
+ catch ( Exception ex )
91
+ {
92
+ // profiled app will continue working as expected without this method
93
+ Log . Error ( $ "Exception when calling { methodDef } .", ex ) ;
94
+ throw ;
95
+ }
96
+
72
97
var originalMethod = Emit . DynamicMethodBuilder < Func < object , object , object , object , Task < T > > >
73
98
. CreateMethodCallDelegate (
74
99
thisType ,
0 commit comments