-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finagle-http: record binary annotations when spans complete
Problem: It would be useful to record more high-level information when spans complete Solution: Add the following annotations: ``` http.status_code = int (HTTP code.... 400/500/200 etc...) http.method String (HTTP method...ie POST, GET) ``` JIRA Issues: CSL-10325 Differential Revision: https://phabricator.twitter.biz/D580894
- Loading branch information
1 parent
debefa8
commit 78d93fd
Showing
5 changed files
with
77 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
finagle-http/src/main/scala/com/twitter/finagle/http/filter/HttpTracingFilter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.twitter.finagle.http.filter | ||
|
||
import com.twitter.finagle._ | ||
import com.twitter.finagle.tracing.{Trace, Tracing} | ||
import com.twitter.util.Future | ||
|
||
private[finagle] object HttpTracingFilter extends SimpleFilter[http.Request, http.Response] { | ||
val Role: Stack.Role = Stack.Role("HttpTracing") | ||
def apply( | ||
request: http.Request, | ||
service: Service[http.Request, http.Response] | ||
): Future[http.Response] = { | ||
val tracing = Trace() | ||
val rep = service(request) | ||
traceHttpRequest(request, tracing) | ||
traceHttpResponse(rep, tracing) | ||
rep | ||
} | ||
|
||
def traceHttpRequest(request: http.Request, tracing: Tracing): Unit = { | ||
if (tracing.isActivelyTracing) { | ||
tracing.recordRpc(request.method.toString) | ||
tracing.recordBinary("http.method", request.method.toString) | ||
tracing.recordBinary("http.uri", stripParameters(request.uri)) | ||
} | ||
} | ||
|
||
def traceHttpResponse(rep: Future[http.Response], tracing: Tracing): Unit = { | ||
if (tracing.isActivelyTracing) { | ||
rep.onSuccess { r => | ||
tracing.recordBinary("http.status_code", r.statusCode) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Remove any parameters from url. | ||
*/ | ||
private[this] def stripParameters(uri: String): String = { | ||
uri.indexOf('?') match { | ||
case -1 => uri | ||
case n => uri.substring(0, n) | ||
} | ||
} | ||
|
||
/** | ||
* Creates a [[com.twitter.finagle.Stackable]] `HttpTracingFilter` which will add binary | ||
* annotations `http.uri`, `http.status_code`, and `http.method` to completed http spans. | ||
*/ | ||
def module: Stackable[ServiceFactory[http.Request, http.Response]] = | ||
new Stack.Module0[ServiceFactory[http.Request, http.Response]] { | ||
val role = HttpTracingFilter.Role | ||
val description = "Record http annotation for completed spans" | ||
def make( | ||
next: ServiceFactory[http.Request, http.Response] | ||
): ServiceFactory[http.Request, http.Response] = { | ||
HttpTracingFilter.andThen(next) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters