Akka Http Logging with traceId

1,115 views
Skip to first unread message

Arun

unread,
Sep 13, 2016, 1:48:23 AM9/13/16
to Akka User List
Hi,

We have a requirement where we need to log information with traceId (or unique identifier) for  a given HTTP request across route and actors. This can help us to trace logging.

The configuration is as following:

akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = "INFO"
logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
}

and logback.xml is as following:

<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<includeContext>true</includeContext>
<fieldNames>
<timestamp>@timestamp</timestamp>
<message>msg</message>
<thread>[ignore]</thread>
<levelValue>[ignore]</levelValue>
<logger>logger</logger>
<version>[ignore]</version>
</fieldNames>
<throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
<maxDepthPerThrowable>80</maxDepthPerThrowable>
<maxLength>2048</maxLength>
<shortenedClassNameLength>20</shortenedClassNameLength>
<rootCauseFirst>true</rootCauseFirst>
</throwableConverter>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>

Please let me know how we can enable traceId from route to actor systems.

Thanks
Arun

algermissen1971

unread,
Sep 13, 2016, 1:57:58 AM9/13/16
to akka...@googlegroups.com
Hi Arun

Take a look at kamon.io

Jan

Sent from my iPhone
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Arun

unread,
Sep 13, 2016, 2:57:21 AM9/13/16
to Akka User List
Thanks Jan.

I am looking for something similar to http://code.hootsuite.com/logging-contextual-info-in-an-asynchronous-scala-application/ , I could able to find that either by using custom akka dispatcher or custom execution context, we can achieve the same, but I would prefer anything I can do with minimal changes in akka default behaviour. 

Using MDC with Logback; the logback uses a ThreadLocal variable and this works when one thread is used for one request, in case of Akka asynchronous communication happens across multiple threads.

Thanks
Arun

Yann Simon

unread,
Sep 13, 2016, 3:53:48 AM9/13/16
to Akka User List
I wrote that some times ago: http://yanns.github.io/blog/2014/05/04/slf4j-mapped-diagnostic-context-mdc-with-play-framework/
I use a somewhat modified version of that, but it works only with Futures.
With actors (and akka-stream and akka-http), I think that you only have 2 options:
- use kamon.io
- propagating a "context" yourself, and using a custom Logger that reads from this context

Yann

Konrad Malawski

unread,
Sep 13, 2016, 4:03:39 AM9/13/16
to akka...@googlegroups.com, Arun
Reactive Monitoring is able to propagate MDC across Actors:

-- 
Konrad `ktoso` Malawski
Akka @ Lightbend

Arun

unread,
Sep 13, 2016, 4:28:00 AM9/13/16
to Akka User List
Thanks Yann. Let me explore these options. 

As per akka documentation http://doc.akka.io/docs/akka/2.4.10/scala/logging.html , can I use "sourceThread" as traceid?

Regards,
Arun

Yann Simon

unread,
Sep 13, 2016, 4:32:46 AM9/13/16
to Akka User List
I don't think so.
The source thread is the thread used to handle the message, as the log is done in another actor (and maybe in another thread).

Arun

unread,
Sep 13, 2016, 6:49:19 AM9/13/16
to Akka User List
Thanks Yann and Jan.

The kamon looks clean way of implementation, the page also talks about http://kamon.io/integrations/logback/mdc-in-an-asyncronous-environment/  the way you have describe in your blog as well. 

I am going ahead with kamon.

Thanks to everyone. 

Regards,
Arun
Reply all
Reply to author
Forward
0 new messages