Skip to content

Instantly share code, notes, and snippets.

@adamw
Last active November 25, 2018 07:57
Show Gist options
  • Save adamw/437344352d9e47c545da08e1a4243680 to your computer and use it in GitHub Desktop.
Save adamw/437344352d9e47c545da08e1a4243680 to your computer and use it in GitHub Desktop.
object CorrelationId {
val CorrelationIdHeader = "X-Correlation-ID"
def setCorrelationIdMiddleware(service: HttpRoutes[Task]): HttpRoutes[Task] =
Kleisli { req: Request[Task] =>
val cid = req.headers.get(CaseInsensitiveString(CorrelationIdHeader)) match {
case None => newCorrelationId()
case Some(cidHeader) => cidHeader.value
}
localCid.update(Some(cid))
logger.info("Starting request")
service(req)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment