diff --git a/src/HttpHandler/Fetch.fs b/src/HttpHandler/Fetch.fs index 9fceaa0..dac8961 100644 --- a/src/HttpHandler/Fetch.fs +++ b/src/HttpHandler/Fetch.fs @@ -77,14 +77,14 @@ module Fetch = try use request = buildRequest client ctx timer.Start() - ctx.Request.Metrics.Counter Metric.FetchInc Map.empty 1L + ctx.Request.Metrics.Counter Metric.FetchInc ctx.Request.Labels 1L let! response = client.SendAsync(request, ctx.Request.CompletionMode, cancellationToken) timer.Stop() ctx.Request.Metrics.Gauge Metric.FetchLatencyUpdate - Map.empty + ctx.Request.Labels (float timer.ElapsedMilliseconds) let items = diff --git a/src/HttpHandler/HttpContext.fs b/src/HttpHandler/HttpContext.fs index 857be3b..162dc20 100644 --- a/src/HttpHandler/HttpContext.fs +++ b/src/HttpHandler/HttpContext.fs @@ -4,6 +4,7 @@ namespace Oryx open System +open System.Collections open System.Diagnostics open System.Net open System.Net.Http @@ -83,6 +84,8 @@ and HttpRequest = LogFormat: string /// Optional Metrics for recording metrics. Metrics: IMetrics + /// Optional Labels to label the request + Labels: Generic.IDictionary /// Extra state used to e.g build the URL. Clients are free to utilize this property for adding extra /// information to the context. Items: Map @@ -129,6 +132,7 @@ module HttpContext = LogLevel = LogLevel.None LogFormat = defaultLogFormat Metrics = EmptyMetrics() + Labels = dict [] Items = Map.empty CompletionMode = HttpCompletionOption.ResponseContentRead } diff --git a/src/HttpHandler/HttpHandler.fs b/src/HttpHandler/HttpHandler.fs index b1e88e7..cc4bce2 100644 --- a/src/HttpHandler/HttpHandler.fs +++ b/src/HttpHandler/HttpHandler.fs @@ -105,7 +105,7 @@ module HttpHandler = let item = parser stream return! next.OnNextAsync(ctx, item) with ex -> - ctx.Request.Metrics.Counter Metric.DecodeErrorInc Map.empty 1L + ctx.Request.Metrics.Counter Metric.DecodeErrorInc ctx.Request.Labels 1L return! next.OnErrorAsync(ctx, ex) } @@ -126,7 +126,7 @@ module HttpHandler = let! item = parser stream return! next.OnNextAsync(ctx, item) with ex -> - ctx.Request.Metrics.Counter Metric.DecodeErrorInc Map.empty 1L + ctx.Request.Metrics.Counter Metric.DecodeErrorInc ctx.Request.Labels 1L return! next.OnErrorAsync(ctx, ex) } @@ -315,7 +315,7 @@ module HttpHandler = match response.IsSuccessStatusCode with | true -> return! next.OnNextAsync(ctx, content = content) | false -> - ctx.Request.Metrics.Counter Metric.FetchErrorInc Map.empty 1L + ctx.Request.Metrics.Counter Metric.FetchErrorInc ctx.Request.Labels 1L let! err = errorHandler response content return! next.OnErrorAsync(ctx, err)