From 41c655708e954aa362adc7f62f1b98324fb30ce9 Mon Sep 17 00:00:00 2001 From: Roger Yang <80478925+RogerHYang@users.noreply.github.com> Date: Thu, 31 Oct 2024 10:01:33 -0700 Subject: [PATCH] fix: remove httpx dependency (#1093) --- .../pyproject.toml | 9 --------- .../openinference/instrumentation/openai/_request.py | 11 +++++++---- .../test-requirements.txt | 6 ++++++ python/tox.ini | 5 ++++- 4 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 python/instrumentation/openinference-instrumentation-openai/test-requirements.txt diff --git a/python/instrumentation/openinference-instrumentation-openai/pyproject.toml b/python/instrumentation/openinference-instrumentation-openai/pyproject.toml index 724b098a8..de55a468b 100644 --- a/python/instrumentation/openinference-instrumentation-openai/pyproject.toml +++ b/python/instrumentation/openinference-instrumentation-openai/pyproject.toml @@ -38,14 +38,6 @@ dependencies = [ instruments = [ "openai >= 1.0.0", ] -test = [ - "openai == 1.0.0", - "opentelemetry-sdk", - "opentelemetry-instrumentation-httpx", - "respx", - "numpy", - "pytest-vcr", -] [project.urls] Homepage = "https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-openai" @@ -56,7 +48,6 @@ path = "src/openinference/instrumentation/openai/version.py" [tool.hatch.build.targets.sdist] include = [ "/src", - "/tests", ] [tool.hatch.build.targets.wheel] diff --git a/python/instrumentation/openinference-instrumentation-openai/src/openinference/instrumentation/openai/_request.py b/python/instrumentation/openinference-instrumentation-openai/src/openinference/instrumentation/openai/_request.py index c30045f49..13b64de7e 100644 --- a/python/instrumentation/openinference-instrumentation-openai/src/openinference/instrumentation/openai/_request.py +++ b/python/instrumentation/openinference-instrumentation-openai/src/openinference/instrumentation/openai/_request.py @@ -5,7 +5,6 @@ from types import ModuleType from typing import Any, Awaitable, Callable, Iterable, Iterator, Mapping, Tuple -from httpx import URL from opentelemetry import context as context_api from opentelemetry import trace as trace_api from opentelemetry.context import _SUPPRESS_INSTRUMENTATION_KEY @@ -123,11 +122,15 @@ def _get_span_kind(self, cast_to: type) -> str: ) def _get_attributes_from_instance(self, instance: Any) -> Iterator[Tuple[str, AttributeValue]]: - if not isinstance(base_url := getattr(instance, "base_url", None), URL): + if ( + not (base_url := getattr(instance, "base_url", None)) + or not (host := getattr(base_url, "host", None)) + or not isinstance(host, str) + ): return - if base_url.host.endswith("api.openai.com"): + if host.endswith("api.openai.com"): yield SpanAttributes.LLM_PROVIDER, OpenInferenceLLMProviderValues.OPENAI.value - if base_url.host.endswith("openai.azure.com"): + elif host.endswith("openai.azure.com"): yield SpanAttributes.LLM_PROVIDER, OpenInferenceLLMProviderValues.AZURE.value def _get_attributes_from_request( diff --git a/python/instrumentation/openinference-instrumentation-openai/test-requirements.txt b/python/instrumentation/openinference-instrumentation-openai/test-requirements.txt new file mode 100644 index 000000000..5a8460117 --- /dev/null +++ b/python/instrumentation/openinference-instrumentation-openai/test-requirements.txt @@ -0,0 +1,6 @@ +openai==1.0.0 +opentelemetry-sdk +opentelemetry-instrumentation-httpx +respx +numpy +pytest-vcr diff --git a/python/tox.ini b/python/tox.ini index 69707d511..6a03e1047 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -50,7 +50,10 @@ commands_pre = bedrock-latest: uv pip install -U boto3 mistralai: uv pip install --reinstall {toxinidir}/instrumentation/openinference-instrumentation-mistralai[test] mistralai-latest: uv pip install -U mistralai - openai: uv pip install --reinstall {toxinidir}/instrumentation/openinference-instrumentation-openai[test] + openai: uv pip uninstall -r test-requirements.txt + openai: uv pip install --reinstall-package openinference-instrumentation-openai . + openai: python -c 'import openinference.instrumentation.openai' + openai: uv pip install -r test-requirements.txt openai-latest: uv pip install -U openai vertexai: uv pip install --reinstall {toxinidir}/instrumentation/openinference-instrumentation-vertexai[test] vertexai-latest: uv pip install -U vertexai