diff --git a/README.md b/README.md index a12d92e..bfe8c04 100644 --- a/README.md +++ b/README.md @@ -243,7 +243,7 @@ sequenceDiagram ``` ### Example X-Ray diagram from live test - +![X-Ray trace of full event workflow](assets/x-ray.png) ## Contributing See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. diff --git a/assets/x-ray.png b/assets/x-ray.png new file mode 100644 index 0000000..831cac6 Binary files /dev/null and b/assets/x-ray.png differ diff --git a/openbrain/agents/exceptions.py b/openbrain/agents/exceptions.py index 56850eb..626f93f 100644 --- a/openbrain/agents/exceptions.py +++ b/openbrain/agents/exceptions.py @@ -1,12 +1,5 @@ from langchain.tools.base import ToolException -from openbrain.util import config, get_logger, get_metrics, get_tracer - -logger = get_logger() -metrics = get_metrics() -tracer = get_tracer() - - class AgentError(Exception): """Raised when the agent fails.""" @@ -25,16 +18,4 @@ class AgentToolIncompleteContactError(AgentToolError): class AgentToolLeadMomentumError(AgentToolError): """Raised when LeadMomentum returns an error""" - pass - # event_bus_name = config.EVENTBUS_FRIENDLY_NAME - # event_source = Util.PROJECT - # event_bridge_client = Util.BOTO_SESSION.client("events") - # event = { - # "Source": event_source, - # "DetailType": __name__, - # "EventBusName": event_bus_name, - # "Detail": "{}", - # } - - # TODO: Send to dead letter queue diff --git a/openbrain/cli.py b/openbrain/cli.py index 21ba544..03b5450 100644 --- a/openbrain/cli.py +++ b/openbrain/cli.py @@ -8,7 +8,7 @@ from openbrain.agents.gpt_agent import GptAgent from openbrain.orm.model_agent_config import AgentConfig -from openbrain.util import config, get_logger, get_tracer, get_metrics, Defaults +from openbrain.util import Defaults class CliChatBot(Cmd): diff --git a/openbrain/util.py b/openbrain/util.py index c7c143d..046bde8 100644 --- a/openbrain/util.py +++ b/openbrain/util.py @@ -1,45 +1,21 @@ -import logging import os from dataclasses import dataclass, field, asdict from enum import Enum -from io import StringIO import boto3 -from aws_lambda_powertools import ( - Logger, - Metrics, - Tracer, -) +from aws_lambda_powertools import Logger from botocore.exceptions import ClientError, NoCredentialsError from dotenv import load_dotenv - -from openbrain.exceptions import ObMissingEnvironmentVariable - load_dotenv() -# MODE = os.getenv("MODE", "LOCAL") - +APP_NAME = "openbrain" def get_logger() -> Logger: - _logger = Logger(service=f"{__name__}") - log_stream = StringIO() - string_handler = logging.StreamHandler(log_stream) - _logger.addHandler(string_handler) - # logging.basicConfig(stream=log_stream, level=logging.INFO, format='%(levelname)s :: %(message)s') - # boto3.set_stream_logger() - # boto3.set_stream_logger("botocore") + log_level = os.environ.get("LOG_LEVEL", "INFO") # Default to INFO if not set + _logger = Logger(service=f"{APP_NAME}", level=log_level) return _logger -def get_metrics() -> Metrics: - metrics = Metrics(service=f"{__name__}") - return metrics - - -def get_tracer() -> Tracer: - tracer = Tracer(service=f"{__name__}") - return tracer - def detect_aws_region() -> str: """Detects the AWS region from the environment or boto3 session""" @@ -286,8 +262,6 @@ def _initialize(cls): logger = get_logger() -metrics = get_metrics() -tracer = get_tracer() config = ConfigSingleton() if __name__ == "__main__": logger.debug(config)