Skip to content

Instantly share code, notes, and snippets.

@thefringeninja
Created September 2, 2012 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thefringeninja/3604430 to your computer and use it in GitHub Desktop.
Save thefringeninja/3604430 to your computer and use it in GitHub Desktop.
New Relic + Nancy
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