Skip to content

Commit 687669f

Browse files
authored
[chore] Fix missing AgentScope tool metrics (#109)
2 parents ad281f2 + 89b426d commit 687669f

File tree

1 file changed

+5
-3
lines changed
  • instrumentation-loongsuite/loongsuite-instrumentation-agentscope/src/opentelemetry/instrumentation/agentscope

1 file changed

+5
-3
lines changed

instrumentation-loongsuite/loongsuite-instrumentation-agentscope/src/opentelemetry/instrumentation/agentscope/patch.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from __future__ import annotations
1818

1919
import logging
20+
import timeit
2021

2122
from opentelemetry.semconv._incubating.attributes import (
2223
gen_ai_attributes as GenAIAttributes,
@@ -114,15 +115,15 @@ async def _trace_async_generator_wrapper(
114115
_apply_error_attributes(span, error_obj)
115116
# Record metrics with error
116117
if handler._metrics_recorder is not None:
117-
handler._metrics_recorder.record(
118+
handler._metrics_recorder.record_extended(
118119
span,
119120
invocation,
120121
error_type=error_obj.type.__qualname__,
121122
)
122123
else:
123124
# Record metrics without error
124125
if handler._metrics_recorder is not None:
125-
handler._metrics_recorder.record(span, invocation)
126+
handler._metrics_recorder.record_extended(span, invocation)
126127
except Exception:
127128
# Don't let finalization errors break the generator
128129
pass
@@ -164,6 +165,7 @@ async def wrap_tool_call(wrapped, instance, args, kwargs, handler):
164165
tool_description=tool_description,
165166
tool_call_arguments=tool_args,
166167
)
168+
invocation.monotonic_start_s = timeit.default_timer()
167169

168170
span_name = f"{GenAIAttributes.GenAiOperationNameValues.EXECUTE_TOOL.value} {tool_name}"
169171
with handler._tracer.start_as_current_span(
@@ -185,7 +187,7 @@ async def wrap_tool_call(wrapped, instance, args, kwargs, handler):
185187

186188
# Record metrics with error
187189
if handler._metrics_recorder is not None:
188-
handler._metrics_recorder.record(
190+
handler._metrics_recorder.record_extended(
189191
span, invocation, error_type=error_obj.type.__qualname__
190192
)
191193

0 commit comments

Comments
 (0)