Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(instrumentation): replace api base url hardcoded value from watsonx #2173

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?


from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.utils import (
Expand Down Expand Up @@ -101,10 +102,15 @@ def _set_span_attribute(span, name, value):


def _set_api_attributes(span):
watsonx_llm = watsonx_llm_init()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need this?

Copy link
Author

@rajmanna-dev rajmanna-dev Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can i extract url directly from WatsonxLLM objcet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comment here I shared an example of how we've done it elsewhere - #2165 (review)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should i check the attribute 'url' of the instance and then set that to api_base_url variable.
Like:

if hasattr(instance, "url"):
    api_base_url = instance.url

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked that the instance can actually have this attribute? I'd run one of the sample apps and see

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(
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")
Expand Down
2 changes: 1 addition & 1 deletion packages/sample-app/sample_app/watsonx-langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
rajmanna-dev marked this conversation as resolved.
Show resolved Hide resolved
apikey=os.getenv("IAM_API_KEY"),
project_id=os.getenv("PROJECT_ID"),
params=watsonx_llm_parameters,
Expand Down
Loading