diff --git a/metrics/opentelemetry-metrics/src/test/scala/sttp/tapir/server/metrics/opentelemetry/OpenTelemetryMetricsTest.scala b/metrics/opentelemetry-metrics/src/test/scala/sttp/tapir/server/metrics/opentelemetry/OpenTelemetryMetricsTest.scala index 093cd8d85f..1f0225c82a 100644 --- a/metrics/opentelemetry-metrics/src/test/scala/sttp/tapir/server/metrics/opentelemetry/OpenTelemetryMetricsTest.scala +++ b/metrics/opentelemetry-metrics/src/test/scala/sttp/tapir/server/metrics/opentelemetry/OpenTelemetryMetricsTest.scala @@ -55,7 +55,9 @@ class OpenTelemetryMetricsTest extends AnyFlatSpec with Matchers { AttributeKey.stringKey("http.request.method"), "GET", AttributeKey.stringKey("path"), - "/person" + "/person", + AttributeKey.stringKey("url.scheme"), + "http" ) point.getValue shouldBe 1 @@ -65,7 +67,9 @@ class OpenTelemetryMetricsTest extends AnyFlatSpec with Matchers { AttributeKey.stringKey("http.request.method"), "GET", AttributeKey.stringKey("path"), - "/person" + "/person", + AttributeKey.stringKey("url.scheme"), + "http" ) point.getValue shouldBe 0 } @@ -101,8 +105,12 @@ class OpenTelemetryMetricsTest extends AnyFlatSpec with Matchers { "GET", AttributeKey.stringKey("path"), "/person", + AttributeKey.stringKey("url.scheme"), + "http", AttributeKey.stringKey("http.response.status_code"), - "200" + "200", + AttributeKey.stringKey("error.type"), + "" ) && dp.getValue == 2 => true case dp @@ -111,8 +119,12 @@ class OpenTelemetryMetricsTest extends AnyFlatSpec with Matchers { "GET", AttributeKey.stringKey("path"), "/person", + AttributeKey.stringKey("url.scheme"), + "http", AttributeKey.stringKey("http.response.status_code"), - "400" + "400", + AttributeKey.stringKey("error.type"), + "" ) && dp.getValue == 2 => true case _ => false @@ -157,7 +169,11 @@ class OpenTelemetryMetricsTest extends AnyFlatSpec with Matchers { AttributeKey.stringKey("http.response.status_code"), "200", AttributeKey.stringKey("phase"), - "body" + "body", + AttributeKey.stringKey("url.scheme"), + "http", + AttributeKey.stringKey("error.type"), + "" ) ) } @@ -211,8 +227,12 @@ class OpenTelemetryMetricsTest extends AnyFlatSpec with Matchers { "GET", AttributeKey.stringKey("path"), "/person", + AttributeKey.stringKey("url.scheme"), + "http", AttributeKey.stringKey("http.response.status_code"), - "500" + "500", + AttributeKey.stringKey("error.type"), + "" ) point.getValue shouldBe 1 } diff --git a/server/core/src/main/scala/sttp/tapir/server/metrics/Metric.scala b/server/core/src/main/scala/sttp/tapir/server/metrics/Metric.scala index 5b3ba343d6..c229f6bf24 100644 --- a/server/core/src/main/scala/sttp/tapir/server/metrics/Metric.scala +++ b/server/core/src/main/scala/sttp/tapir/server/metrics/Metric.scala @@ -74,6 +74,7 @@ object MetricLabels { lazy val OpenTelemetryAttributes: MetricLabels = MetricLabels( forRequest = List( "http.request.method" -> { case (_, req) => req.method.method }, + "url.scheme" -> { case (_, req) => req.uri.scheme.getOrElse("unknown") }, "path" -> { case (ep, _) => ep.showPathTemplate(showQueryParam = None) } ), forResponse = List( @@ -81,6 +82,11 @@ object MetricLabels { case Right(r) => r.code.code.toString // Default to 500 for exceptions case Left(_) => "500" + }, + "error.type" -> { + case Left(ex) => ex.getClass.getSimpleName + case Right(_) => "" + } ) )