Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
fix: handle when no tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
zac-li committed Jun 9, 2023
1 parent 794eb12 commit 83a2114
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions lcserve/backend/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ def _get_error_msg(e: Union[WebSocketDisconnect, ConnectionClosed]) -> str:
tracer=tracer, parent_span=get_current_span()
)
}

# If the function is a streaming response, we pass the websocket callback handler,
# so that stream data can be sent back to the client.
if include_ws_callback_handlers:
Expand Down
7 changes: 7 additions & 0 deletions lcserve/backend/langchain_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def on_llm_start(
parent_run_id: Optional[UUID] = None,
**kwargs: Any
) -> None:
if not self.tracer:
return

prompts_len = 0
operation = "langchain.on_llm_start"

Expand All @@ -36,8 +39,12 @@ def on_llm_start(
span.set_attribute("prompts_len", prompts_len)

def on_llm_end(self, response: LLMResult, *, run_id: UUID, **kwargs: Any) -> None:
if not self.tracer:
return

operation = "langchain.on_llm_end"
token_usage = response.llm_output["token_usage"]

context = set_span_in_context(self.parent_span)
with self.tracer.start_as_current_span("llm end", context=context) as span:
span.set_attribute("otel.operation.name", operation)
Expand Down

0 comments on commit 83a2114

Please sign in to comment.