mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
feat(core): Improve Langsmith traces for AI executions (#9081)
Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
26
packages/@n8n/nodes-langchain/utils/tracing.ts
Normal file
26
packages/@n8n/nodes-langchain/utils/tracing.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { BaseCallbackConfig } from '@langchain/core/callbacks/manager';
|
||||
import type { IExecuteFunctions } from 'n8n-workflow';
|
||||
|
||||
interface TracingConfig {
|
||||
additionalMetadata?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export function getTracingConfig(
|
||||
context: IExecuteFunctions,
|
||||
config: TracingConfig = {},
|
||||
): BaseCallbackConfig {
|
||||
const parentRunManager = context.getParentCallbackManager
|
||||
? context.getParentCallbackManager()
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
runName: `[${context.getWorkflow().name}] ${context.getNode().name}`,
|
||||
metadata: {
|
||||
execution_id: context.getExecutionId(),
|
||||
workflow: context.getWorkflow(),
|
||||
node: context.getNode().name,
|
||||
...(config.additionalMetadata ?? {}),
|
||||
},
|
||||
callbacks: parentRunManager,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user