mirror of
https://github.com/langgenius/dify.git
synced 2026-05-01 07:58:02 +08:00
feat(telemetry): add input/output token split to enterprise OTEL traces
- Add PROMPT_TOKENS and COMPLETION_TOKENS to WorkflowNodeExecutionMetadataKey - Store prompt/completion tokens in node execution metadata JSON (no schema change) - Calculate workflow-level token split by summing node executions on-the-fly - Export gen_ai.usage.input_tokens and output_tokens to enterprise telemetry - Add semantic convention constants for token attributes - Maintain backward compatibility (historical data shows null) BREAKING: None MIGRATION: None (uses JSON metadata, no schema changes)
This commit is contained in:
@ -439,6 +439,8 @@ class WorkflowPersistenceLayer(GraphEngineLayer):
|
||||
"created_at": domain_execution.created_at,
|
||||
"finished_at": domain_execution.finished_at,
|
||||
"total_tokens": meta.get(WorkflowNodeExecutionMetadataKey.TOTAL_TOKENS, 0),
|
||||
"prompt_tokens": meta.get(WorkflowNodeExecutionMetadataKey.PROMPT_TOKENS),
|
||||
"completion_tokens": meta.get(WorkflowNodeExecutionMetadataKey.COMPLETION_TOKENS),
|
||||
"total_price": meta.get(WorkflowNodeExecutionMetadataKey.TOTAL_PRICE, 0.0),
|
||||
"currency": meta.get(WorkflowNodeExecutionMetadataKey.CURRENCY),
|
||||
"tool_name": (meta.get(WorkflowNodeExecutionMetadataKey.TOOL_INFO) or {}).get("tool_name")
|
||||
|
||||
Reference in New Issue
Block a user