Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -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
Loading