Ejemplo n.º 1
0
        public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall instrumentedMethodCall, IAgent agent, ITransaction transaction)
        {
            var operation = instrumentedMethodCall.MethodCall.Method.MethodName;
            var isAsync   = operation.EndsWith("Async", StringComparison.OrdinalIgnoreCase);

            operation = isAsync ? "LinqQueryAsync" : "LinqQuery";

            var caller = instrumentedMethodCall.MethodCall.InvocationTarget;

            var collection = MongoDbHelper.GetCollectionFieldFromGeneric(caller);
            var database   = MongoDbHelper.GetDatabaseFromGeneric(collection);

            ConnectionInfo connectionInfo      = MongoDbHelper.GetConnectionInfoFromDatabase(database);
            var            collectionNamespace = MongoDbHelper.GetCollectionNamespacePropertyFromGeneric(caller);
            var            model = MongoDbHelper.GetCollectionName(collectionNamespace);

            var segment = transaction.StartDatastoreSegment(instrumentedMethodCall.MethodCall,
                                                            new ParsedSqlStatement(DatastoreVendor.MongoDB, model, operation), isLeaf: true, connectionInfo: connectionInfo);

            if (!isAsync)
            {
                return(Delegates.GetDelegateFor(segment));
            }

            return(Delegates.GetAsyncDelegateFor <Task>(agent, segment, true));
        }
        public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall instrumentedMethodCall, IAgent agent, ITransaction transaction)
        {
            var operation = instrumentedMethodCall.MethodCall.Method.MethodName;
            var model     = TryGetModelName(instrumentedMethodCall);

            var            caller         = instrumentedMethodCall.MethodCall.InvocationTarget;
            ConnectionInfo connectionInfo = MongoDbHelper.GetConnectionInfoFromDatabase(caller);

            var segment = transaction.StartDatastoreSegment(instrumentedMethodCall.MethodCall,
                                                            new ParsedSqlStatement(DatastoreVendor.MongoDB, model, operation), isLeaf: true, connectionInfo: connectionInfo);

            if (!operation.EndsWith("Async", StringComparison.OrdinalIgnoreCase))
            {
                return(Delegates.GetDelegateFor(segment));
            }

            return(Delegates.GetAsyncDelegateFor <Task>(agent, segment, true));
        }