Skip to content

Commit b4207ed

Browse files
committed
fix(langchain): add role to plain completions
1 parent 6f9755a commit b4207ed

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/span_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ def set_chat_response(span: Span, response: LLMResult) -> None:
269269
)
270270
if tool_calls and isinstance(tool_calls, list):
271271
_set_chat_tool_calls(span, prefix, tool_calls)
272-
272+
else:
273+
_set_span_attribute(
274+
span, f"{prefix}.role", "assistant"
275+
)
273276
i += 1
274277

275278

packages/opentelemetry-instrumentation-langchain/tests/test_span_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ def test_plain_generation_defaults_to_assistant_role():
8282
set_chat_response(span, result)
8383

8484
prefix = f"{GenAIAttributes.GEN_AI_COMPLETION}.0"
85-
assert prefix + ".role" not in span.attributes
85+
assert prefix + ".role" == "assistant"
8686
assert span.attributes[prefix + ".content"] == "plain completion"

0 commit comments

Comments
 (0)