public static object ExecuteReaderAsync( object command, object boxedCancellationToken, int opCode, int mdToken, long moduleVersionPtr) { const string methodName = AdoNetConstants.MethodNames.ExecuteReaderAsync; var cancellationToken = (CancellationToken)boxedCancellationToken; Type npgsqlComandType; Type npgsqlDataReaderType; try { npgsqlComandType = command.GetInstrumentedType(NpgsqlCommandTypeName); npgsqlDataReaderType = npgsqlComandType.Assembly.GetType(NpgsqlDataReaderTypeName); } catch (Exception ex) { // This shouldn't happen because the assembly holding the Npgsql.NpgsqlDataReader type should have been loaded already // profiled app will not continue working as expected without this method Log.Error(ex, "Error finding the Npgsql.NpgsqlDataReader type"); throw; } Func <DbCommand, CancellationToken, object> instrumentedMethod; try { instrumentedMethod = MethodBuilder <Func <DbCommand, CancellationToken, object> > .Start(moduleVersionPtr, mdToken, opCode, methodName) .WithConcreteType(npgsqlComandType) .WithParameters(cancellationToken) .WithNamespaceAndNameFilters(ClrNames.GenericTask, ClrNames.CancellationToken) .Build(); } catch (Exception ex) { Log.ErrorRetrievingMethod( exception: ex, moduleVersionPointer: moduleVersionPtr, mdToken: mdToken, opCode: opCode, instrumentedType: NpgsqlCommandTypeName, methodName: methodName, instanceType: command.GetType().AssemblyQualifiedName); throw; } return(AsyncHelper.InvokeGenericTaskDelegate( owningType: command.GetType(), taskResultType: npgsqlDataReaderType, nameOfIntegrationMethod: nameof(ExecuteReaderAsyncInternal), integrationType: typeof(NpgsqlCommandIntegration), (DbCommand)command, cancellationToken, instrumentedMethod)); }
public static object ExecuteAsync(object executionStrategy, object context, int opCode, int mdToken) { if (executionStrategy == null) { throw new ArgumentNullException(nameof(executionStrategy)); } const string methodName = nameof(ExecuteAsync); // At runtime, get a Type object for GraphQL.ExecutionResult var executionStrategyInstanceType = executionStrategy.GetType(); Type graphQLExecutionResultType; Type executionStrategyInterfaceType; try { var graphQLAssembly = AppDomain.CurrentDomain.GetAssemblies() .Where(a => a.GetName().Name.Equals(GraphQLAssemblyName)) .Single(); graphQLExecutionResultType = graphQLAssembly.GetType(GraphQLExecutionResultName, throwOnError: true); executionStrategyInterfaceType = graphQLAssembly.GetType(GraphQLExecutionStrategyInterfaceName, throwOnError: true); } catch (Exception ex) { // This shouldn't happen because the GraphQL assembly should have been loaded to construct various other types // profiled app will not continue working as expected without this method Log.ErrorException($"Error finding types in the GraphQL assembly.", ex); throw; } Func <object, object, object> instrumentedMethod; try { instrumentedMethod = MethodBuilder <Func <object, object, object> > .Start(Assembly.GetCallingAssembly(), mdToken, opCode, methodName) .WithConcreteType(executionStrategyInstanceType) .WithParameters(context) .Build(); } catch (Exception ex) { // profiled app will not continue working as expected without this method Log.ErrorException($"Error resolving {executionStrategyInterfaceType.Name}.{methodName}(...)", ex); throw; } return(AsyncHelper.InvokeGenericTaskDelegate( owningType: executionStrategyInterfaceType, taskResultType: graphQLExecutionResultType, nameOfIntegrationMethod: nameof(CallGraphQLExecuteAsyncInternal), integrationType: typeof(GraphQLIntegration), executionStrategy, context, instrumentedMethod)); }
public static object CallElasticsearchAsync <TResponse>( object pipeline, object requestData, object cancellationTokenSource, int opCode, int mdToken, long moduleVersionPtr) { if (pipeline == null) { throw new ArgumentNullException(nameof(pipeline)); } var tokenSource = cancellationTokenSource as CancellationTokenSource; var cancellationToken = tokenSource?.Token ?? CancellationToken.None; var genericArgument = typeof(TResponse); var genericResponseType = ElasticsearchResponseType.MakeGenericType(genericArgument); Func <object, object, CancellationToken, object> instrumentedMethod; try { instrumentedMethod = MethodBuilder <Func <object, object, CancellationToken, object> > .Start(moduleVersionPtr, mdToken, opCode, nameof(CallElasticsearchAsync)) .WithConcreteType(pipeline.GetType()) .WithMethodGenerics(genericArgument) .WithParameters(requestData, cancellationToken) .WithNamespaceAndNameFilters(ClrNames.GenericTask, "Elasticsearch.Net.RequestData", ClrNames.CancellationToken) .ForceMethodDefinitionResolution() .Build(); } catch (Exception ex) { Log.ErrorRetrievingMethod( exception: ex, moduleVersionPointer: moduleVersionPtr, mdToken: mdToken, opCode: opCode, instrumentedType: RequestPipelineInterfaceTypeName, methodName: nameof(CallElasticsearchAsync), instanceType: pipeline.GetType().AssemblyQualifiedName); throw; } return(AsyncHelper.InvokeGenericTaskDelegate( owningType: ElasticsearchNetCommon.RequestPipelineType, taskResultType: genericResponseType, nameOfIntegrationMethod: nameof(CallElasticsearchAsyncInternal), integrationType: typeof(ElasticsearchNet5Integration), pipeline, requestData, cancellationToken, instrumentedMethod)); }
public static object ExecuteAsyncGeneric( object wireProtocol, object connection, object cancellationTokenSource, int opCode, int mdToken, long moduleVersionPtr) { // The generic type for this method comes from the declaring type of wireProtocol if (wireProtocol == null) { throw new ArgumentNullException(nameof(wireProtocol)); } var tokenSource = cancellationTokenSource as CancellationTokenSource; var cancellationToken = tokenSource?.Token ?? CancellationToken.None; var wireProtocolType = wireProtocol.GetType(); var wireProtocolGenericArgs = GetGenericsFromWireProtocol(wireProtocolType); const string methodName = nameof(ExecuteAsync); Func <object, object, CancellationToken, object> executeAsync; try { executeAsync = MethodBuilder <Func <object, object, CancellationToken, object> > .Start(moduleVersionPtr, mdToken, opCode, methodName) .WithConcreteType(wireProtocolType) .WithDeclaringTypeGenerics(wireProtocolGenericArgs) .WithParameters(connection, cancellationToken) .WithNamespaceAndNameFilters(ClrNames.GenericTask, "MongoDB.Driver.Core.Connections.IConnection", ClrNames.CancellationToken) .Build(); } catch (Exception ex) { // profiled app will not continue working as expected without this method Log.Error(ex, $"Error resolving {wireProtocolType.Name}.{methodName}(IConnection connection, CancellationToken cancellationToken)"); throw; } return(AsyncHelper.InvokeGenericTaskDelegate( wireProtocolType, wireProtocolGenericArgs[0], nameof(ExecuteAsyncInternalGeneric), typeof(MongoDbIntegration), wireProtocol, connection, cancellationToken, executeAsync)); }
public static object ExecuteDbDataReaderAsync( object @this, int behavior, object cancellationTokenSource, int opCode, int mdToken) { var tokenSource = cancellationTokenSource as CancellationTokenSource; var cancellationToken = tokenSource?.Token ?? CancellationToken.None; var command = (DbCommand)@this; var instanceType = command.GetType(); var commandBehavior = (CommandBehavior)behavior; var callingAssembly = Assembly.GetCallingAssembly(); var dataReaderType = callingAssembly.GetType(DbDataReader); Func <object, object, object, object> instrumentedMethod = null; try { instrumentedMethod = MethodBuilder <Func <object, object, object, object> > .Start(Assembly.GetCallingAssembly(), mdToken, opCode, nameof(ExecuteDbDataReaderAsync)) .WithConcreteType(typeof(DbCommand)) .WithParameters(commandBehavior, cancellationToken) .Build(); } catch (Exception ex) { Log.ErrorException($"Error resolving {DbCommand}.{nameof(ExecuteDbDataReaderAsync)}(...)", ex); throw; } return(AsyncHelper.InvokeGenericTaskDelegate( instanceType, dataReaderType, nameof(ExecuteDbDataReaderAsyncInternal), typeof(AdoNetIntegration), command, commandBehavior, cancellationToken, instrumentedMethod)); }
public static object ExecuteDbDataReaderAsync( object @this, int behavior, object cancellationTokenSource, int opCode, int mdToken, long moduleVersionPtr) { var tokenSource = cancellationTokenSource as CancellationTokenSource; var cancellationToken = tokenSource?.Token ?? CancellationToken.None; var instrumentedType = typeof(DbCommand); var dataReaderType = typeof(DbDataReader); var commandBehavior = (CommandBehavior)behavior; Func <object, CommandBehavior, object, object> instrumentedMethod = null; try { instrumentedMethod = MethodBuilder <Func <object, CommandBehavior, object, object> > .Start(moduleVersionPtr, mdToken, opCode, nameof(ExecuteDbDataReaderAsync)) .WithConcreteType(instrumentedType) .WithParameters(commandBehavior, cancellationToken) .WithNamespaceAndNameFilters(ClrNames.GenericTask, SystemDataCommonCommandBehavior, ClrNames.CancellationToken) .Build(); } catch (Exception ex) { Log.ErrorException($"Error resolving {SystemDataCommonDbCommand}.{nameof(ExecuteDbDataReaderAsync)}(...)", ex); throw; } return(AsyncHelper.InvokeGenericTaskDelegate( owningType: instrumentedType, taskResultType: dataReaderType, nameOfIntegrationMethod: nameof(ExecuteDbDataReaderAsyncInternal), integrationType: typeof(AdoNetIntegration), parametersToPass: new object[] { @this, behavior, cancellationToken, instrumentedMethod })); }
public static object CallElasticsearchAsync <TResponse>(object pipeline, object requestData, object cancellationTokenSource, int opCode, int mdToken) { var tokenSource = cancellationTokenSource as CancellationTokenSource; var cancellationToken = tokenSource?.Token ?? CancellationToken.None; var genericArgument = typeof(TResponse); var genericResponseType = ElasticsearchResponseType.MakeGenericType(genericArgument); Func <object, object, CancellationToken, object> instrumentedMethod; try { instrumentedMethod = MethodBuilder <Func <object, object, CancellationToken, object> > .Start(Assembly.GetCallingAssembly(), mdToken, opCode, nameof(CallElasticsearchAsync)) .WithConcreteType(pipeline.GetType()) .WithMethodGenerics(genericArgument) .WithParameters(requestData, cancellationToken) .ForceMethodDefinitionResolution() .Build(); } catch (Exception ex) { Log.ErrorException($"Error resolving Elasticsearch.Net.IRequestPipeline.{nameof(CallElasticsearchAsync)}<T>(...)", ex); throw; } return(AsyncHelper.InvokeGenericTaskDelegate( owningType: ElasticsearchNetCommon.RequestPipelineType, taskResultType: genericResponseType, nameOfIntegrationMethod: nameof(CallElasticsearchAsyncInternal), integrationType: typeof(ElasticsearchNet5Integration), pipeline, requestData, cancellationToken, instrumentedMethod)); }
public static object ExecuteAsync( object apiController, object controllerContext, object boxedCancellationToken, int opCode, int mdToken, long moduleVersionPtr) { if (apiController == null) { throw new ArgumentNullException(nameof(apiController)); } var cancellationToken = (CancellationToken)boxedCancellationToken; var callOpCode = (OpCodeValue)opCode; var httpControllerType = apiController.GetInstrumentedInterface(HttpControllerTypeName); Type taskResultType; try { var request = controllerContext.GetProperty <object>("Request").GetValueOrDefault(); var httpRequestMessageType = request.GetInstrumentedType("System.Net.Http.HttpRequestMessage"); // The request should never be null, so get the base type found in System.Net.Http.dll if (httpRequestMessageType != null) { var systemNetHttpAssembly = httpRequestMessageType.Assembly; taskResultType = systemNetHttpAssembly.GetType("System.Net.Http.HttpResponseMessage", true); } // This should never happen, but put in a reasonable fallback of finding the first System.Net.Http.dll in the AppDomain else { Log.Warning($"{nameof(AspNetWebApi2Integration)}.{nameof(ExecuteAsync)}: Unable to find System.Net.Http.HttpResponseMessage Type from method arguments. Using fallback logic to find the Type needed for return type."); var statsd = Tracer.Instance.Statsd; statsd?.Warning(source: $"{nameof(AspNetWebApi2Integration)}.{nameof(ExecuteAsync)}", message: "Unable to find System.Net.Http.HttpResponseMessage Type from method arguments. Using fallback logic to find the Type needed for return type.", null); var systemNetHttpAssemblies = AppDomain.CurrentDomain.GetAssemblies().Where(assembly => assembly.GetName().Name.Equals("System.Net.Http", StringComparison.OrdinalIgnoreCase)); var firstSystemNetHttpAssembly = systemNetHttpAssemblies.First(); taskResultType = firstSystemNetHttpAssembly.GetType("System.Net.Http.HttpResponseMessage", true); } } catch (Exception ex) { // This shouldn't happen because the System.Net.Http assembly should have been loaded if this method was called // The profiled app will not continue working as expected without this method Log.Error(ex, "Error finding types in the user System.Net.Http assembly."); throw; } Func <object, object, CancellationToken, object> instrumentedMethod = null; try { instrumentedMethod = MethodBuilder <Func <object, object, CancellationToken, object> > .Start(moduleVersionPtr, mdToken, opCode, nameof(ExecuteAsync)) .WithConcreteType(httpControllerType) .WithParameters(controllerContext, cancellationToken) .WithNamespaceAndNameFilters( ClrNames.GenericTask, HttpControllerContextTypeName, ClrNames.CancellationToken) .Build(); } catch (Exception ex) { Log.ErrorRetrievingMethod( exception: ex, moduleVersionPointer: moduleVersionPtr, mdToken: mdToken, opCode: opCode, instrumentedType: HttpControllerTypeName, methodName: nameof(ExecuteAsync), instanceType: apiController.GetType().AssemblyQualifiedName); throw; } return(AsyncHelper.InvokeGenericTaskDelegate( owningType: apiController.GetType(), taskResultType: taskResultType, nameOfIntegrationMethod: nameof(ExecuteAsyncInternal), integrationType: typeof(AspNetWebApi2Integration), instrumentedMethod, apiController, controllerContext, cancellationToken)); }
public static object HttpMessageHandler_SendAsync( object handler, object request, object boxedCancellationToken, int opCode, int mdToken, long moduleVersionPtr) { if (handler == null) { throw new ArgumentNullException(nameof(handler)); } // original signature: // Task<HttpResponseMessage> HttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) var cancellationToken = (CancellationToken)boxedCancellationToken; var callOpCode = (OpCodeValue)opCode; var httpMessageHandler = handler.GetInstrumentedType(HttpMessageHandler); Type taskResultType; try { var currentHttpAssembly = httpMessageHandler.Assembly; taskResultType = currentHttpAssembly.GetType("System.Net.Http.HttpResponseMessage", true); } catch (Exception ex) { // This shouldn't happen because the System.Net.Http assembly should have been loaded if this method was called // profiled app will not continue working as expected without this method Log.Error(ex, "Error finding types in the user System.Net.Http assembly."); throw; } Func <object, object, CancellationToken, object> instrumentedMethod = null; try { instrumentedMethod = MethodBuilder <Func <object, object, CancellationToken, object> > .Start(moduleVersionPtr, mdToken, opCode, SendAsync) .WithConcreteType(httpMessageHandler) .WithParameters(request, cancellationToken) .WithNamespaceAndNameFilters(ClrNames.GenericTask, ClrNames.HttpRequestMessage, ClrNames.CancellationToken) .Build(); } catch (Exception ex) { Log.ErrorRetrievingMethod( exception: ex, moduleVersionPointer: moduleVersionPtr, mdToken: mdToken, opCode: opCode, instrumentedType: HttpMessageHandler, methodName: SendAsync, instanceType: handler.GetType().AssemblyQualifiedName); throw; } return(AsyncHelper.InvokeGenericTaskDelegate( owningType: handler.GetType(), taskResultType: taskResultType, nameOfIntegrationMethod: nameof(SendAsyncInternal), integrationType: typeof(HttpMessageHandlerIntegration), instrumentedMethod, callOpCode == OpCodeValue.Call ? httpMessageHandler : handler.GetType(), handler, request, cancellationToken)); }
public static object ExecuteAsync(object executionStrategy, object context, int opCode, int mdToken, long moduleVersionPtr) { if (executionStrategy == null) { throw new ArgumentNullException(nameof(executionStrategy)); } const string methodName = nameof(ExecuteAsync); // At runtime, get a Type object for GraphQL.ExecutionResult var executionStrategyInstanceType = executionStrategy.GetType(); Type graphQLExecutionResultType; Type executionStrategyInterfaceType; try { executionStrategyInterfaceType = executionStrategy.GetInstrumentedInterface(GraphQLExecutionStrategyInterfaceName); graphQLExecutionResultType = executionStrategyInterfaceType.Assembly.GetType(GraphQLExecutionResultName, throwOnError: true); } catch (Exception ex) { // This shouldn't happen because the GraphQL assembly should have been loaded to construct various other types // profiled app will not continue working as expected without this method Log.Error(ex, "Error finding types in the GraphQL assembly."); throw; } Func <object, object, object> instrumentedMethod; try { instrumentedMethod = MethodBuilder <Func <object, object, object> > .Start(moduleVersionPtr, mdToken, opCode, methodName) .WithConcreteType(executionStrategyInstanceType) .WithParameters(context) .WithNamespaceAndNameFilters(ClrNames.GenericTask, "GraphQL.Execution.ExecutionContext") .Build(); } catch (Exception ex) { Log.ErrorRetrievingMethod( exception: ex, moduleVersionPointer: moduleVersionPtr, mdToken: mdToken, opCode: opCode, instrumentedType: GraphQLExecutionStrategyInterfaceName, methodName: methodName, instanceType: executionStrategy.GetType().AssemblyQualifiedName); throw; } return(AsyncHelper.InvokeGenericTaskDelegate( owningType: executionStrategyInterfaceType, taskResultType: graphQLExecutionResultType, nameOfIntegrationMethod: nameof(CallGraphQLExecuteAsyncInternal), integrationType: typeof(GraphQLIntegration), executionStrategy, context, instrumentedMethod)); }
private static object ExecuteReaderAsync( object command, int behavior, object boxedCancellationToken, int opCode, int mdToken, long moduleVersionPtr, string sqlClientNamespace) { const string methodName = AdoNetConstants.MethodNames.ExecuteReaderAsync; var cancellationToken = (CancellationToken)boxedCancellationToken; var commandBehavior = (CommandBehavior)behavior; Type sqlCommandType; Type sqlDataReaderType; try { sqlCommandType = command.GetInstrumentedType(sqlClientNamespace, SqlCommandTypeName); sqlDataReaderType = sqlCommandType.Assembly.GetType($"{sqlClientNamespace}.{SqlDataReaderTypeName}"); } catch (Exception ex) { // This shouldn't happen because the assembly holding the SqlCommand and SqlDataReader types should have been loaded already. // Profiled app will not continue working as expected without this method. Log.Error(ex, "Error finding the SqlCommand or SqlDataReader type"); throw; } Func<DbCommand, CommandBehavior, CancellationToken, object> instrumentedMethod; try { instrumentedMethod = MethodBuilder<Func<DbCommand, CommandBehavior, CancellationToken, object>> .Start(moduleVersionPtr, mdToken, opCode, methodName) .WithConcreteType(sqlCommandType) .WithParameters(commandBehavior, cancellationToken) .WithNamespaceAndNameFilters($"{ClrNames.GenericTask}<{sqlClientNamespace}.{SqlDataReaderTypeName}>", AdoNetConstants.TypeNames.CommandBehavior, ClrNames.CancellationToken) .Build(); } catch (Exception ex) { Log.ErrorRetrievingMethod( exception: ex, moduleVersionPointer: moduleVersionPtr, mdToken: mdToken, opCode: opCode, instrumentedType: $"{sqlClientNamespace}.{SqlCommandTypeName}", methodName: methodName, instanceType: command.GetType().AssemblyQualifiedName); throw; } return AsyncHelper.InvokeGenericTaskDelegate( owningType: command.GetType(), taskResultType: sqlDataReaderType, nameOfIntegrationMethod: nameof(ExecuteReaderAsyncInternal), integrationType: typeof(SqlCommandIntegration), (DbCommand)command, commandBehavior, cancellationToken, instrumentedMethod); }