-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
guard against errors in the HTTP client request instrumentation, fixes …
- Loading branch information
Showing
2 changed files
with
36 additions
and
12 deletions.
There are no files selected for viewing
34 changes: 23 additions & 11 deletions
34
...trumentation-common/src/main/scala/kamon/instrumentation/http/OperationNameSettings.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 |
---|---|---|
@@ -1,18 +1,30 @@ | ||
package kamon.instrumentation.http | ||
|
||
import kamon.util.Filter | ||
import org.slf4j.LoggerFactory | ||
|
||
import scala.util.Try | ||
|
||
final case class OperationNameSettings( | ||
defaultOperationName: String, | ||
operationMappings: Map[Filter.Glob, String], | ||
operationNameGenerator: HttpOperationNameGenerator) { | ||
|
||
private val logger = LoggerFactory.getLogger(classOf[OperationNameSettings]) | ||
|
||
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) | ||
Try { | ||
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) | ||
} getOrElse(defaultOperationName) | ||
} | ||
} |
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