Skip to content

Commit 283eac9

Browse files
committed
P5-PR8: metrics — add minimal Prometheus counters for inbound faxes by provider/status (phaxio, sinch, humblefax)
1 parent 7767391 commit 283eac9

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

api/app/main.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
from .signalwire_service import get_signalwire_service
5252
import logging as _logging
5353
try:
54-
from prometheus_client import generate_latest, CONTENT_TYPE_LATEST
54+
from prometheus_client import generate_latest, CONTENT_TYPE_LATEST, Counter
5555
_PROM_AVAILABLE = True
5656
except Exception: # pragma: no cover
5757
_PROM_AVAILABLE = False
@@ -92,6 +92,16 @@
9292
app.state.hf_imap_worker = None # type: ignore[attr-defined]
9393
app.state.hf_imap_task = None # type: ignore[attr-defined]
9494

95+
# Minimal Prometheus counters (only when library is available)
96+
if _PROM_AVAILABLE:
97+
INBOUND_FAXES_TOTAL = Counter(
98+
'faxbot_inbound_faxes_total',
99+
'Inbound fax events processed',
100+
['provider', 'status']
101+
)
102+
else: # pragma: no cover
103+
INBOUND_FAXES_TOTAL = None # type: ignore
104+
95105
# Log documented credential fallbacks (no secret values)
96106
try:
97107
if not os.getenv("SINCH_API_KEY") and os.getenv("PHAXIO_API_KEY") and settings.sinch_api_key:
@@ -4622,6 +4632,11 @@ def get_nested(d, *keys):
46224632
db.add(fx)
46234633
db.commit()
46244634
audit_event("inbound_received", job_id=job_id, backend="phaxio")
4635+
try:
4636+
if INBOUND_FAXES_TOTAL is not None:
4637+
INBOUND_FAXES_TOTAL.labels(provider='phaxio', status=str(status)).inc()
4638+
except Exception:
4639+
pass
46254640
return _ack_response({"status": "ok"})
46264641

46274642

@@ -4823,6 +4838,11 @@ async def sinch_inbound(request: Request):
48234838
db.add(fx)
48244839
db.commit()
48254840
audit_event("inbound_received", job_id=job_id, backend="sinch", pdf_error=pdf_error)
4841+
try:
4842+
if INBOUND_FAXES_TOTAL is not None:
4843+
INBOUND_FAXES_TOTAL.labels(provider='sinch', status=str(status)).inc()
4844+
except Exception:
4845+
pass
48264846
return _ack_response({"status": "ok"})
48274847

48284848

@@ -4899,6 +4919,8 @@ async def humblefax_inbound(request: Request):
48994919
# Minimal audit trail without PHI
49004920
try:
49014921
audit_event("inbound_received", job_id=str(ext_id), backend="humblefax")
4922+
if INBOUND_FAXES_TOTAL is not None:
4923+
INBOUND_FAXES_TOTAL.labels(provider='humblefax', status=str(data.get('status') or 'received')).inc()
49024924
except Exception:
49034925
pass
49044926
return _ack_response({"status": "ok"})

0 commit comments

Comments
 (0)