Created
September 2, 2012 20:50
-
-
Save thefringeninja/3604430 to your computer and use it in GitHub Desktop.
New Relic + Nancy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using NewRelicAgent = NewRelic.Api.Agent.NewRelic; // protip: don't give class and namespace the same name. it's awkward. | |
public class NewRelicStartup : IStartup | |
{ | |
private readonly IRouteResolver routeResolver; | |
public NewRelicStartup(IRouteResolver routeResolver) | |
{ | |
this.routeResolver = routeResolver; | |
} | |
public void Initialize(IPipelines pipelines) | |
{ | |
pipelines.BeforeRequest.AddItemToStartOfPipeline( | |
context => | |
{ | |
var route = routeResolver.Resolve(context); | |
if (route == null || route.Item1 == null || route.Item1.Description == null) // probably not necessary but don't want the chance of losing visibility on anything | |
{ | |
NewRelicAgent.SetTransactionName( | |
context.Request.Method, | |
context.Request.Url.ToString()); | |
} | |
else | |
{ | |
NewRelicAgent.SetTransactionName( | |
route.Item1.Description.Method, | |
route.Item1.Description.Path); | |
} | |
return null; | |
}); | |
pipelines.OnError.AddItemToEndOfPipeline( | |
(context, ex) => | |
{ | |
NewRelicAgent.NoticeError( | |
ex); | |
return null; | |
}); | |
} | |
public IEnumerable<TypeRegistration> TypeRegistrations { get { return null; } } | |
public IEnumerable<CollectionTypeRegistration> CollectionTypeRegistrations { get { return null; } } | |
public IEnumerable<InstanceRegistration> InstanceRegistrations { get { return null; } } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment