本文介绍了使用NewRelic对.Net中的通用类进行自定义检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

有什么方法可以通过新的自定义自定义指令在.Net中检测通用类?我像对非通用类一样添加了检测配置,但是没有运气.

解决方案

您将需要使用IL签名.确定签名的最佳方法是在newrelic.config中将"New Relic"日志记录设置为"all",运行您的应用程序,然后在相应的探查器日志中搜索方法名称(确保在完成后将日志记录设置回info)

使用签名,您可以构建自定义工具自定义交易.. >

使用示例代码:

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var t = new Test<int>();
            while (true)
            {
                StartTransaction();
                t.mymethod(100);
            }
        }
        static void StartTransaction()
        {
            Console.WriteLine("Start Transaction");
            System.Threading.Thread.Sleep(1100);
            MethodA();
        }
        static void MethodA()
        {
            Console.WriteLine("MethodA");
        }
    }
    class Test<T>
    {
        public void mymethod(T t) {
            var k = t;
            System.Threading.Thread.Sleep(1000);
        }
    }
}

在分析器日志NewRelic.Profiler.[pid]中,其中[pid]对应于运行您的应用程序的w3wp进程或其他进程,您将看到以下内容:

[Trace]Possibly instrumenting: (Module: C:\Users\me\Documents\Visual Studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe, AppDomain: ConsoleApplication1.exe)[ConsoleApplication1]ConsoleApplication1.Test`1.mymethod

没有扩展名 ConsoleApplication1 的AppDomain和类/方法名 ConsoleApplication1.Test`1.mymethod 都是构建自定义工具/事务所必需的.

示例(自定义交易):

<?xml version="1.0" encoding="utf-8"?>
<extension xmlns="urn:newrelic-extension">
    <instrumentation>
      <tracerFactory name="NewRelic.Agent.Core.Tracer.Factories.BackgroundThreadTracerFactory" metricName="Background/MyTaskRunner">
        <match assemblyName="ConsoleApplication1" className="ConsoleApplication.Test`1">
          <exactMethodMatcher methodName="mymethod" />
        </match>
      </tracerFactory>
    </instrumentation>
</extension>

通常,您不需要在检测文件中指定方法参数.

Is there any way to instrument generic classes in .Net with new relic custom instrumenation? I added the instrumentation config like I do for non generic classes but with no luck.

解决方案

You will need to use an IL signature. The best way to determine the signature is to turn up New Relic logging to 'all' in newrelic.config, run your app and then search the corresponding profiler log for the method name (make sure to set the logging back to info when finished).

Using the signature you can the build Custom Instrumentation and Custom Transactions.

Using example code:

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var t = new Test<int>();
            while (true)
            {
                StartTransaction();
                t.mymethod(100);
            }
        }
        static void StartTransaction()
        {
            Console.WriteLine("Start Transaction");
            System.Threading.Thread.Sleep(1100);
            MethodA();
        }
        static void MethodA()
        {
            Console.WriteLine("MethodA");
        }
    }
    class Test<T>
    {
        public void mymethod(T t) {
            var k = t;
            System.Threading.Thread.Sleep(1000);
        }
    }
}

Looking in the profiler log, NewRelic.Profiler.[pid] where [pid] corresponds to the w3wp process or other process running your application, you would see the following:

[Trace]Possibly instrumenting: (Module: C:\Users\me\Documents\Visual Studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe, AppDomain: ConsoleApplication1.exe)[ConsoleApplication1]ConsoleApplication1.Test`1.mymethod

The AppDomain without the extension ConsoleApplication1 and the class/method name ConsoleApplication1.Test`1.mymethod are needed to build the custom instrumentation/transaction.

Example (custom transaction):

<?xml version="1.0" encoding="utf-8"?>
<extension xmlns="urn:newrelic-extension">
    <instrumentation>
      <tracerFactory name="NewRelic.Agent.Core.Tracer.Factories.BackgroundThreadTracerFactory" metricName="Background/MyTaskRunner">
        <match assemblyName="ConsoleApplication1" className="ConsoleApplication.Test`1">
          <exactMethodMatcher methodName="mymethod" />
        </match>
      </tracerFactory>
    </instrumentation>
</extension>

In general you don't need to specify method parameters in the instrumentation file.

这篇关于使用NewRelic对.Net中的通用类进行自定义检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 21:44