Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add Exception Filter trace #482

Closed
wants to merge 1 commit into from

2 participants

@suwatch
Owner

There are two service implementation in Kudu.

  1. IHttpHandler
  2. APIController

For HttpHandler, the runnaway exception is handled by TraceModule (see onError). For APIController (this PR), it is handled by TraceExceptionFilter.

@davidebbo davidebbo commented on the diff
...Services.Web/Tracing/TraceExceptionFilterAttribute.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Diagnostics;
+using System.Web.Http.Filters;
+using Kudu.Contracts.Tracing;
+
+namespace Kudu.Services.Web.Tracing
+{
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
+ public sealed class TraceExceptionFilterAttribute : ExceptionFilterAttribute
+ {
+ public override void OnException(HttpActionExecutedContext context)
+ {
+ ITracer tracer = TraceServices.CurrentRequestTracer;
@davidebbo Owner

That's the magic line I was missing when I tried to do it. Getting injection to work is pretty tricky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@davidebbo
Owner

:shipit:

@suwatch suwatch closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 22, 2013
  1. @suwatch

    add Exception Filter trace

    suwatch authored
This page is out of date. Refresh to see the latest.
View
1  Kudu.Services.Web/App_Start/NinjectServices.cs
@@ -196,6 +196,7 @@ public static void RegisterRoutes(IKernel kernel, RouteCollection routes)
var jsonFormatter = new JsonMediaTypeFormatter();
GlobalConfiguration.Configuration.Formatters.Add(jsonFormatter);
GlobalConfiguration.Configuration.DependencyResolver = new NinjectWebApiDependencyResolver(kernel);
+ GlobalConfiguration.Configuration.Filters.Add(new TraceExceptionFilterAttribute());
// Git Service
routes.MapHttpRoute("git-info-refs-root", "info/refs", new { controller = "InfoRefs", action = "Execute" });
View
1  Kudu.Services.Web/Kudu.Services.Web.csproj
@@ -139,6 +139,7 @@
<Compile Include="Security\BlockLocalhostModule.cs" />
<Compile Include="Services\DeploymentEnvironment.cs" />
<Compile Include="Services\NinjectWebApiDependencyResolver.cs" />
+ <Compile Include="Tracing\TraceExceptionFilterAttribute.cs" />
<Compile Include="Tracing\TraceModule.cs" />
<Compile Include="Tracing\TraceServices.cs" />
<Compile Include="App_Start\NinjectServices.cs" />
View
23 Kudu.Services.Web/Tracing/TraceExceptionFilterAttribute.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Diagnostics;
+using System.Web.Http.Filters;
+using Kudu.Contracts.Tracing;
+
+namespace Kudu.Services.Web.Tracing
+{
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
+ public sealed class TraceExceptionFilterAttribute : ExceptionFilterAttribute
+ {
+ public override void OnException(HttpActionExecutedContext context)
+ {
+ ITracer tracer = TraceServices.CurrentRequestTracer;
@davidebbo Owner

That's the magic line I was missing when I tried to do it. Getting injection to work is pretty tricky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ if (tracer == null || tracer.TraceLevel <= TraceLevel.Off)
+ {
+ return;
+ }
+
+ tracer.TraceError(context.Exception);
+ }
+ }
+}
Something went wrong with that request. Please try again.