diff options
author | Vlad Uspensky <v.uspenskiy@icloud.com> | 2017-05-25 17:23:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-25 17:23:12 -0700 |
commit | ec4848d56ac89d55cf7c38f075f028f219a5ffc9 (patch) | |
tree | 9f9c765cdcd31178f1ea0d983bb563b0d68c45e8 /src/main/scala/xyz/driver/core/rest.scala | |
parent | 0a3438068e4b853e4c42f83a4eb304ae53382e51 (diff) | |
parent | 3dfb989d221d0f121404adaac0d970228fa180a5 (diff) | |
download | driver-core-ec4848d56ac89d55cf7c38f075f028f219a5ffc9.tar.gz driver-core-ec4848d56ac89d55cf7c38f075f028f219a5ffc9.tar.bz2 driver-core-ec4848d56ac89d55cf7c38f075f028f219a5ffc9.zip |
Merge pull request #39 from drivergroup/http-stacktrace
Http stacktracing using headers to see which hosts this request was passing
Diffstat (limited to 'src/main/scala/xyz/driver/core/rest.scala')
-rw-r--r-- | src/main/scala/xyz/driver/core/rest.scala | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/main/scala/xyz/driver/core/rest.scala b/src/main/scala/xyz/driver/core/rest.scala index 6944cf7..15c6d83 100644 --- a/src/main/scala/xyz/driver/core/rest.scala +++ b/src/main/scala/xyz/driver/core/rest.scala @@ -21,6 +21,7 @@ import io.swagger.models.Scheme import pdi.jwt.{Jwt, JwtAlgorithm} import xyz.driver.core.auth._ import xyz.driver.core.time.provider.TimeProvider +import org.slf4j.MDC import scala.concurrent.{ExecutionContext, Future} import scala.util.{Failure, Success} @@ -44,10 +45,13 @@ package rest { .fold(java.util.UUID.randomUUID.toString)(_.value()) } + def extractStacktrace(request: HttpRequest): Array[String] = + request.headers.find(_.name == ContextHeaders.StacktraceHeader).fold("")(_.value()).split("->") + def extractContextHeaders(request: HttpRequest): Map[String, String] = { request.headers.filter { h => h.name === ContextHeaders.AuthenticationTokenHeader || h.name === ContextHeaders.TrackingIdHeader || - h.name === ContextHeaders.PermissionsTokenHeader + h.name === ContextHeaders.PermissionsTokenHeader || h.name === ContextHeaders.StacktraceHeader } map { header => if (header.name === ContextHeaders.AuthenticationTokenHeader) { header.name -> header.value.stripPrefix(ContextHeaders.AuthenticationHeaderPrefix).trim @@ -155,6 +159,7 @@ package rest { val PermissionsTokenHeader = "Permissions" val AuthenticationHeaderPrefix = "Bearer" val TrackingIdHeader = "X-Trace" + val StacktraceHeader = "X-Stacktrace" } object AuthProvider { @@ -358,9 +363,15 @@ package rest { val requestTime = time.currentTime() val request = requestStub - .withHeaders(RawHeader(ContextHeaders.TrackingIdHeader, context.trackingId)) - .withHeaders(context.contextHeaders.toSeq.map { h => - RawHeader(h._1, h._2): HttpHeader + .withHeaders(context.contextHeaders.toSeq.map { + case (ContextHeaders.TrackingIdHeader, headerValue) => + RawHeader(ContextHeaders.TrackingIdHeader, context.trackingId) + case (ContextHeaders.StacktraceHeader, headerValue) => + RawHeader(ContextHeaders.StacktraceHeader, + Option(MDC.get("stack")) + .orElse(context.contextHeaders.get(ContextHeaders.StacktraceHeader)) + .getOrElse("")) + case (header, headerValue) => RawHeader(header, headerValue) }: _*) log.info(s"Sending request to ${request.method} ${request.uri}") |