0

We use a lot of Finagle Filters and Services in our code. However, we don't support Zipkin in our infrastructure. At times there's a need to trace an incoming request across the chain of Filters/Services, especially in the face of concurrent requests. What's the most non-intrusive way to get such a functionality?

Goal: Would be great if Finagle itself provided an additional apply method like so:

def apply(request: ReqIn, service: Service[ReqOut, RepIn], traceId: String): Future[RepOut]

Then the subclasses could opt-in to using this method instead. The last argument being the identifier that every Filter/Service in the chain could "append to".

override def apply(request, service, traceId): Future[...] = {
  val myTrace = traceId+".me2" // can be logged if needed
  service.apply(..., myTrace)
}

Example:

val chain = FilterA andThen FilterB andThen ServiceP

val response = chain(request, UUID.randomString) // need a way to "seed the request chain with unique string"

The goal is to have something that can uniquely trace/log the series of filter/services effectively. How may I go about by extending Finagle via traits/monkey-patching? Or is this not doable?

PhD
  • 11,202
  • 14
  • 64
  • 112

1 Answers1

0

This can be done using Finagle's Contexts.

Contexts give you access to request-scoped state, such as a request’s deadline, throughout the logical life of a request without requiring them to be explicitly passed

fusion
  • 1,257
  • 10
  • 15
  • I tried using that but I’m not sure I understand the usage from the link. Do you have another/different example? – PhD Oct 14 '19 at 02:04