Skip to content

Commit 5dc3e03

Browse files
Add x-source-ui header to metrics.
Signed-off-by: Raymond Roestenburg <[email protected]>
1 parent bebf8b2 commit 5dc3e03

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

apps/common/src/main/scala/org/lfdecentralizedtrust/splice/http/HttpServerMetrics.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,17 @@ class HttpServerMetrics(metricsFactory: LabeledMetricsFactory) {
4141
// We need to pass the operation explicitly, which represents the OpenAPI operation ID.
4242
def withMetrics(service: String)(operation: String): Directive0 = {
4343
import org.apache.pekko.http.scaladsl.server.Directives.*
44-
implicit val mc: MetricsContext =
45-
MetricsContext("operation" -> operation, "http_service" -> service)
4644

4745
extractExecutionContext.flatMap { implicit ec =>
48-
extractRequest.flatMap { _ =>
46+
extractRequest.flatMap { req =>
47+
val c = MetricsContext("operation" -> operation, "http_service" -> service)
48+
implicit val mc: MetricsContext = req.headers
49+
.find(_.is("x-source-ui")) // custom header added by the UI
50+
.map { header =>
51+
c.withExtraLabels("source_ui" -> header.value)
52+
}
53+
.getOrElse(c)
54+
4955
inFlightRequests.inc()
5056
val timing = requestTiming.startAsync()
5157
mapRouteResultFuture { resultFuture =>

0 commit comments

Comments
 (0)