fix: suppress alembic INFO logs before import to prevent Datadog misclassification (#12691)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Graham Neubig
2026-02-12 19:32:39 +00:00
committed by GitHub
parent d7656bf1c9
commit 5f958ab60d
2 changed files with 16 additions and 9 deletions

View File

@@ -1,10 +1,15 @@
import logging
import os import os
from logging.config import fileConfig from logging.config import fileConfig
from alembic import context # Suppress alembic.runtime.plugins INFO logs during import to prevent non-JSON logs in production
from google.cloud.sql.connector import Connector # These plugin setup messages would otherwise appear before logging is configured
from sqlalchemy import create_engine logging.getLogger('alembic.runtime.plugins').setLevel(logging.WARNING)
from storage.base import Base
from alembic import context # noqa: E402
from google.cloud.sql.connector import Connector # noqa: E402
from sqlalchemy import create_engine # noqa: E402
from storage.base import Base # noqa: E402
target_metadata = Base.metadata target_metadata = Base.metadata

View File

@@ -1,8 +1,14 @@
import logging
import os
import sys import sys
from logging.config import fileConfig from logging.config import fileConfig
from pathlib import Path from pathlib import Path
from alembic import context # Suppress alembic.runtime.plugins INFO logs during import to prevent non-JSON logs in production
# These plugin setup messages would otherwise appear before logging is configured
logging.getLogger('alembic.runtime.plugins').setLevel(logging.WARNING)
from alembic import context # noqa: E402
# Add the project root to the Python path so we can import OpenHands modules # Add the project root to the Python path so we can import OpenHands modules
# From alembic/env.py, we need to go up 5 levels to reach the OpenHands project root # From alembic/env.py, we need to go up 5 levels to reach the OpenHands project root
@@ -34,14 +40,10 @@ config = context.config
# Interpret the config file for Python logging. # Interpret the config file for Python logging.
# This line sets up loggers basically. # This line sets up loggers basically.
if config.config_file_name is not None: if config.config_file_name is not None:
import os
if os.path.exists(config.config_file_name): if os.path.exists(config.config_file_name):
fileConfig(config.config_file_name) fileConfig(config.config_file_name)
else: else:
# Use basic logging configuration if config file doesn't exist # Use basic logging configuration if config file doesn't exist
import logging
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
# add your model's MetaData object here # add your model's MetaData object here