Skip to content

Commit

Permalink
feat: add req additional attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
varshith257 authored Nov 8, 2024
1 parent 95fe794 commit 38bf6fd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"),
""
)
)
}
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,19 @@ 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(
"http.response.status_code" -> {
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(_) => ""

}
)
)
Expand Down

0 comments on commit 38bf6fd

Please sign in to comment.