Skip to content

Commit

Permalink
#3315 - updated docs for prometheus to match with the new packages du…
Browse files Browse the repository at this point in the history
…e to the upgrade of the java client
  • Loading branch information
gastonschabas committed Nov 17, 2023
1 parent 268e4bf commit 3da8ac2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions doc/server/observability.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Add the following dependency:
"com.softwaremill.sttp.tapir" %% "tapir-prometheus-metrics" % "@VERSION@"
```

`PrometheusMetrics` encapsulates `CollectorReqistry` and `Metric` instances. It provides several ready to use metrics as
`PrometheusMetrics` encapsulates `PrometheusReqistry` and `Metric` instances. It provides several ready to use metrics as
well as an endpoint definition to read the metrics & expose them to the Prometheus server.

For example, using `NettyFutureServerInterpreter`:
Expand Down Expand Up @@ -92,18 +92,18 @@ To create and add custom metrics:
```scala mdoc:compile-only
import sttp.tapir.server.metrics.prometheus.PrometheusMetrics
import sttp.tapir.server.metrics.{EndpointMetric, Metric}
import io.prometheus.client.{CollectorRegistry, Counter}
import io.prometheus.metrics.core.metrics.{Counter, Gauge, Histogram}
import io.prometheus.metrics.model.registry.PrometheusRegistry
import scala.concurrent.Future

// Metric for counting responses labeled by path, method and status code
val responsesTotal = Metric[Future, Counter](
Counter
.build()
.namespace("tapir")
.name("responses_total")
.builder()
.name("tapir_responses_total")
.help("HTTP responses")
.labelNames("path", "method", "status")
.register(CollectorRegistry.defaultRegistry),
.register(PrometheusRegistry.defaultRegistry),
onRequest = { (req, counter, _) =>
Future.successful(
EndpointMetric()
Expand All @@ -112,14 +112,14 @@ val responsesTotal = Metric[Future, Counter](
val path = ep.showPathTemplate()
val method = req.method.method
val status = res.code.toString()
counter.labels(path, method, status).inc()
counter.labelValues(path, method, status).inc()
}
}
)
}
)

val prometheusMetrics = PrometheusMetrics[Future]("tapir", CollectorRegistry.defaultRegistry)
val prometheusMetrics = PrometheusMetrics[Future]("tapir", PrometheusRegistry.defaultRegistry)
.addCustom(responsesTotal)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object PrometheusMetricsExample extends App with StrictLogging {
val endpoints =
List(
personEndpoint,
// Exposes GET endpoint under `metrics` path for prometheus and serializes metrics from `CollectorRegistry` to plain text response
// Exposes GET endpoint under `metrics` path for prometheus and serializes metrics from `PrometheusRegistry` to plain text response
prometheusMetrics.metricsEndpoint
)

Expand Down

0 comments on commit 3da8ac2

Please sign in to comment.