mirror of
https://github.com/n8n-io/n8n
synced 2026-04-21 15:47:20 +00:00
fix(core): Release LS trace clients on run finalization (no-changelog) (#28254)
Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
parent
98534c6db9
commit
320a4b244d
3 changed files with 16 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ export type { DomainAccessTracker } from './domain-access';
|
|||
export {
|
||||
createInstanceAiTraceContext,
|
||||
continueInstanceAiTraceContext,
|
||||
releaseTraceClient,
|
||||
withCurrentTraceSpan,
|
||||
} from './tracing/langsmith-tracing';
|
||||
export { createInstanceAgent } from './agent/instance-agent';
|
||||
|
|
|
|||
|
|
@ -423,6 +423,15 @@ function mergeRunTreeInputs(
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Unconditionally remove the cached LangSmith Client for a trace.
|
||||
* Call after run finalization (success or failure) so the Client and
|
||||
* its RunTree hierarchy can be garbage-collected.
|
||||
*/
|
||||
export function releaseTraceClient(traceId: string): void {
|
||||
traceClients.delete(traceId);
|
||||
}
|
||||
|
||||
export function getTraceParentRun(): RunTree | undefined {
|
||||
const overrideRun = traceParentOverrideStorage.getStore()?.current;
|
||||
if (overrideRun) {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import {
|
|||
PlannedTaskCoordinator,
|
||||
PlannedTaskStorage,
|
||||
applyPlannedTaskPermissions,
|
||||
releaseTraceClient,
|
||||
resumeAgentRun,
|
||||
RunStateRegistry,
|
||||
startBuildWorkflowAgentTask,
|
||||
|
|
@ -544,6 +545,8 @@ export class InstanceAiService {
|
|||
threadId: tracing.rootRun.metadata?.thread_id,
|
||||
error: getErrorMessage(error),
|
||||
});
|
||||
} finally {
|
||||
releaseTraceClient(tracing.rootRun.traceId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -574,6 +577,7 @@ export class InstanceAiService {
|
|||
private deleteTraceContextsForThread(threadId: string): void {
|
||||
for (const [runId, entry] of this.traceContextsByRunId) {
|
||||
if (entry.threadId === threadId) {
|
||||
releaseTraceClient(entry.tracing.rootRun.traceId);
|
||||
this.traceContextsByRunId.delete(runId);
|
||||
}
|
||||
}
|
||||
|
|
@ -609,6 +613,8 @@ export class InstanceAiService {
|
|||
traceRunId: traceContext.rootRun.id,
|
||||
error: getErrorMessage(error),
|
||||
});
|
||||
} finally {
|
||||
releaseTraceClient(traceContext.rootRun.traceId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue