Example #1
0
        public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
        {
            var method  = methodInfo.Method;
            var canWrap = method.MatchesAny(assemblyName: AssemblyName, typeName: SyncTypeName, methodName: SyncMethodName, parameterSignature: "System.Web.HttpContext");

            if (!canWrap)
            {
                canWrap = method.MatchesAny(assemblyName: AssemblyName, typeName: AsyncTypeName, methodName: AsyncBeginMethodName);
            }

            return(new CanWrapResponse(canWrap));
        }
Example #2
0
        public CanWrapResponse CanWrap(InstrumentedMethodInfo instrumentedMethodInfo)
        {
            var canWrap = instrumentedMethodInfo.IsAsync &&
                          PossibleWrapperNames.Contains(instrumentedMethodInfo.RequestedWrapperName);

            if (!canWrap)
            {
                return(new CanWrapResponse(false));
            }

            return(TaskFriendlySyncContextValidator.CanWrapAsyncMethod(instrumentedMethodInfo.Method.Type.Assembly.GetName().Name, instrumentedMethodInfo.Method.Type.Name, instrumentedMethodInfo.Method.MethodName));
        }
Example #3
0
        public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
        {
            var method  = methodInfo.Method;
            var canWrap = method.MatchesAny("Couchbase.NetClient", "Couchbase.CouchbaseBucket", "QueryAsync");

            if (canWrap)
            {
                return(TaskFriendlySyncContextValidator.CanWrapAsyncMethod("Couchbase.NetClient", "Couchbase.CouchbaseBucket", "QueryAsync"));
            }

            return(new CanWrapResponse(false));
        }
        public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
        {
            var method  = methodInfo.Method;
            var canWrap = method.MatchesAny
                          (
                assemblyName: AssemblyName,
                typeName: TypeName,
                methodName: MethodName
                          );

            return(new CanWrapResponse(canWrap));
        }
Example #5
0
        public CanWrapResponse CanWrap(InstrumentedMethodInfo instrumentedMethodInfo)
        {
            var method  = instrumentedMethodInfo.Method;
            var canWrap = method.MatchesAny
                          (
                assemblyName: "System.ServiceModel",
                typeName: "System.ServiceModel.ChannelFactory",
                methodName: "InitializeEndpoint"
                          );

            return(new CanWrapResponse(canWrap));
        }
        public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
        {
            var canWrap = WrapperNames.Contains(methodInfo.RequestedWrapperName, StringComparer.OrdinalIgnoreCase);

            if (canWrap && ExecuteAsAsync)
            {
                var method = methodInfo.Method;
                return(TaskFriendlySyncContextValidator.CanWrapAsyncMethod(method.Type.Assembly.GetName().Name, method.Type.FullName, method.MethodName));
            }

            return(new CanWrapResponse(canWrap));
        }
        public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
        {
            var method  = methodInfo.Method;
            var canWrap = method.MatchesAny
                          (
                assemblyNames: new[] { AssemblyName },
                typeNames: new[] { SyncTypeName, AsyncTypeName, TAPTypeName },
                methodNames: new[] { SyncMethodName, InvokeBeginMethodName, InvokeEndMethodName, InvokeAsyncMethodName }
                          );

            return(new CanWrapResponse(canWrap));
        }
        public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
        {
            var method = methodInfo.Method;

            var canWrap = method.MatchesAny(assemblyName: "MongoDB.Driver", typeName: "MongoDB.Driver.MongoIndexManagerBase`1",
                                            methodNames: new[]
            {
                "CreateOne",
                "CreateOneAsync"
            });

            return(new CanWrapResponse(canWrap));
        }
        public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
        {
            var method = methodInfo.Method;

            if (method.MatchesAny(assemblyName: "System.Net.Http", typeName: InstrumentedTypeName, methodName: "SendAsync"))
            {
                return(TaskFriendlySyncContextValidator.CanWrapAsyncMethod("System.Net.Http", "System.Net.Http.HttpClient", method.MethodName));
            }
            else
            {
                return(new CanWrapResponse(false));
            }
        }
Example #10
0
        public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
        {
            var method = methodInfo.Method;

            var canWrap = method.MatchesAny(assemblyName: "MongoDB.Driver", typeName: "MongoDB.Driver.Linq.MongoQueryProviderImpl`1",
                                            methodNames: new[]
            {
                "ExecuteModel",
                "ExecuteModelAsync"
            });

            return(new CanWrapResponse(canWrap));
        }
        public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
        {
            var method = methodInfo.Method;

            var canWrap = method.MatchesAny(assemblyName: "MongoDB.Driver.Core", typeName: "MongoDB.Driver.Core.Operations.AsyncCursor`1",
                                            methodSignatures: new[]
            {
                new MethodSignature("GetNextBatch", "System.Threading.CancellationToken"),
                new MethodSignature("GetNextBatchAsync", "System.Threading.CancellationToken"),
            });

            return(new CanWrapResponse(canWrap));
        }
        public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
        {
            var method  = methodInfo.Method;
            var version = method.Type.Assembly.GetName().Version;

            if (version == null)
            {
                return(new CanWrapResponse(false));
            }

            var canWrap = method.MatchesAny(assemblyName: "System.Web.Http", typeName: "System.Web.Http.ExceptionHandling.CompositeExceptionLogger", methodName: "LogAsync") &&
                          version.Major >= 5; // WebApi v2 == System.Web.Http v5

            return(new CanWrapResponse(canWrap));
        }
        public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
        {
            var method  = methodInfo.Method;
            var canWrap = method.MatchesAny
                          (
                assemblyName: ServiceModelAssembly,
                typeName: ServiceChannelProxyType,
                methodSignatures: new[]
            {
                new MethodSignature(InvokeMethod)
            }
                          );

            return(new CanWrapResponse(canWrap));
        }
        private void GenerateLibraryVersionSupportabilityMetric(InstrumentedMethodInfo instrumentedMethodInfo)
        {
            try
            {
                var reflectionAssemblyName = instrumentedMethodInfo.Method.Type.Assembly.GetName();
                var assemblyName           = reflectionAssemblyName.Name;
                var assemblyVersion        = reflectionAssemblyName.Version.ToString();

                _agentHealthReporter.ReportLibraryVersion(assemblyName, assemblyVersion);
            }
            catch (Exception ex)
            {
                Log.Error($"Failed to generate Library version Supportability Metric for {instrumentedMethodInfo.ToString()} : exception: {ex}");
            }
        }
        public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
        {
            var method = methodInfo.Method;

            if (method.MatchesAny(assemblyName: AssemblyName, typeNames: new[] { HttpClientTypeName, SocketsHttpHandlerTypeName }, methodName: SendAsyncMethodName))
            {
                return(TaskFriendlySyncContextValidator.CanWrapAsyncMethod(AssemblyName, HttpClientTypeName, method.MethodName));
            }
            else if (method.MatchesAny(assemblyName: AssemblyName, typeName: SocketsHttpHandlerTypeName, methodName: SendMethodName))
            {
                return(new CanWrapResponse(true));
            }

            return(new CanWrapResponse(false));
        }
Example #16
0
        public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
        {
            var method = methodInfo.Method;

            // WCF 4
            if (method.MatchesAny(assemblyName: "System.ServiceModel.Activation", typeName: "System.ServiceModel.Activation.HostedHttpRequestAsyncResult",
                                  methodName: ".ctor", parameterSignature: "System.Web.HttpApplication,System.String,System.Boolean,System.Boolean,System.AsyncCallback,System.Object"))
            {
                return(new CanWrapResponse(true));
            }

            // WCF 3
            var canWrap = method.MatchesAny(assemblyName: "System.ServiceModel", typeName: "System.ServiceModel.Activation.HostedHttpRequestAsyncResult",
                                            methodName: ".ctor", parameterSignature: "System.Web.HttpApplication,System.Boolean,System.AsyncCallback,System.Object");

            return(new CanWrapResponse(canWrap));
        }
        public void BeforeWrappedMethod_PassesCorrectParametersToWrapperLoader()
        {
            Mock.Arrange(() => _wrapperMap.Get(Arg.IsAny <InstrumentedMethodInfo>())).Returns(() => new TrackedWrapper(Mock.Create <IWrapper>()));

            var          type              = typeof(Class_WrapperService);
            const string methodName        = "MyMethod";
            const string tracerFactoryName = "MyTracer";
            var          target            = new object();
            var          arguments         = new object[0];

            _wrapperService.BeforeWrappedMethod(type, methodName, string.Empty, target, arguments, tracerFactoryName, null, EmptyTracerArgs, 0);

            var method                = new Method(type, methodName, string.Empty);
            var expectedMethodCall    = new MethodCall(method, target, arguments);
            var instrumetedMethodInfo = new InstrumentedMethodInfo(0, expectedMethodCall.Method, tracerFactoryName, false, null, null, false);

            Mock.Assert(() => _wrapperMap.Get(instrumetedMethodInfo));
        }
Example #18
0
        public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
        {
            var method = methodInfo.Method;

            var canWrap = method.MatchesAny(assemblyName: "MongoDB.Driver", typeName: "MongoDB.Driver.MongoCollectionImpl`1+MongoIndexManager",
                                            methodNames: new[]
            {
                "CreateMany",
                "DropAll",
                "DropOne",
                "List",

                "CreateManyAsync",
                "DropAllAsync",
                "DropOneAsync",
                "ListAsync"
            });

            return(new CanWrapResponse(canWrap));
        }
Example #19
0
        private TrackedWrapper GetDefaultWrapperOrSetNoOp(InstrumentedMethodInfo instrumentedMethodInfo)
        {
            foreach (var wrapper in _defaultWrappers)
            {
                if (CanWrap(instrumentedMethodInfo, wrapper))
                {
                    return(new TrackedWrapper(wrapper));
                }
            }

            Log.DebugFormat(
                "No matching wrapper found for {0}.{1}({2}) in assembly [{3}] (requested wrapper name was {4}). This usually indicates misconfigured instrumentation. This method will be ignored.",
                instrumentedMethodInfo.Method.Type.FullName,
                instrumentedMethodInfo.Method.MethodName,
                instrumentedMethodInfo.Method.ParameterTypeNames,
                instrumentedMethodInfo.Method.Type.Assembly.FullName,
                instrumentedMethodInfo.RequestedWrapperName);

            return(GetNoOpWrapper());
        }
Example #20
0
        private static bool CanWrap(InstrumentedMethodInfo instrumentedMethodInfo, IWrapper wrapper)
        {
            var method          = instrumentedMethodInfo.Method;
            var canWrapResponse = wrapper.CanWrap(instrumentedMethodInfo);

            if (canWrapResponse.AdditionalInformation != null && !canWrapResponse.CanWrap)
            {
                Log.Warn(canWrapResponse.AdditionalInformation);
            }
            if (canWrapResponse.AdditionalInformation != null && canWrapResponse.CanWrap)
            {
                Log.Info(canWrapResponse.AdditionalInformation);
            }

            if (canWrapResponse.CanWrap)
            {
                Log.Debug($"Wrapper \"{wrapper.GetType().FullName}\" will be used for instrumented method \"{method.Type}.{method.MethodName}\"");
            }

            return(canWrapResponse.CanWrap);
        }
Example #21
0
        public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
        {
            var method = methodInfo.Method;

            var version = method.Type.Assembly.GetName().Version;

            if (version == null)
            {
                return(new CanWrapResponse(false));
            }

            var canWrap = method.MatchesAny(assemblyName: "System.Web.Http", typeName: "System.Web.Http.Controllers.ApiControllerActionInvoker", methodName: "InvokeActionAsync") &&
                          version.Major == 4; // WebApi v1 == System.Web.Http v4

            if (canWrap)
            {
                return(TaskFriendlySyncContextValidator.CanWrapAsyncMethod("System.Web.Http", "System.Web.Http.Controllers.ApiControllerActionInvoker", method.MethodName));
            }

            return(new CanWrapResponse(false));
        }
Example #22
0
        public TrackedWrapper Get(InstrumentedMethodInfo instrumentedMethodInfo)
        {
            //Then, see if there's a standard wrapper supporting this method
            foreach (var wrapper in _nonDefaultWrappers)
            {
                if (CanWrap(instrumentedMethodInfo, wrapper))
                {
                    return(new TrackedWrapper(wrapper));
                }
            }

            //Next, check to see if one of the dynamic wrappers can be used
            foreach (var wrapper in ExtensionsLoader.TryGetDynamicWrapperInstance(instrumentedMethodInfo.RequestedWrapperName))
            {
                if (CanWrap(instrumentedMethodInfo, wrapper))
                {
                    return(new TrackedWrapper(wrapper));
                }
            }

            //Otherwise, return one of our defaults or a NoOp
            return(GetDefaultWrapperOrSetNoOp(instrumentedMethodInfo));
        }
Example #23
0
        public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
        {
            var method  = methodInfo.Method;
            var canWrap = method.MatchesAny(assemblyName: "MongoDB.Driver", typeName: "MongoDB.Driver.MongoCollection",
                                            methodSignatures: new[]
            {
                new MethodSignature("Aggregate"),
                new MethodSignature("CreateIndex", "MongoDB.Driver.IMongoIndexKeys,MongoDB.Driver.IMongoIndexOptions"),
                new MethodSignature("Drop"),
                new MethodSignature("FindAndModify"),
                new MethodSignature("FindAndRemove"),
                new MethodSignature("GetIndexes"),
                new MethodSignature("IndexExistsByName"),
                new MethodSignature("InitializeOrderedBulkOperation"),
                new MethodSignature("InitializeUnorderedBulkOperation"),
                new MethodSignature("ParallelScanAs", "MongoDB.Driver.ParallelScanArgs"),
                new MethodSignature("Save", "System.Type,System.Object,MongoDB.Driver.MongoInsertOptions"),
                new MethodSignature("Update", "MongoDB.Driver.IMongoQuery,MongoDB.Driver.IMongoUpdate,MongoDB.Driver.MongoUpdateOptions"),
                new MethodSignature("Validate", "MongoDB.Driver.ValidateCollectionArgs")
            });

            return(new CanWrapResponse(canWrap));
        }
        public void AfterWrappedMethod_SetsNoOpWhenThrowsExceptionTooManyTimes()
        {
            var wrapper        = Mock.Create <IWrapper>();
            var trackedWrapper = new TrackedWrapper(wrapper);

            var wrapperMap = new WrapperMap(new List <IWrapper> {
                wrapper
            }, _defaultWrapper, _noOpWrapper);

            Mock.Arrange(() => wrapper.BeforeWrappedMethod(Arg.IsAny <InstrumentedMethodCall>(), Arg.IsAny <IAgent>(), Arg.IsAny <ITransaction>())).Returns((result, exception) => { throw new Exception(); });
            Mock.Arrange(() => _configurationService.Configuration.WrapperExceptionLimit).Returns(1);

            var          type              = typeof(System.Web.HttpApplication);
            const string methodName        = "ExecuteStep";
            const string tracerFactoryName = "NewRelic.Agent.Core.Tracer.Factories.DefaultTracerFactory";
            var          invocationTarget  = new object();
            var          arguments         = new object[2];
            var          argumentSignature = "IExecutionStep,System.Boolean&";
            var          metricName        = string.Empty;

            var method     = new Method(type, methodName, argumentSignature);
            var methodCall = new MethodCall(method, invocationTarget, arguments);
            var info       = new InstrumentedMethodInfo(0, methodCall.Method, tracerFactoryName, false, null, null, false);

            Mock.Arrange(() => wrapper.CanWrap(info)).Returns(new CanWrapResponse(true));

            var wrapperService = new WrapperService(_configurationService, wrapperMap, _agent, _agentHealthReporter, _agentTimerService);

            var afterWrappedMethod1 = wrapperService.BeforeWrappedMethod(type, methodName, argumentSignature, invocationTarget, arguments, tracerFactoryName, metricName, EmptyTracerArgs, 0);

            Assert.Throws <Exception>(() => afterWrappedMethod1(null, null));

            var afterWrappedMethod2 = wrapperService.BeforeWrappedMethod(type, methodName, argumentSignature, invocationTarget, arguments, tracerFactoryName, metricName, EmptyTracerArgs, 0);

            Assert.DoesNotThrow(() => afterWrappedMethod2(null, null));
        }
        public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
        {
            var method = methodInfo.Method;

            var canWrap = method.MatchesAny(assemblyName: "MongoDB.Driver", typeName: "MongoDB.Driver.MongoDatabaseImpl",
                                            methodNames: new[]
            {
                "CreateCollection",
                "CreateView",
                "DropCollection",
                "ListCollections",
                "RenameCollection",
                "RunCommand",

                "CreateCollectionAsync",
                "CreateViewAsync",
                "DropCollectionAsync",
                "ListCollectionsAsync",
                "RenameCollectionAsync",
                "RunCommandAsync"
            });

            return(new CanWrapResponse(canWrap));
        }
Example #26
0
 public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
 {
     return(new CanWrapResponse(WrapperName.Equals(methodInfo.RequestedWrapperName)));
 }
 public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
 {
     return(new CanWrapResponse("NewRelic.Providers.Wrapper.AspNetCore.InvokeActionMethodAsync".Equals(methodInfo.RequestedWrapperName)));
 }
Example #28
0
 public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
 {
     return(new CanWrapResponse(WrapperNames.Contains(methodInfo.RequestedWrapperName, StringComparer.OrdinalIgnoreCase)));
 }
 public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
 {
     return(new CanWrapResponse("GenericHostWebHostBuilderExtensionsWrapper".Equals(methodInfo.RequestedWrapperName)));
 }
 public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)
 {
     return(new CanWrapResponse(methodInfo.RequestedWrapperName.Equals(WrapperName, StringComparison.OrdinalIgnoreCase)));
 }