|
51 | 51 | from .signalwire_service import get_signalwire_service |
52 | 52 | import logging as _logging |
53 | 53 | try: |
54 | | - from prometheus_client import generate_latest, CONTENT_TYPE_LATEST |
| 54 | + from prometheus_client import generate_latest, CONTENT_TYPE_LATEST, Counter |
55 | 55 | _PROM_AVAILABLE = True |
56 | 56 | except Exception: # pragma: no cover |
57 | 57 | _PROM_AVAILABLE = False |
|
92 | 92 | app.state.hf_imap_worker = None # type: ignore[attr-defined] |
93 | 93 | app.state.hf_imap_task = None # type: ignore[attr-defined] |
94 | 94 |
|
| 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 | + |
95 | 105 | # Log documented credential fallbacks (no secret values) |
96 | 106 | try: |
97 | 107 | 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): |
4622 | 4632 | db.add(fx) |
4623 | 4633 | db.commit() |
4624 | 4634 | 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 |
4625 | 4640 | return _ack_response({"status": "ok"}) |
4626 | 4641 |
|
4627 | 4642 |
|
@@ -4823,6 +4838,11 @@ async def sinch_inbound(request: Request): |
4823 | 4838 | db.add(fx) |
4824 | 4839 | db.commit() |
4825 | 4840 | 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 |
4826 | 4846 | return _ack_response({"status": "ok"}) |
4827 | 4847 |
|
4828 | 4848 |
|
@@ -4899,6 +4919,8 @@ async def humblefax_inbound(request: Request): |
4899 | 4919 | # Minimal audit trail without PHI |
4900 | 4920 | try: |
4901 | 4921 | 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() |
4902 | 4924 | except Exception: |
4903 | 4925 | pass |
4904 | 4926 | return _ack_response({"status": "ok"}) |
|
0 commit comments