Skip to content

Commit

Permalink
fixup! Introduce DD traces & metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
roekatz committed Feb 28, 2024
1 parent 9bd4dd1 commit 93c49ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/opal-common/opal_common/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
from .logging.formatter import Formatter
from .logging.intercept import InterceptHandler
from .logging.thirdparty import hijack_uvicorn_logs
from .monitoring.apm import fix_ddtrace_logging


def configure_logs():
"""Takeover process logs and create a logger with Loguru according to the
configuration."""
fix_ddtrace_logging()

intercept_handler = InterceptHandler()
formatter = Formatter(opal_common_config.LOG_FORMAT)
filter = ModuleFilter(
include_list=opal_common_config.LOG_MODULE_INCLUDE_LIST,
exclude_list=opal_common_config.LOG_MODULE_EXCLUDE_LIST,
)
logging.basicConfig(handlers=[intercept_handler], level=0, force=True)

if opal_common_config.LOG_PATCH_UVICORN_LOGS:
# Monkey patch UVICORN to use our logger
hijack_uvicorn_logs(intercept_handler)
Expand Down
10 changes: 10 additions & 0 deletions packages/opal-common/opal_common/monitoring/apm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os
from typing import Optional
from urllib.parse import urlparse
Expand All @@ -11,6 +12,7 @@ def configure_apm(enable_apm: bool, service_name: str):
"""optionally enable datadog APM / profiler."""
if enable_apm:
logger.info("Enabling DataDog APM")
# logging.getLogger("ddtrace").propagate = False

class FilterRootPathTraces(TraceFilter):
def process_trace(self, trace: list[Span]) -> Optional[list[Span]]:
Expand Down Expand Up @@ -48,3 +50,11 @@ def process_trace(self, trace: list[Span]) -> Optional[list[Span]]:
else:
logger.info("DataDog APM disabled")
tracer.configure(enabled=False)


def fix_ddtrace_logging():
logging.getLogger("ddtrace").setLevel(logging.WARNING)

ddtrace_logger = logging.getLogger("ddtrace")
for handler in ddtrace_logger.handlers:
ddtrace_logger.removeHandler(handler)

0 comments on commit 93c49ab

Please sign in to comment.