Skip to main content
Previously we added a cumulative request counter to measure the total number of requests handled by an application and broke it down by attributes such as route and method. In this article we’ll add a second metric to track how many requests are actively being processed at any given moment — i.e., concurrent in-progress requests. Goals
  • Keep the cumulative total requests metric (http_requests_total).
  • Add a metric that represents the number of concurrent requests currently being processed (a value that can increase and decrease).
Why a different metric type is needed A traditional counter only increases, which is ideal for cumulative totals. To represent in-progress concurrency — a value that should increment when a request starts and decrement when it finishes — we need a metric type that can go up and down. Compare the options:
Metric typeBehaviorWhen to use
CounterMonotonic (only increases)Total number of events processed (e.g., requests completed).
GaugeArbitrary instantaneous valuePoint-in-time measurements that aren’t relative to previous values (e.g., memory usage).
Up-down counterIncrement and decrement relative to previous valueActive/in-progress counts that should rise and fall (e.g., concurrent requests).
For tracking concurrent requests, an up-down counter is the preferred choice because its value moves up and down relative to the previous state.
Complete Flask example
  • Configures a MeterProvider with a console exporter.
  • Creates a cumulative http_requests_total counter (incremented when responses are sent).
  • Creates a concurrent_requests up-down counter (incremented at request start, decremented after response).
  • Uses Flask before_request and after_request hooks to manage the concurrent counter.
  • Adds a slow route to let you observe concurrent requests.
How it works
  • before_request runs before Flask dispatches to the route handler. We increment concurrent_requests there (with route and method attributes) to indicate a request has started.
  • after_request runs after the route handler returns but before the response is sent. We decrement concurrent_requests and increment http_requests_total here, so the total only counts completed responses.
  • The slow POST /products route uses time.sleep(10) so you can make multiple concurrent requests and observe concurrent_requests rising while requests are still in-flight.
Testing with curl
  • Fast route:
  • Slow route (takes ~10 seconds to return):
Example console metric exports (sample)
Notes and practical tips
  • Place the total requests increment in after_request so you count only completed responses.
  • Attach attributes like route and method with each metric call to enable dimensional filtering and per-endpoint breakdowns. For example: {"route": request.path, "method": request.method}.
  • Export interval controls how often metrics are pushed to the exporter. In this example the reader is configured with export_interval_millis=5000 to export every 5 seconds.
  • If your application can raise exceptions during request handling, consider ensuring the decrement always runs (see warning below).
If a request handler raises an exception, after_request may not always run. To guarantee the concurrent counter is decremented in all cases, consider using Flask’s teardown_request (which runs for both successful and failed requests) or ensure exception paths also decrement the up-down counter.
Configuration summary
SettingPurposeExample
ExporterSends metric data to a destinationConsoleMetricExporter()
ReaderControls export frequencyPeriodicExportingMetricReader(exporter, export_interval_millis=5000)
Meter name/versionIdentify the instrumenting library/serviceget_meter(name="shopping-app", version="0.1.2")
Attributes on metric callsFor dimensional metrics and filtering{"route": request.path, "method": request.method}
Links and references This pattern gives you both a cumulative throughput signal (total requests processed) and a live concurrency signal (current in-progress requests), enabling better observability and capacity planning for your web service.

Watch Video