From a1732f3e0f09eced8f4dcf8ea8ebaf0f48b97265 Mon Sep 17 00:00:00 2001 From: karthik Date: Sun, 25 Jan 2026 08:24:30 -0500 Subject: [PATCH 1/2] Add httpx instrumentation support Adds HTTPX as a supported instrument, using the existing opentelemetry-instrumentation-httpx package from otel-contrib. - Add HTTPX enum value to Instruments - Add init_httpx_instrumentor() function - Add opentelemetry-instrumentation-httpx dependency Behaves like REQUESTS/URLLIB3 instrumentation - uses excluded_urls to avoid tracing internal otel exporter calls. Fixes #2283 Co-Authored-By: Claude Opus 4.5 --- packages/traceloop-sdk/pyproject.toml | 1 + .../traceloop-sdk/traceloop/sdk/instruments.py | 1 + .../traceloop/sdk/tracing/tracing.py | 17 +++++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/packages/traceloop-sdk/pyproject.toml b/packages/traceloop-sdk/pyproject.toml index 53e1c4ddb3..cd1919c104 100644 --- a/packages/traceloop-sdk/pyproject.toml +++ b/packages/traceloop-sdk/pyproject.toml @@ -15,6 +15,7 @@ dependencies = [ "opentelemetry-sdk>=1.38.0,<2", "opentelemetry-exporter-otlp-proto-http>=1.38.0,<2", "opentelemetry-exporter-otlp-proto-grpc>=1.38.0,<2", + "opentelemetry-instrumentation-httpx>=0.59b0", "opentelemetry-instrumentation-logging>=0.59b0", "opentelemetry-instrumentation-requests>=0.59b0", "opentelemetry-instrumentation-sqlalchemy>=0.59b0", diff --git a/packages/traceloop-sdk/traceloop/sdk/instruments.py b/packages/traceloop-sdk/traceloop/sdk/instruments.py index c507d31366..7600e42fee 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" + HTTPX = "httpx" LANCEDB = "lancedb" LANGCHAIN = "langchain" LLAMA_INDEX = "llama_index" diff --git a/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py b/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py index 08c52905f2..9b6e3e6b7c 100644 --- a/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py +++ b/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py @@ -504,6 +504,9 @@ def init_instrumentations( elif instrument == Instruments.HAYSTACK: if init_haystack_instrumentor(): instrument_set = True + elif instrument == Instruments.HTTPX: + if init_httpx_instrumentor(): + instrument_set = True elif instrument == Instruments.LANCEDB: if init_lancedb_instrumentor(): instrument_set = True @@ -735,6 +738,20 @@ def init_haystack_instrumentor(): return False +def init_httpx_instrumentor(): + try: + if is_package_installed("httpx"): + from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor + + instrumentor = HTTPXClientInstrumentor() + if not instrumentor.is_instrumented_by_opentelemetry: + instrumentor.instrument(excluded_urls=EXCLUDED_URLS) + return True + except Exception as e: + logging.error(f"Error initializing HTTPX instrumentor: {e}") + return False + + def init_langchain_instrumentor(): try: if is_package_installed("langchain") or is_package_installed("langgraph"): From 1cd98eace5be3b769e03ee0d6ec0f57aa4dbd071 Mon Sep 17 00:00:00 2001 From: karthik Date: Sun, 25 Jan 2026 08:56:44 -0500 Subject: [PATCH 2/2] fix(httpx): remove unsupported excluded_urls parameter HTTPXClientInstrumentor.instrument() doesn't accept excluded_urls as a parameter - it reads from OTEL_PYTHON_HTTPX_EXCLUDED_URLS environment variable instead. Co-Authored-By: Claude Opus 4.5 --- packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py b/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py index 9b6e3e6b7c..71cfb1aa1f 100644 --- a/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py +++ b/packages/traceloop-sdk/traceloop/sdk/tracing/tracing.py @@ -745,7 +745,9 @@ def init_httpx_instrumentor(): instrumentor = HTTPXClientInstrumentor() if not instrumentor.is_instrumented_by_opentelemetry: - instrumentor.instrument(excluded_urls=EXCLUDED_URLS) + # Note: HTTPXClientInstrumentor doesn't accept excluded_urls param. + # Use OTEL_PYTHON_HTTPX_EXCLUDED_URLS env var instead. + instrumentor.instrument() return True except Exception as e: logging.error(f"Error initializing HTTPX instrumentor: {e}")