Skip to content

Commit

Permalink
fix missing request attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
alizenhom committed Dec 2, 2024
1 parent 142b86c commit d2bae33
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
is_streaming,
message_to_event,
set_span_attribute,
set_span_attributes,
)


Expand All @@ -40,14 +41,14 @@ def chat_completions_create(

def traced_method(wrapped, instance, args, kwargs):
span_attributes = {**get_llm_request_attributes(kwargs, instance)}

span_name = f"{span_attributes[GenAIAttributes.GEN_AI_OPERATION_NAME]} {span_attributes[GenAIAttributes.GEN_AI_REQUEST_MODEL]}"
with tracer.start_as_current_span(
name=span_name,
kind=SpanKind.CLIENT,
attributes=span_attributes,
end_on_exit=False,
) as span:
set_span_attributes(span, span_attributes)
if span.is_recording():
for message in kwargs.get("messages", []):
event_logger.emit(
Expand Down Expand Up @@ -90,6 +91,7 @@ async def traced_method(wrapped, instance, args, kwargs):
attributes=span_attributes,
end_on_exit=False,
) as span:
set_span_attributes(span, span_attributes)
if span.is_recording():
for message in kwargs.get("messages", []):
event_logger.emit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def choice_to_event(choice, capture_content):


def set_span_attributes(span, attributes: dict):
for field, value in attributes.model_dump(by_alias=True).items():
for field, value in attributes.items():
set_span_attribute(span, field, value)


Expand Down

0 comments on commit d2bae33

Please sign in to comment.