<@U22BBEZQU> your problem is that you've got 2 Rep...
# http4k
d
@jdiaz your problem is that you've got 2 ReportHttpTransaction filters in there - there needs to be only a single filter - that does the naming in the label function and the emit in the report function. Here's an example fix, although it could definitely use a bit of tidying up! ­čÖé
Copy code
import org.http4k.core.HttpTransaction
import org.http4k.core.Method.DELETE
import org.http4k.core.Method.GET
import <http://org.http4k.core.Method.POST|org.http4k.core.Method.POST>
import org.http4k.core.Method.PUT
import org.http4k.core.Request
import org.http4k.core.Response
import org.http4k.core.Status.Companion.OK
import org.http4k.core.then
import org.http4k.filter.ResponseFilters
import org.http4k.routing.bind
import org.http4k.routing.routes

data class Dimension(val a: String, val v: String)

fun emitMetric(listOf: List<Dimension>, s: String, toMillis: Long) {
    println(listOf + s + toMillis)
}

val emit = { tx: HttpTransaction ->
    emitMetric(listOf(
        Dimension("URI", tx.routingGroup),
        Dimension("Method", tx.label("Name")!!)
    ), "Latency", tx.duration.toMillis()
    )
}

val mapsRoute = routes(
    "/{id}" bind PUT to name("UpdateMap").then { _: Request -> Response(OK) },
    "/" bind POST to name("CreateMap").then { _: Request -> Response(OK) },
    "/{id}" bind DELETE to name("DeleteMap").then { _: Request -> Response(OK) },
    "/{id}" bind GET to name("ReadMap").then { _: Request -> Response(OK) }
)

val app = routes(
    "/maps" bind mapsRoute
    // More routes here
)

fun name(name: String) = ResponseFilters.ReportHttpTransaction(
    transactionLabeller = { tx: HttpTransaction ->
        tx.label("Name", name)
    }, recordFn = emit
)

fun main(args: Array<String>) {
    app(Request(GET, "/maps/123"))
    app(Request(POST, "/maps/"))
}