Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServiceStack with NewRelic monitoring

Does anyone have sample code for a ServiceStack Api that successfully reports transactions into NewRelic?

This doesn't appear to be trivial – it doesn't happen out of the box, and adding a RequestFilter that calls NewRelic.Api.Agent.NewRelic.SetTransactionName doesn't change that.

The server and apps seem to be configured correctly - the other apps (ASP WebForms and ASP MVC) on the same IIS server are reporting correctly. We are using IIS 7.5. Each app is in its own app pool and has a NewRelic.AppName in the web.config

like image 653
Anthony Avatar asked Nov 29 '13 14:11

Anthony


2 Answers

I work at New Relic.

In addition to what @mythz said, I wanted to confirm that you've got the app pool configured separately (so you're not seeing the transactions in one of your other monitored pools) - you have set up a Web.config file with a separate application name (NewRelic.AppName setting) for this pool, right?

Assuming yes, and that you are seeing at least an agent startup event in the logs for the agent from that pool, I can verify that we've heard the same from other customers, though it's been awhile since we last visited the issue. Better automatic support for ServiceStack is on the horizon but I don't have an ETA.

When working with one customer experiencing this issue, we found that ServiceStack was calling into our agent for some reason. The solution that worked for them was to override ServiceStack's implementation of AppHostBase.Release in the project and validate the object that is to be released if it is a New Relic instance. They overrode it in the web service project's AppHost (AppHost template is in your project at App_Start\AppHost.cs), like this:

public override void Release(object instance)

{

    if (instance.GetType().ToString().StartsWith("NewRelic.Agent", StringComparison.CurrentCultureIgnoreCase))

        return;



    base.Release(instance);

}

In case this doesn't lead to a solution, if you could open a support ticket at https://support.newrelic.com, we could work with you further to get these stats tracked or at least get you on the notification list when we improve servicestack support.

like image 73
fool Avatar answered Oct 10 '22 06:10

fool


I've never used NewRelic but it might help if you set the transaction name as early as possible in ServiceStack's Request Pipeline, e.g in the RawHttpHandlers in AppHost with:

RawHttpHandlers.Add(httpReq => {
    NewRelic.Api.Agent.NewRelic.SetTransactionName(
        httpReq.HttpMethod, httpReq.AbsoluteUri);
});

or in older ServiceStack v3 with:

SetConfig(new EndpointHostConfig
{
    RawHttpHandlers = {
        httpReq => {
            NewRelic.Api.Agent.NewRelic.SetTransactionName(
                httpReq.HttpMethod, httpReq.AbsoluteUri);
            return null;
        } 
    }
});
like image 10
mythz Avatar answered Oct 10 '22 06:10

mythz