-
Notifications
You must be signed in to change notification settings - Fork 641
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
Add common gen AI utils into opentelemetry-instrumentation #3188
base: main
Are you sure you want to change the base?
Conversation
Lint and tests for OpenAI are failing because we test against oldest published supported dependencies opentelemetry-python-contrib/tox.ini Lines 427 to 429 in 07c97ea
Lines 12 to 14 in 07c97ea
To move this PR forward we either need to
|
I decided to do this, I've split the openai changes for now. I'll make a tracking bug to update the code once this PR is merged. |
4175da2
to
dcd3e4c
Compare
def get_span_name(span_attributes: Mapping[str, AttributeValue]) -> str: | ||
name = span_attributes.get(GenAIAttributes.GEN_AI_OPERATION_NAME, "") | ||
model = span_attributes.get(GenAIAttributes.GEN_AI_REQUEST_MODEL, "") | ||
return f"{name} {model}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
model name is not always available, we should return name
in this case
opentelemetry-instrumentation/src/opentelemetry/instrumentation/genai_utils.py
Show resolved
Hide resolved
return f"{name} {model}" | ||
|
||
|
||
def handle_span_exception(span: Span, error: Exception) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
def handle_span_exception(span: Span, error: Exception) -> None: | |
def end_span_with_exception(span: Span, error: Exception) -> None: |
?
we're not handling anything, right?
BTW - there is nothing gen-ai specific here, should we move it to common instrumentation helpers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tbh I'm kind of just mechanically copying from openai-v2:
Lines 232 to 238 in a716949
def handle_span_exception(span, error): | |
span.set_status(Status(StatusCode.ERROR, str(error))) | |
if span.is_recording(): | |
span.set_attribute( | |
ErrorAttributes.ERROR_TYPE, type(error).__qualname__ | |
) | |
span.end() |
Actually, the API/SDK has a mechanism here when used in start_as_current_span
ctx manager. That would also call span.record_exception()
which I believe add a span event with the stacktrace.
cc @lzchen @alizenhom do you know why OpenAI doesn't just use the existing mechanism?
Putting this back in draft for now, see the comments on linked issue #3191 (comment) |
Description
Part of #3191
(Copied out of cohere PR #3081)
Type of change
Refactor
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.