Story 1445: Functions RED Metrics

Functions already had traces and structured logs, but operators still lacked registry-backed RED metrics for the route, queue, and relay boundaries. The missing signal was not another request id; it was a low-cardinality metric stream that CloudWatch can alert on and OTel can connect to traces.

Metric Model

HTTP route or WS route key
  -> http.server.request.duration histogram
     count = request rate
     error.type filter = error count
     buckets = p95 / p99 duration

SQS record
  -> pramaan.sqs.consume.duration histogram
     count = SQS attempts
     error.type filter = failed attempts
  -> aws.sqs.message.oldest_age
     value = queue lag from SentTimestamp

Projection relay batch
  -> pramaan.projection_relay.duration histogram
     error.type=dispatch_failed when any row fails to enqueue

Registry Rows Used

MetricTypeUnitLabels
http.server.request.durationhistogramsservice.name, deployment.environment.name, http.route, http.response.status_code, error.type
pramaan.sqs.consume.durationhistogramsservice.name, deployment.environment.name, queue, error.type
aws.sqs.message.oldest_ageupdowncountersdeployment.environment.name, queue
pramaan.projection_relay.durationhistogramsservice.name, deployment.environment.name, error.type

Guardrails

The shared helper rejects forbidden metric labels before export: firm_id, run_id, matter_id, user_id, trace_id, and span_id. Those remain trace/log lookup fields, never metric dimensions.

Latency is emitted only as histograms in seconds. There is no average-only request latency replacement.

Export Path

Each registered metric records through the OTel meter owned by the ADOT Lambda layer and mirrors the same sample through Powertools single_metric to CloudWatch EMF. Tests parse the emitted EMF JSON and assert the metric name, unit, histogram metadata, dimensions, and export target.

Recall: Story 1445 turns functions route, SQS, and relay boundaries into registry-backed metrics with low-cardinality dimensions and histogram latency, so p95/p99 and error burn alerts survive.