ServiceStack with NewRelic monitoring
Asked Answered
S

3

15

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

Stereoisomerism answered 29/11, 2013 at 14:42 Comment(0)
T
11

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.

Telescopium answered 29/11, 2013 at 19:59 Comment(2)
FYI, it might help in your troubleshooting that it appears this is also related to the IOC used, e.g. 2 people that had exhibited this issue were both using StructureMap.Zigzagger
for me this was happening with the default Funq container, the above example resolved the issueGravy
Z
10

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;
        } 
    }
});
Zigzagger answered 29/11, 2013 at 16:33 Comment(2)
For those late to the party like me, the above is for SS 3. For SS 4 it is simplified to RawHttpHandlers.Add(httpReq => { etc });Histidine
thanks @mythz. i changed the AbsoluteUri to RawUrl, it made more sense in the new relic ui. i also had to return null (running latest ss).Airlee
M
8

In addition to fool's answer (ensuring the agent instance isn't disposed by SS), if you want New Relic transaction names to match your service DTO names you can do the following:

public class NewRelicIntegrationPlugin : IPlugin
{
    public void Register(IAppHost appHost)
    {
        appHost.RequestFilters.Insert(0, RenameNewRelicTransaction);
    }

    private void RenameNewRelicTransaction(IHttpRequest httpRequest, IHttpResponse httpResponse, object dto)
    {
        if ( dto != null )
            NewRelic.Api.Agent.NewRelic.SetTransactionName("ServiceStack", dto.GetType().Name);
    }
}
Marshallmarshallese answered 20/5, 2014 at 6:1 Comment(2)
I had to change RequestFilters to GlobalRequestFilters in the latest version , 4.5.6Endgame
And IHttpRequest and IHttpResponse to IRequest and IResponse.Astro

© 2022 - 2024 — McMap. All rights reserved.