Skip to content

A Mapped Diagnostic Context (MDC) propagation Akka Dispatcher for the asynchronous environment of the Play Framework.

License

Notifications You must be signed in to change notification settings

rishabh9/mdc-propagation-dispatcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Mapped Diagnostic Context (MDC) Propagation Akka Dispatcher

A Mapped Diagnostic Context (MDC) propagation Akka Dispatcher for the asynchronous environment of the Play Framework.

Took the idea from here:

  1. http://yanns.github.io/blog/2014/05/04/slf4j-mapped-diagnostic-context-mdc-with-play-framework/
  2. https://github.com/jroper/thread-local-context-propagation/

The provided code logs an UUID, per request, by default.

Refer the code and customize to your whims and fancy.

Created this project so that I can have the dispatcher in a separate jar, to make my development easier.

How To Use

Add the dependency
libraryDependencies += "com.github.rishabh9" %% "mdc-propagation-dispatcher" % "0.0.8"	
Either add 'MappedDiagnosticContextFilter' to Filters.java
import com.github.rishabh9.MappedDiagnosticContextFilter;

@Singleton
public class Filters implements HttpFilters {
    private final MappedDiagnosticContextFilter mdcFilter;
    
    @Inject
    public Filters(MappedDiagnosticContextFilter mdcFilter) {
        this.mdcFilter = mdcFilter;
    }

    @Override
    public EssentialFilter[] filters() {
        final EssentialFilter[] filters = {
                mdcFilter.asJava()
        };
        return filters;
    }
}
Or annotate your controllers/methods with 'EnableMDC' annotation
import com.github.rishabh9.EnableMDC;
import play.mvc.Controller;

@EnableMDC
public class MyController extends Controller {
 // ...
}
Update your logging configuration
<pattern>%d{HH:mm:ss.SSS} %coloredLevel %logger{35} %mdc{X-UUID:--} - %msg%n%rootException</pattern>
Update your application.conf
play {
  akka {
    actor {
      default-dispatcher {
        type = "com.github.rishabh9.MDCPropagatingDispatcherConfigurator"
      }
    }
  }
}

About

A Mapped Diagnostic Context (MDC) propagation Akka Dispatcher for the asynchronous environment of the Play Framework.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •