Skip to content

Commit

Permalink
Adjust tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldraper committed Mar 13, 2017
1 parent 9b10d63 commit f3fab0b
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 62 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class Filters extends DefaultHttpFilters(
new DefaultTracingFilter(
new ContentTagger, // content headers
new HttpVersionTagger, // HTTP version
new RemoteSpanTagger, // remote address
new StandardSpanTagger("myapp"), // standard OpenTracing tags
new StandardSpanTagger, // standard OpenTracing tags
new TagsSpanTagger(_ => true) // Play request tags
)
)
Expand Down
22 changes: 0 additions & 22 deletions play/src/main/scala/io/opentracing/play/IpAddressTagger.scala

This file was deleted.

29 changes: 0 additions & 29 deletions play/src/main/scala/io/opentracing/play/RemoteSpanTagger.scala

This file was deleted.

16 changes: 12 additions & 4 deletions play/src/main/scala/io/opentracing/play/StandardSpanTagger.scala
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package io.opentracing.play

import com.google.common.net.InetAddresses
import io.opentracing.Span
import io.opentracing.tag.Tags
import java.net.{Inet4Address, Inet6Address}
import java.nio.ByteBuffer
import play.api.mvc.{RequestHeader, Result}
import scala.util.Try

/**
* Applies standard tags
* @see https://raw.githubusercontent.com/opentracing/specification/1.0/data_conventions.yaml
*/
class StandardSpanTagger(name: Option[String] = None) extends SpanTagger {
class StandardSpanTagger extends SpanTagger {
def tag(span: Span, request: RequestHeader, result: Result) = {
name.foreach(Tags.PEER_SERVICE.set(span, _))
Tags.HTTP_METHOD.set(span, request.method)
Tags.HTTP_STATUS.set(span, result.header.status)
Tags.HTTP_URL.set(span, request.uri)
Tags.PEER_HOSTNAME.set(span, request.domain)
//Tags.PEER_PORT.set(span, request.host.split(":").lift(1).fold(if (request.secure) 443.toShort else 80.toShort)(_.toShort))
request.headers.get("X-Forwarded-Port").flatMap(port => Try(port.toInt.toShort).toOption)
.foreach(Tags.PEER_PORT.set(span, _))
Try(InetAddresses.forString(request.remoteAddress)).foreach {
case ip: Inet4Address => Tags.PEER_HOST_IPV4.set(span, ByteBuffer.wrap(ip.getAddress).getInt)
case ip: Inet6Address => Tags.PEER_HOST_IPV6.set(span, ip.getHostAddress.takeWhile(_ != "%"))
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class TracingFilter(contextSpan: ContextSpan, taggers: Traversable[Span
protected[this] def tracer: Tracer

def apply(next: EssentialAction) = EssentialAction { request =>
val span = tracer.buildSpan(Routes.endpointName(request).getOrElse(request.method))
val span = tracer.buildSpan(Routes.endpointName(request).getOrElse(s"HTTP ${request.method}"))
.asChildOf(tracer.extract(Format.Builtin.HTTP_HEADERS, new HeadersTextMap(request.headers)))
.withTag(Tags.SPAN_KIND.getKey, Tags.SPAN_KIND_SERVER)
.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class ContentTagger extends SpanTagger {
}

object ContentTagger {
val contentLengthTag = "http.contentLength"
val contentTypeTag = "http.contentType"
val contentLengthTag = "http.response.contentLength"
val contentTypeTag = "http.response.contentType"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class ContentTagger extends SpanTagger {
}

object ContentTagger extends ContentTagger {
val contentLengthTag = "http.contentLength"
val contentTypeTag = "http.contentType"
val contentLengthTag = "http.response.contentLength"
val contentTypeTag = "http.response.contentType"
}

0 comments on commit f3fab0b

Please sign in to comment.