Skip to content

Proof of concept of mdc propagation in akka-http using kamon.io

License

Notifications You must be signed in to change notification settings

kamkor/akka-http-mdc-logging-kamon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

akka-http-mdc-logging-kamon proof of concept

I am evaluating akka-http as technology for writing some microservices at work. Being able to propagate requestId and some other parameters in MDC is very important to me. And since MDC doesn't really fit well in asynchronous environment, it can be quite tricky to propagate it in library like akka-http.

In this repository I am trying to propagate requestId in MDC with the help of kamon.io. I have very little experience with akka-http and kamon.io. This repository is just my proof of concept for my evaluation of akka-http. I will try to improve the solution, and if I can't then I will try something else.

Cons of current solution:

Todo

  • Make sure that propagation of TraceContext/MDC also works in the exception handler.
  • Write proper tests that verify that propagation works. Currently I have only tested it manually using curl, bash script, logs and my eyes. ;)

How to run

sbt aspectj-runner:run

curl -X GET -H "request-id: 321" "http://localhost:8080/greet/kamkor"

sh batchcurl.sh 20 where 20 is number of curls to execute

Example output

akka.io.TcpListener mdcReqId[] New connection accepted
me.kamkor.web.GreetEndpoint mdcReqId[321] reqId[321] thread[system-akka.actor.default-dispatcher-3] parsed request
me.kamkor.actor.GreetActor mdcReqId[321] reqId[321] thread[system-akka.greet-actor-dispatcher-6] Greet message
me.kamkor.actor.GreetActor mdcReqId[321] reqId[321] thread[pool-5-thread-5] generateGreet Future
me.kamkor.web.GreetEndpoint mdcReqId[321] reqId[321] thread[system-akka.actor.default-dispatcher-4] completing request
me.kamkor.actor.GreetActor mdcReqId[321] reqId[321] thread[system-akka.greet-actor-dispatcher-6] GeneratedGreetMsg message

Note that GreetEndpoint, GreetActor and future execution in GreetActor use different execution contexts. GreetEndpoint uses default akka dispatcher. GreetActor uses its own akka dispatcher and Future in GreetActor is executed in custom ExecutionContext.

About

Proof of concept of mdc propagation in akka-http using kamon.io

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published