From 1257b4cea68dec426ba08f5d31f8265f899bcd8b Mon Sep 17 00:00:00 2001 From: ionmincu Date: Fri, 4 Apr 2025 17:23:12 +0300 Subject: [PATCH] feat(tracer): filter tracer http logs --- sdk/langchain/pyproject.toml | 2 +- .../tracers/AsyncUiPathTracer.py | 4 ++- .../uipath_langchain/tracers/_utils.py | 28 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/sdk/langchain/pyproject.toml b/sdk/langchain/pyproject.toml index e7760a13..fd65947a 100644 --- a/sdk/langchain/pyproject.toml +++ b/sdk/langchain/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "uipath-langchain" -version = "0.0.82" +version = "0.0.83" description = "UiPath Langchain" readme = { file = "README.md", content-type = "text/markdown" } requires-python = ">=3.9" diff --git a/sdk/langchain/uipath_langchain/tracers/AsyncUiPathTracer.py b/sdk/langchain/uipath_langchain/tracers/AsyncUiPathTracer.py index fe259318..b90e637a 100644 --- a/sdk/langchain/uipath_langchain/tracers/AsyncUiPathTracer.py +++ b/sdk/langchain/uipath_langchain/tracers/AsyncUiPathTracer.py @@ -13,10 +13,12 @@ from langchain_core.tracers.schemas import Run from pydantic import PydanticDeprecationWarning -from ._utils import _simple_serialize_defaults +from ._utils import _setup_tracer_httpx_logging, _simple_serialize_defaults logger = logging.getLogger(__name__) +_setup_tracer_httpx_logging("/llmops_/api/Agent/trace/") + class Status: SUCCESS = 1 diff --git a/sdk/langchain/uipath_langchain/tracers/_utils.py b/sdk/langchain/uipath_langchain/tracers/_utils.py index 1d510d55..7ad38fcc 100644 --- a/sdk/langchain/uipath_langchain/tracers/_utils.py +++ b/sdk/langchain/uipath_langchain/tracers/_utils.py @@ -1,7 +1,35 @@ import datetime +import logging from zoneinfo import ZoneInfo +class IgnoreSpecificUrl(logging.Filter): + def __init__(self, url_to_ignore): + super().__init__() + self.url_to_ignore = url_to_ignore + + def filter(self, record): + try: + if record.msg == 'HTTP Request: %s %s "%s %d %s"': + # Ignore the log if the URL matches the one we want to ignore + method = record.args[0] + url = record.args[1] + + if method == "POST" and url.path.endswith(self.url_to_ignore): + # Check if the URL contains the specific path we want to ignore + return True + return False + + except Exception: + return False + + +def _setup_tracer_httpx_logging(url: str): + # Create a custom logger for httpx + # Add the custom filter to the root logger + logging.getLogger("httpx").addFilter(IgnoreSpecificUrl(url)) + + def _simple_serialize_defaults(obj): if hasattr(obj, "model_dump"): return obj.model_dump(exclude_none=True, mode="json")