Skip to content

Commit

Permalink
feat: standardizing logging across openbrain and ob-api
Browse files Browse the repository at this point in the history
  • Loading branch information
svange committed Jul 31, 2024
1 parent 1d32530 commit 56eefc8
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Binary file added assets/x-ray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 0 additions & 19 deletions openbrain/agents/exceptions.py
Original file line number Diff line number Diff line change
@@ -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."""

Expand All @@ -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
2 changes: 1 addition & 1 deletion openbrain/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
34 changes: 4 additions & 30 deletions openbrain/util.py
Original file line number Diff line number Diff line change
@@ -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"""
Expand Down Expand Up @@ -286,8 +262,6 @@ def _initialize(cls):


logger = get_logger()
metrics = get_metrics()
tracer = get_tracer()
config = ConfigSingleton()
if __name__ == "__main__":
logger.debug(config)
Expand Down

0 comments on commit 56eefc8

Please sign in to comment.