-
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.
Merge pull request #926 from yarosman/master-play-route-name-generator
Allow to define custom router name generator for play server
- Loading branch information
Showing
5 changed files
with
118 additions
and
20 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
15 changes: 15 additions & 0 deletions
15
...tation/kamon-play/src/main/scala/kamon/instrumentation/play/GrpcRouterNameGenerator.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,15 @@ | ||
package kamon.instrumentation.play | ||
|
||
import akka.http.scaladsl.model.HttpRequest | ||
|
||
trait GrpcRouterNameGenerator { | ||
|
||
def generateOperationName(request: akka.http.scaladsl.model.HttpRequest): String | ||
|
||
} | ||
|
||
class DefaultGrpcRouterNameGenerator extends GrpcRouterNameGenerator { | ||
|
||
override def generateOperationName(request: HttpRequest): String = request.uri.toRelative.toString | ||
|
||
} |
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
23 changes: 23 additions & 0 deletions
23
...n/kamon-play/src/main/scala/kamon/instrumentation/play/RouterOperationNameGenerator.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,23 @@ | ||
package kamon.instrumentation.play | ||
|
||
import play.api.routing.HandlerDef | ||
|
||
import scala.collection.concurrent.TrieMap | ||
|
||
trait RouterOperationNameGenerator { | ||
def generateOperationName(handlerDef: HandlerDef): String | ||
} | ||
|
||
class DefaultRouterOperationNameGenerator extends RouterOperationNameGenerator { | ||
|
||
private val _operationNameCache = TrieMap.empty[String, String] | ||
private val _normalizePattern = """\$([^<]+)<[^>]+>""".r | ||
|
||
def generateOperationName(handlerDef: HandlerDef): String = { | ||
_operationNameCache.getOrElseUpdate(handlerDef.path, { | ||
// Convert paths of form /foo/bar/$paramname<regexp>/blah to /foo/bar/paramname/blah | ||
_normalizePattern.replaceAllIn(handlerDef.path, "$1") | ||
}) | ||
} | ||
|
||
} |