From eafefb5486f30cb996bd96084afc8bd951c6b260 Mon Sep 17 00:00:00 2001 From: rajmanna Date: Fri, 18 Oct 2024 11:50:42 +0530 Subject: [PATCH 1/4] fix: replace api base url hardcoded value --- .../opentelemetry/instrumentation/watsonx/__init__.py | 8 ++++++-- packages/sample-app/sample_app/watsonx-langchain.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/opentelemetry-instrumentation-watsonx/opentelemetry/instrumentation/watsonx/__init__.py b/packages/opentelemetry-instrumentation-watsonx/opentelemetry/instrumentation/watsonx/__init__.py index f6402e572..e086e433a 100644 --- a/packages/opentelemetry-instrumentation-watsonx/opentelemetry/instrumentation/watsonx/__init__.py +++ b/packages/opentelemetry-instrumentation-watsonx/opentelemetry/instrumentation/watsonx/__init__.py @@ -100,11 +100,15 @@ def _set_span_attribute(span, name, value): return -def _set_api_attributes(span): +def _set_api_attributes(span, instance): + if hasattr(instance, "url"): + api_base_url = instance.url + else: + api_base_url = "https://us-south.ml.cloud.ibm.com" _set_span_attribute( span, WatsonxSpanAttributes.WATSONX_API_BASE, - "https://us-south.ml.cloud.ibm.com", + api_base_url, ) _set_span_attribute(span, WatsonxSpanAttributes.WATSONX_API_TYPE, "watsonx.ai") _set_span_attribute(span, WatsonxSpanAttributes.WATSONX_API_VERSION, "1.0") diff --git a/packages/sample-app/sample_app/watsonx-langchain.py b/packages/sample-app/sample_app/watsonx-langchain.py index ebdfc5093..b6b975bdc 100644 --- a/packages/sample-app/sample_app/watsonx-langchain.py +++ b/packages/sample-app/sample_app/watsonx-langchain.py @@ -28,7 +28,7 @@ def watsonx_llm_init() -> ModelInference: watsonx_llm = WatsonxLLM( model_id="ibm/granite-13b-instruct-v2", - url="https://us-south.ml.cloud.ibm.com", + url=os.getenv("API_BASE_URL"), apikey=os.getenv("IAM_API_KEY"), project_id=os.getenv("PROJECT_ID"), params=watsonx_llm_parameters, From 14c11ed9b352ae15d92f3c3df25de1b5dae9e41c Mon Sep 17 00:00:00 2001 From: rajmanna Date: Fri, 18 Oct 2024 12:18:54 +0530 Subject: [PATCH 2/4] Import the watsonx to access the object --- .../opentelemetry/instrumentation/watsonx/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/opentelemetry-instrumentation-watsonx/opentelemetry/instrumentation/watsonx/__init__.py b/packages/opentelemetry-instrumentation-watsonx/opentelemetry/instrumentation/watsonx/__init__.py index e086e433a..0cfa13687 100644 --- a/packages/opentelemetry-instrumentation-watsonx/opentelemetry/instrumentation/watsonx/__init__.py +++ b/packages/opentelemetry-instrumentation-watsonx/opentelemetry/instrumentation/watsonx/__init__.py @@ -14,6 +14,7 @@ from opentelemetry.trace.status import Status, StatusCode from opentelemetry.metrics import get_meter from opentelemetry.metrics import Counter, Histogram +from sample-app.sample_app.watsonx-langchain import watsonx_llm_init from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.utils import ( @@ -100,9 +101,10 @@ def _set_span_attribute(span, name, value): return -def _set_api_attributes(span, instance): - if hasattr(instance, "url"): - api_base_url = instance.url +def _set_api_attributes(span): + watsonx_llm = watsonx_llm_init() + if hasattr(watsonx_llm, "url"): + api_base_url = watsonx_llm.url else: api_base_url = "https://us-south.ml.cloud.ibm.com" _set_span_attribute( From 8506f4515483309e7357fc42eafc1db7cd7b59b1 Mon Sep 17 00:00:00 2001 From: rajmanna Date: Fri, 18 Oct 2024 13:16:44 +0530 Subject: [PATCH 3/4] Keep the original code --- packages/sample-app/sample_app/watsonx-langchain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sample-app/sample_app/watsonx-langchain.py b/packages/sample-app/sample_app/watsonx-langchain.py index b6b975bdc..f6a0dcb9c 100644 --- a/packages/sample-app/sample_app/watsonx-langchain.py +++ b/packages/sample-app/sample_app/watsonx-langchain.py @@ -28,7 +28,7 @@ def watsonx_llm_init() -> ModelInference: watsonx_llm = WatsonxLLM( model_id="ibm/granite-13b-instruct-v2", - url=os.getenv("API_BASE_URL"), + url=os.getenv("API_BASE_URL", "https://us-south.ml.cloud.ibm.com"), apikey=os.getenv("IAM_API_KEY"), project_id=os.getenv("PROJECT_ID"), params=watsonx_llm_parameters, From 800fe61b6745a3c2ed23b3f977b81edc170bf8d0 Mon Sep 17 00:00:00 2001 From: rajmanna Date: Fri, 18 Oct 2024 14:18:15 +0530 Subject: [PATCH 4/4] Keep the original url --- packages/sample-app/sample_app/watsonx-langchain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sample-app/sample_app/watsonx-langchain.py b/packages/sample-app/sample_app/watsonx-langchain.py index f6a0dcb9c..ebdfc5093 100644 --- a/packages/sample-app/sample_app/watsonx-langchain.py +++ b/packages/sample-app/sample_app/watsonx-langchain.py @@ -28,7 +28,7 @@ def watsonx_llm_init() -> ModelInference: watsonx_llm = WatsonxLLM( model_id="ibm/granite-13b-instruct-v2", - url=os.getenv("API_BASE_URL", "https://us-south.ml.cloud.ibm.com"), + url="https://us-south.ml.cloud.ibm.com", apikey=os.getenv("IAM_API_KEY"), project_id=os.getenv("PROJECT_ID"), params=watsonx_llm_parameters,