mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-14 16:16:48 +00:00
Skip trace work when disabled; share the agent span builder
With TRACES_ENABLED off, LLM calls record no GenAI metrics, and a streamed answer is joined into a preview only when a span keeps it. Agent runs and continuations build their invoke_agent span in one place, which now reads the model from model_id. The trace panel shows a stream's model time next to how long it was open. Adds missing type hints.
This commit is contained in:
1 parent
699906a015
commit
0bbbac0eb2
18 files changed
+88
-35
No files matched your search
@@ -437,6 +437,8 @@ class TestLogActivityTraceSpan:
|
||||
assert agent_span.attributes["gen_ai.operation.name"] == "invoke_agent"
|
||||
assert agent_span.attributes["gen_ai.agent.id"] == "agent-1"
|
||||
assert agent_span.attributes["docsgpt.answer_chars"] == 2
|
||||
# BaseAgent keeps its model in ``model_id``; the span reads it too.
|
||||
assert agent_span.attributes["gen_ai.request.model"] == "gpt-4o"
|
||||
assert agent_span.attributes["docsgpt.source_count"] == 1
|
||||
assert llm_span.parent_id == agent_span.id
|
||||
assert trace.activity_id is not None
|
||||
|
||||
@@ -110,6 +110,18 @@ class TestNonStreaming:
|
||||
metrics.assert_called_once()
|
||||
|
||||
|
||||
class TestDisabled:
|
||||
def test_no_metrics_when_tracing_is_off(self, metrics, monkeypatch):
|
||||
monkeypatch.setattr(settings, "TRACES_ENABLED", False)
|
||||
|
||||
@gen_token_usage
|
||||
def _gen(self, model, messages, stream, tools, **kwargs):
|
||||
return "x"
|
||||
|
||||
_gen(_LLM(), "m", [], False, None)
|
||||
metrics.assert_not_called()
|
||||
|
||||
|
||||
class TestStreaming:
|
||||
def test_span_starts_on_first_next_not_on_call(self, trace, metrics):
|
||||
@stream_token_usage
|
||||
|
||||
@@ -245,6 +245,8 @@ class TestContinuation:
|
||||
tool_span = trace.spans[1]
|
||||
assert agent_span.kind == tracing.KIND_AGENT
|
||||
assert agent_span.attributes["docsgpt.continuation"] is True
|
||||
assert agent_span.attributes["gen_ai.request.model"] == "gpt-4"
|
||||
assert agent_span.name == "invoke_agent ClassicAgent"
|
||||
assert agent_span.status == "ok"
|
||||
assert tool_span.parent_id == agent_span.id
|
||||
assert tool_span.status == "denied"
|
||||
|
||||
Reference in new issue
Block a user