-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Calculate token usage statistics using call stack #117 #118
Conversation
callInfo.childSpanIds.add(childSpanId); | ||
} | ||
|
||
public synchronized void setTokeUsage(String spanId, TokenUsage tokenUsage) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please correct type: setTokenUsage
public void calculateTokenUsage(ProxyContext context) { | ||
Entity entity = getEntityFromTracingContext(context); | ||
if (entity == null) { | ||
log.warn("Entity is not found by traceId={}", context.getTraceId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add prefix to locate the problem more easily: "Failed to calculate token usage"
public synchronized void link(String parentSpanId, String childSpanId) { | ||
CallInfo callInfo = spanIdToCallInfo.get(parentSpanId); | ||
if (callInfo == null) { | ||
log.warn("Parent span is not found by id: {}", parentSpanId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please improve logging in this class.
log.warn("Entity is not found by traceId={}", context.getTraceId()); | ||
return; | ||
} | ||
context.setTokenUsage(entity.calculate(context.getCurrentSpanId())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it better to do it only if it is missing? Some applications/models can compute it more precisely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can rely on applications/assistants any longer to compute statistics
private final List<String> roles; | ||
private final String name; | ||
private final boolean user; | ||
private final Map<String, CallInfo> spanIdToCallInfo = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move the logic related to token tracking to a separate class. e.g. TokenTracker
no longer valid since the core is moved to per request key authorization |
No description provided.