Skip to content

Instantly share code, notes, and snippets.

@orient-man
Last active April 1, 2021 15:05
Show Gist options
  • Save orient-man/c75b7b4e7d76705c6a51931d9b08e232 to your computer and use it in GitHub Desktop.
Save orient-man/c75b7b4e7d76705c6a51931d9b08e232 to your computer and use it in GitHub Desktop.
module Giraffe.ApplicationInsights
open Giraffe
open Microsoft.ApplicationInsights.DataContracts
let private setRoutingMetadata action : HttpHandler =
fun next ctx ->
let action' = ctx.Request.Method + " " + action
ctx.Request.RouteValues.["controller"] <- "Giraffe"
ctx.Request.RouteValues.["action"] <- action'
let telemetry = ctx.Features.Get<RequestTelemetry>()
if not <| isNull telemetry then telemetry.Name <- action'
next ctx
let routef (path: PrintfFormat<_,_,_,_, 'T>) (routeHandler: 'T -> HttpHandler) : HttpHandler =
setRoutingMetadata path.Value >=> (routef path routeHandler)
let route (path: string) : HttpHandler =
setRoutingMetadata path >=> (route path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment