Skip to content

Commit

Permalink
address review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
lacarvalho91 committed May 23, 2020
1 parent 6bb9b9b commit da53f7d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@ package kamon.akka.http

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.headers.RawHeader
import akka.http.scaladsl.model.HttpRequest
import akka.http.scaladsl.model.headers.RawHeader
import akka.stream.ActorMaterializer
import kamon.Kamon
import kamon.testkit._
import kamon.trace.Span
import kamon.tag.Lookups.{plain, plainBoolean, plainLong}
import okhttp3.Request
import org.scalatest.concurrent.Eventually
import org.scalatest.{BeforeAndAfterAll, Matchers, OptionValues, WordSpecLike}
import kamon.testkit._
import org.json4s._
import org.json4s.native.JsonMethods._
import org.scalatest.concurrent.Eventually
import org.scalatest.{BeforeAndAfterAll, Matchers, OptionValues, WordSpecLike}

import scala.concurrent.duration._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ package kamon.akka.http
import java.util.UUID

import akka.actor.ActorSystem
import akka.http.scaladsl.UseHttp2
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.stream.ActorMaterializer
import javax.net.ssl.{HostnameVerifier, SSLSession}
import kamon.testkit._
import kamon.tag.Lookups.{plain, plainBoolean, plainLong}
import kamon.testkit._
import kamon.trace.Span.Mark
import okhttp3.{OkHttpClient, Request}
import org.scalatest._
import org.scalatest.concurrent.{Eventually, ScalaFutures}

import scala.concurrent.duration._
import okhttp3.{OkHttpClient, Request}

class AkkaHttpServerTracingSpec extends WordSpecLike with Matchers with ScalaFutures with Inside with BeforeAndAfterAll
with MetricInspection.Syntax with Reconfigure with TestWebServer with Eventually with OptionValues with TestSpanReporter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package http
import com.typesafe.config.Config
import kamon.context.Context
import kamon.instrumentation.http.HttpClientInstrumentation.Settings
import kamon.instrumentation.http.HttpInstrumentation.OperationNameSettings
import kamon.instrumentation.tag.TagKeys
import kamon.instrumentation.trace.SpanTagger
import kamon.instrumentation.trace.SpanTagger.TagMode
Expand Down Expand Up @@ -133,7 +132,7 @@ object HttpClientInstrumentation {

private def createClientSpan(requestMessage: HttpMessage.Request, context: Context): Span = {
val span = Kamon
.clientSpanBuilder(HttpInstrumentation.operationName(settings.operationNameSettings, requestMessage), component)
.clientSpanBuilder(settings.operationNameSettings.operationName(requestMessage), component)
.context(context)

if(!settings.enableSpanMetrics)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import java.time.Duration

import com.typesafe.config.Config
import kamon.context.Context
import kamon.instrumentation.http.HttpInstrumentation.OperationNameSettings
import kamon.instrumentation.http.HttpServerInstrumentation.Settings
import kamon.instrumentation.trace.SpanTagger.TagMode
import kamon.instrumentation.tag.TagKeys
Expand Down Expand Up @@ -296,7 +295,7 @@ object HttpServerInstrumentation {


private def buildServerSpan(context: Context, request: HttpMessage.Request, deferSamplingDecision: Boolean): Span = {
val span = Kamon.serverSpanBuilder(HttpInstrumentation.operationName(settings.operationNameSettings, request), component)
val span = Kamon.serverSpanBuilder(settings.operationNameSettings.operationName(request), component)
span.context(context)

if(!settings.enableSpanMetrics)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package kamon.instrumentation.http

import kamon.util.Filter

final case class OperationNameSettings(defaultOperationName: String,
operationMappings: Map[Filter.Glob, String],
operationNameGenerator: HttpOperationNameGenerator) {
private[http] def operationName(request: HttpMessage.Request): String = {
val requestPath = request.path
//first apply any mappings rules
val customMapping = operationMappings.collectFirst {
case (pattern, operationName) if pattern.accept(requestPath) => operationName
}.orElse( //fallback to use any configured name generator
operationNameGenerator.name(request)
)
customMapping.getOrElse(defaultOperationName)
}
}

0 comments on commit da53f7d

Please sign in to comment.