Use this file to discover all available pages before exploring further.
The ERP Financial Agent exposes a rich observability surface: a Prometheus /metrics endpoint that tracks LLM latency, token consumption, SQL execution, and HTTP traffic; a Grafana dashboard provisioned automatically from monitoring/grafana/dashboards/erp-agent.json; LangSmith trace integration for every LangGraph invocation; per-user and per-node cost accounting backed by Redis and DynamoDB; and structured JSON logs with correlation IDs via structlog. All components can be started locally with a single Compose command.
docker compose -f monitoring/docker-compose.monitoring.yml up
This starts two containers:
Service
Image
Host port
Prometheus
prom/prometheus:v2.51.0
9090
Grafana
grafana/grafana:10.4.0
3000
Prometheus scrapes the backend at host.docker.internal:8000/metrics every 15 seconds and retains data for 15 days (--storage.tsdb.retention.time=15d). Grafana is provisioned automatically with a Prometheus data source and the ERP Agent dashboard.
Default Grafana credentials are admin / admin. Self-registration is disabled (GF_USERS_ALLOW_SIGN_UP=false). Change the password immediately after first login in any non-local environment.
All metrics are registered under the prefix erp_agent_ (configured by settings.metrics_prefix in src/observability/metrics.py). The scrape endpoint is GET /metrics.
erp_agent_errors_total Labels: error_type, node Type: Counter Desc: Total errors by type and originating nodeerp_agent_active_sessions Type: Gauge Desc: Number of active sessions
For production, replace host.docker.internal:8000 with the ALB DNS or the ECS service discovery endpoint. On ECS Fargate with Container Insights enabled, consider using the AWS Managed Prometheus (AMP) remote-write integration instead of self-hosted Prometheus.
Fires if the 95th-percentile LLM call duration exceeds 15 seconds for at least 2 minutes. Indicates model cold starts, network latency to Bedrock, or unusually large prompts.
Fires when the 95th-percentile SQL execution time exceeds 10 seconds for 2 minutes. Indicates missing indexes, long-running aggregations, or RDS instance saturation.
The dashboard JSON (monitoring/grafana/dashboards/erp-agent.json) is mounted read-only at startup. Access Grafana at http://localhost:3000 and look for the ERP Agent dashboard on the home page.
src/observability/cost_tracker.py implements a CostTracker singleton that accumulates token usage — broken down by user, session, and LangGraph node — and persists state to Redis (90-day TTL) and DynamoDB (permanent backup) every 10 LLM calls.Cost calculation uses separate rates for standard and reasoning models (Anthropic Opus-class models are detected by the opus substring in the model ID):
Cost context (user and session) is injected into the tracker via set_cost_context(user_id, session_id) in the API layer before each graph invocation. This ensures costs are attributed correctly even when requests arrive concurrently.
LangSmith tracing is configured in src/observability/langsmith.py and must be enabled before the LangGraph graph or any LLM client is instantiated.Required environment variables:
Variable
Description
LANGSMITH_API_KEY
Your LangSmith API key
LANGCHAIN_TRACING_V2
Set to true to enable tracing
LANGSMITH_PROJECT
Project name in LangSmith (default: erp-financial-agent)
How it works:
def configure_langsmith() -> None: settings = get_settings() if not settings.langsmith_api_key: logger.info("LangSmith tracing disabled (no API key)") return os.environ["LANGCHAIN_TRACING_V2"] = str(settings.langchain_tracing_v2).lower() os.environ["LANGCHAIN_API_KEY"] = settings.langsmith_api_key os.environ["LANGCHAIN_PROJECT"] = settings.langsmith_project
When tracing is enabled, every LangGraph node invocation — SQL generation, schema linking, validation, self-correction — appears as a named span in LangSmith under the erp-financial-agent project. You can replay failed conversations, inspect token counts per node, and compare latencies across model versions.
Tracing sends prompt and completion text to LangSmith. For tenants with strict data-residency requirements, either disable tracing (LANGCHAIN_TRACING_V2=false) or use LangSmith’s self-hosted option.