diff --git a/packages/traceloop-sdk/pyproject.toml b/packages/traceloop-sdk/pyproject.toml index d31795fd5a..675988ce35 100644 --- a/packages/traceloop-sdk/pyproject.toml +++ b/packages/traceloop-sdk/pyproject.toml @@ -42,6 +42,7 @@ dependencies = [ "opentelemetry-instrumentation-llamaindex", "opentelemetry-instrumentation-milvus", "opentelemetry-instrumentation-haystack", + "opentelemetry-instrumentation-httpx>=0.59b0", "opentelemetry-instrumentation-bedrock", "opentelemetry-instrumentation-sagemaker", "opentelemetry-instrumentation-replicate", diff --git a/packages/traceloop-sdk/traceloop/sdk/instruments.py b/packages/traceloop-sdk/traceloop/sdk/instruments.py index d4232a3899..c99c7c21d7 100644 --- a/packages/traceloop-sdk/traceloop/sdk/instruments.py +++ b/packages/traceloop-sdk/traceloop/sdk/instruments.py @@ -13,6 +13,7 @@ class Instruments(Enum): GOOGLE_GENERATIVEAI = "google_generativeai" GROQ = "groq" HAYSTACK = "haystack" + HTTPCLIENT = "httpclient" LANCEDB = "lancedb" LANGCHAIN = "langchain" LITELLM = "litellm" diff --git a/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py b/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py index 9db24fe4b6..a4b0854cab 100644 --- a/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py +++ b/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py @@ -542,6 +542,9 @@ def init_instrumentations( elif instrument == Instruments.HAYSTACK: if init_haystack_instrumentor(): instrument_set = True + elif instrument == Instruments.HTTPCLIENT: + if init_httpclient_instrumentor(): + instrument_set = True elif instrument == Instruments.LANCEDB: if init_lancedb_instrumentor(): instrument_set = True @@ -783,6 +786,20 @@ def init_haystack_instrumentor(): return False +def init_httpclient_instrumentor(): + try: + if is_package_installed("httpx"): + from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor + + instrumentor = HTTPXClientInstrumentor() + if not instrumentor.is_instrumented_by_opentelemetry: + instrumentor.instrument() + return True + except Exception as e: + logging.error(f"Error initializing HTTPX instrumentor: {e}") + return False + + def init_langchain_instrumentor(use_attributes: bool = True): try: if is_package_installed("langchain") or is_package_installed("langgraph"):