@illuma-ai/observability-langchain 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/callback-handler.d.ts +196 -0
- package/dist/callback-handler.d.ts.map +1 -0
- package/dist/callback-handler.js +469 -0
- package/dist/callback-handler.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +17 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
2
|
+
import type { Serialized } from '@langchain/core/load/serializable';
|
|
3
|
+
import type { LLMResult } from '@langchain/core/outputs';
|
|
4
|
+
import type { Document } from '@langchain/core/documents';
|
|
5
|
+
import type { ObserveClient, ObserveClientOptions } from '@illuma-ai/observe-sdk';
|
|
6
|
+
/**
|
|
7
|
+
* Options for constructing the ObservabilityCallbackHandler.
|
|
8
|
+
* Provide either a pre-configured `client` instance, or `clientOptions`
|
|
9
|
+
* to have the handler create one internally.
|
|
10
|
+
*/
|
|
11
|
+
export interface ObservabilityCallbackHandlerOptions {
|
|
12
|
+
/** Pre-configured ObserveClient instance */
|
|
13
|
+
client?: ObserveClient;
|
|
14
|
+
/** Options to construct an ObserveClient (used if `client` is not provided) */
|
|
15
|
+
clientOptions?: ObserveClientOptions;
|
|
16
|
+
/** Optional trace name override (default: "langchain-run") */
|
|
17
|
+
traceName?: string;
|
|
18
|
+
/** Optional user ID to associate with the trace */
|
|
19
|
+
userId?: string;
|
|
20
|
+
/** Optional session ID to associate with the trace */
|
|
21
|
+
sessionId?: string;
|
|
22
|
+
/** Optional tags for the trace */
|
|
23
|
+
tags?: string[];
|
|
24
|
+
/** Optional metadata for the trace */
|
|
25
|
+
metadata?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* LangChain callback handler that sends trace data to Illuma Observe.
|
|
29
|
+
*
|
|
30
|
+
* The handler maps LangChain's run hierarchy to Illuma Observe's trace model:
|
|
31
|
+
* - The first (root) run lazily creates a **trace**
|
|
32
|
+
* - LLM runs create **generation** observations (with updates on end/error)
|
|
33
|
+
* - Chain, tool, and retriever runs create **span** observations (with updates on end/error)
|
|
34
|
+
* - Parent/child relationships are preserved via `parentObservationId`
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { ObservabilityCallbackHandler } from '@illuma-ai/observability-langchain';
|
|
39
|
+
* import { ObserveClient } from '@illuma-ai/observe-sdk';
|
|
40
|
+
*
|
|
41
|
+
* const client = new ObserveClient({
|
|
42
|
+
* publicKey: 'pk-...',
|
|
43
|
+
* secretKey: 'sk-...',
|
|
44
|
+
* baseUrl: 'https://observe.illuma.ai',
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* const handler = new ObservabilityCallbackHandler({ client });
|
|
48
|
+
* const result = await chain.invoke({ input: 'Hello' }, { callbacks: [handler] });
|
|
49
|
+
*
|
|
50
|
+
* await client.shutdown(); // flush all pending events
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare class ObservabilityCallbackHandler extends BaseCallbackHandler {
|
|
54
|
+
name: string;
|
|
55
|
+
private client;
|
|
56
|
+
private ownsClient;
|
|
57
|
+
/** Trace-level configuration */
|
|
58
|
+
private traceName;
|
|
59
|
+
private userId?;
|
|
60
|
+
private sessionId?;
|
|
61
|
+
private traceTags?;
|
|
62
|
+
private traceMetadata?;
|
|
63
|
+
/**
|
|
64
|
+
* Maps LangChain runId -> internal run state.
|
|
65
|
+
* Used to correlate start/end/error callbacks for the same run.
|
|
66
|
+
*/
|
|
67
|
+
private runs;
|
|
68
|
+
/**
|
|
69
|
+
* The root trace ID for this handler instance.
|
|
70
|
+
* Created lazily on the first root-level run.
|
|
71
|
+
*/
|
|
72
|
+
private rootTraceId;
|
|
73
|
+
constructor(options: ObservabilityCallbackHandlerOptions);
|
|
74
|
+
/**
|
|
75
|
+
* Called when an LLM call starts. Creates a generation-create event.
|
|
76
|
+
* @param llm - Serialized LLM descriptor
|
|
77
|
+
* @param prompts - The prompt strings sent to the LLM
|
|
78
|
+
* @param runId - Unique ID for this LangChain run
|
|
79
|
+
* @param parentRunId - Parent run ID if this is a nested call
|
|
80
|
+
*/
|
|
81
|
+
handleLLMStart(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, _extraParams?: Record<string, unknown>, _tags?: string[], _metadata?: Record<string, unknown>): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Called when an LLM call completes. Creates a generation-update event
|
|
84
|
+
* with the model output and token usage.
|
|
85
|
+
* @param output - The LLM result containing generations and metadata
|
|
86
|
+
* @param runId - The run ID matching the preceding handleLLMStart
|
|
87
|
+
*/
|
|
88
|
+
handleLLMEnd(output: LLMResult, runId: string): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Called when an LLM call errors. Creates a generation-update with error status.
|
|
91
|
+
* @param err - The error that occurred
|
|
92
|
+
* @param runId - The run ID matching the preceding handleLLMStart
|
|
93
|
+
*/
|
|
94
|
+
handleLLMError(err: Error, runId: string): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Called when a chain starts. Creates a span-create event.
|
|
97
|
+
* If this is the first callback, the root trace is also created.
|
|
98
|
+
* @param chain - Serialized chain descriptor
|
|
99
|
+
* @param inputs - The input object passed to the chain
|
|
100
|
+
* @param runId - Unique ID for this LangChain run
|
|
101
|
+
* @param parentRunId - Parent run ID if this is a nested call
|
|
102
|
+
*/
|
|
103
|
+
handleChainStart(chain: Serialized, inputs: Record<string, unknown>, runId: string, parentRunId?: string): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Called when a chain completes. Creates a span-update with the outputs.
|
|
106
|
+
* @param outputs - The output object returned by the chain
|
|
107
|
+
* @param runId - The run ID matching the preceding handleChainStart
|
|
108
|
+
*/
|
|
109
|
+
handleChainEnd(outputs: Record<string, unknown>, runId: string): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Called when a chain errors. Creates a span-update with error status.
|
|
112
|
+
* @param err - The error that occurred
|
|
113
|
+
* @param runId - The run ID matching the preceding handleChainStart
|
|
114
|
+
*/
|
|
115
|
+
handleChainError(err: Error, runId: string): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Called when a tool invocation starts. Creates a span-create event
|
|
118
|
+
* with the tool name and input.
|
|
119
|
+
* @param tool - Serialized tool descriptor
|
|
120
|
+
* @param input - The input string passed to the tool
|
|
121
|
+
* @param runId - Unique ID for this LangChain run
|
|
122
|
+
* @param parentRunId - Parent run ID if this is a nested call
|
|
123
|
+
*/
|
|
124
|
+
handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Called when a tool invocation completes. Creates a span-update with the output.
|
|
127
|
+
* @param output - The output string returned by the tool
|
|
128
|
+
* @param runId - The run ID matching the preceding handleToolStart
|
|
129
|
+
*/
|
|
130
|
+
handleToolEnd(output: string, runId: string): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Called when a tool invocation errors. Creates a span-update with error status.
|
|
133
|
+
* @param err - The error that occurred
|
|
134
|
+
* @param runId - The run ID matching the preceding handleToolStart
|
|
135
|
+
*/
|
|
136
|
+
handleToolError(err: Error, runId: string): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Called when a retriever query starts. Creates a span-create event
|
|
139
|
+
* for the retrieval operation.
|
|
140
|
+
* @param retriever - Serialized retriever descriptor
|
|
141
|
+
* @param query - The search query string
|
|
142
|
+
* @param runId - Unique ID for this LangChain run
|
|
143
|
+
* @param parentRunId - Parent run ID if this is a nested call
|
|
144
|
+
*/
|
|
145
|
+
handleRetrieverStart(retriever: Serialized, query: string, runId: string, parentRunId?: string): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Called when a retriever query completes. Creates a span-update
|
|
148
|
+
* with the retrieved documents.
|
|
149
|
+
* @param documents - The retrieved Document objects
|
|
150
|
+
* @param runId - The run ID matching the preceding handleRetrieverStart
|
|
151
|
+
*/
|
|
152
|
+
handleRetrieverEnd(documents: Document[], runId: string): Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Called when a retriever query errors. Creates a span-update with error status.
|
|
155
|
+
* @param err - The error that occurred
|
|
156
|
+
* @param runId - The run ID matching the preceding handleRetrieverStart
|
|
157
|
+
*/
|
|
158
|
+
handleRetrieverError(err: Error, runId: string): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* Returns the trace ID for this handler instance, or null if no trace
|
|
161
|
+
* has been created yet (i.e., no callbacks have fired).
|
|
162
|
+
*/
|
|
163
|
+
getTraceId(): string | null;
|
|
164
|
+
/**
|
|
165
|
+
* Flush all pending events to the Illuma Observe API.
|
|
166
|
+
* Delegates to the underlying ObserveClient.flush().
|
|
167
|
+
*/
|
|
168
|
+
flushAsync(): Promise<void>;
|
|
169
|
+
/**
|
|
170
|
+
* Shut down the handler. If the handler owns the client (created via
|
|
171
|
+
* `clientOptions`), the client is fully shut down. Otherwise, only a
|
|
172
|
+
* flush is performed to avoid disrupting a shared client.
|
|
173
|
+
*/
|
|
174
|
+
shutdown(): Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* Lazily creates the root trace on the first callback.
|
|
177
|
+
* Subsequent calls return the existing trace ID.
|
|
178
|
+
*
|
|
179
|
+
* @param input - Optional input to record on the trace (from the first chain)
|
|
180
|
+
* @returns The trace ID for this handler instance
|
|
181
|
+
*/
|
|
182
|
+
private ensureTrace;
|
|
183
|
+
/**
|
|
184
|
+
* Push a raw ingestion event into the ObserveClient's internal queue.
|
|
185
|
+
*
|
|
186
|
+
* The SDK's public API (TraceClient.generation/span) only supports *-create
|
|
187
|
+
* events, but our callback handler needs *-update events as well.
|
|
188
|
+
* Since both packages are owned by Illuma, we access the client's internal
|
|
189
|
+
* queue directly. The queue is a simple array that gets drained on flush.
|
|
190
|
+
*
|
|
191
|
+
* @param type - The ingestion event type (e.g., 'generation-create', 'span-update')
|
|
192
|
+
* @param body - The event body payload
|
|
193
|
+
*/
|
|
194
|
+
private pushEvent;
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=callback-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callback-handler.d.ts","sourceRoot":"","sources":["../src/callback-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EAGrB,MAAM,wBAAwB,CAAC;AAqBhC;;;;GAIG;AACH,MAAM,WAAW,mCAAmC;IAClD,4CAA4C;IAC5C,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,+EAA+E;IAC/E,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC,8DAA8D;IAC9D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,sCAAsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAgBD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,4BAA6B,SAAQ,mBAAmB;IACnE,IAAI,SAAkC;IAEtC,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,UAAU,CAAU;IAE5B,gCAAgC;IAChC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAA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;;;;OAOG;IACG,eAAe,CACnB,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC;IA6BhB;;;;OAIG;IACG,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAcjE;;;;OAIG;IACG,eAAe,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB/D;;;;;;;OAOG;IACG,oBAAoB,CACxB,SAAS,EAAE,UAAU,EACrB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC;IA6BhB;;;;;OAKG;IACG,kBAAkB,CACtB,SAAS,EAAE,QAAQ,EAAE,EACrB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC;IAuBhB;;;;OAIG;IACG,oBAAoB,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBpE;;;OAGG;IACH,UAAU,IAAI,MAAM,GAAG,IAAI;IAI3B;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAY/B;;;;;;OAMG;IACH,OAAO,CAAC,WAAW;IAoBnB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,SAAS;CAuBlB"}
|
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
3
|
+
/**
|
|
4
|
+
* LangChain callback handler that sends trace data to Illuma Observe.
|
|
5
|
+
*
|
|
6
|
+
* The handler maps LangChain's run hierarchy to Illuma Observe's trace model:
|
|
7
|
+
* - The first (root) run lazily creates a **trace**
|
|
8
|
+
* - LLM runs create **generation** observations (with updates on end/error)
|
|
9
|
+
* - Chain, tool, and retriever runs create **span** observations (with updates on end/error)
|
|
10
|
+
* - Parent/child relationships are preserved via `parentObservationId`
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { ObservabilityCallbackHandler } from '@illuma-ai/observability-langchain';
|
|
15
|
+
* import { ObserveClient } from '@illuma-ai/observe-sdk';
|
|
16
|
+
*
|
|
17
|
+
* const client = new ObserveClient({
|
|
18
|
+
* publicKey: 'pk-...',
|
|
19
|
+
* secretKey: 'sk-...',
|
|
20
|
+
* baseUrl: 'https://observe.illuma.ai',
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* const handler = new ObservabilityCallbackHandler({ client });
|
|
24
|
+
* const result = await chain.invoke({ input: 'Hello' }, { callbacks: [handler] });
|
|
25
|
+
*
|
|
26
|
+
* await client.shutdown(); // flush all pending events
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export class ObservabilityCallbackHandler extends BaseCallbackHandler {
|
|
30
|
+
name = 'ObservabilityCallbackHandler';
|
|
31
|
+
client;
|
|
32
|
+
ownsClient;
|
|
33
|
+
/** Trace-level configuration */
|
|
34
|
+
traceName;
|
|
35
|
+
userId;
|
|
36
|
+
sessionId;
|
|
37
|
+
traceTags;
|
|
38
|
+
traceMetadata;
|
|
39
|
+
/**
|
|
40
|
+
* Maps LangChain runId -> internal run state.
|
|
41
|
+
* Used to correlate start/end/error callbacks for the same run.
|
|
42
|
+
*/
|
|
43
|
+
runs = new Map();
|
|
44
|
+
/**
|
|
45
|
+
* The root trace ID for this handler instance.
|
|
46
|
+
* Created lazily on the first root-level run.
|
|
47
|
+
*/
|
|
48
|
+
rootTraceId = null;
|
|
49
|
+
constructor(options) {
|
|
50
|
+
super();
|
|
51
|
+
if (options.client) {
|
|
52
|
+
this.client = options.client;
|
|
53
|
+
this.ownsClient = false;
|
|
54
|
+
}
|
|
55
|
+
else if (options.clientOptions) {
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
57
|
+
const { ObserveClient: ClientCtor } = require('@illuma-ai/observe-sdk');
|
|
58
|
+
this.client = new ClientCtor(options.clientOptions);
|
|
59
|
+
this.ownsClient = true;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
throw new Error('ObservabilityCallbackHandler requires either a `client` or `clientOptions`.');
|
|
63
|
+
}
|
|
64
|
+
this.traceName = options.traceName ?? 'langchain-run';
|
|
65
|
+
this.userId = options.userId;
|
|
66
|
+
this.sessionId = options.sessionId;
|
|
67
|
+
this.traceTags = options.tags;
|
|
68
|
+
this.traceMetadata = options.metadata;
|
|
69
|
+
}
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
// LLM callbacks
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
/**
|
|
74
|
+
* Called when an LLM call starts. Creates a generation-create event.
|
|
75
|
+
* @param llm - Serialized LLM descriptor
|
|
76
|
+
* @param prompts - The prompt strings sent to the LLM
|
|
77
|
+
* @param runId - Unique ID for this LangChain run
|
|
78
|
+
* @param parentRunId - Parent run ID if this is a nested call
|
|
79
|
+
*/
|
|
80
|
+
async handleLLMStart(llm, prompts, runId, parentRunId, _extraParams, _tags, _metadata) {
|
|
81
|
+
const traceId = this.ensureTrace();
|
|
82
|
+
const observationId = randomUUID();
|
|
83
|
+
const startTime = new Date().toISOString();
|
|
84
|
+
const name = llm.id?.[llm.id.length - 1] ?? 'LLM';
|
|
85
|
+
this.runs.set(runId, {
|
|
86
|
+
observationId,
|
|
87
|
+
traceId,
|
|
88
|
+
parentObservationId: parentRunId ? this.runs.get(parentRunId)?.observationId : undefined,
|
|
89
|
+
startTime,
|
|
90
|
+
type: 'generation',
|
|
91
|
+
name,
|
|
92
|
+
});
|
|
93
|
+
this.pushEvent('generation-create', {
|
|
94
|
+
id: observationId,
|
|
95
|
+
traceId,
|
|
96
|
+
parentObservationId: parentRunId ? this.runs.get(parentRunId)?.observationId : undefined,
|
|
97
|
+
name,
|
|
98
|
+
startTime,
|
|
99
|
+
input: prompts,
|
|
100
|
+
metadata: {
|
|
101
|
+
langchainRunId: runId,
|
|
102
|
+
serializedLlm: llm,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Called when an LLM call completes. Creates a generation-update event
|
|
108
|
+
* with the model output and token usage.
|
|
109
|
+
* @param output - The LLM result containing generations and metadata
|
|
110
|
+
* @param runId - The run ID matching the preceding handleLLMStart
|
|
111
|
+
*/
|
|
112
|
+
async handleLLMEnd(output, runId) {
|
|
113
|
+
const run = this.runs.get(runId);
|
|
114
|
+
if (!run)
|
|
115
|
+
return;
|
|
116
|
+
const endTime = new Date().toISOString();
|
|
117
|
+
const generation = output.generations?.[0]?.[0];
|
|
118
|
+
// Extract token usage from LLM response metadata.
|
|
119
|
+
// Different LLM providers place usage stats in different fields.
|
|
120
|
+
const llmOutput = output.llmOutput;
|
|
121
|
+
const tokenUsage = (llmOutput?.tokenUsage ?? llmOutput?.usage ?? {});
|
|
122
|
+
this.pushEvent('generation-update', {
|
|
123
|
+
id: run.observationId,
|
|
124
|
+
traceId: run.traceId,
|
|
125
|
+
endTime,
|
|
126
|
+
output: generation?.text ?? output.generations,
|
|
127
|
+
model: (llmOutput?.modelName ?? llmOutput?.model ?? undefined),
|
|
128
|
+
usage: {
|
|
129
|
+
promptTokens: (tokenUsage.promptTokens ?? tokenUsage.prompt_tokens),
|
|
130
|
+
completionTokens: (tokenUsage.completionTokens ?? tokenUsage.completion_tokens),
|
|
131
|
+
totalTokens: (tokenUsage.totalTokens ?? tokenUsage.total_tokens),
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
this.runs.delete(runId);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Called when an LLM call errors. Creates a generation-update with error status.
|
|
138
|
+
* @param err - The error that occurred
|
|
139
|
+
* @param runId - The run ID matching the preceding handleLLMStart
|
|
140
|
+
*/
|
|
141
|
+
async handleLLMError(err, runId) {
|
|
142
|
+
const run = this.runs.get(runId);
|
|
143
|
+
if (!run)
|
|
144
|
+
return;
|
|
145
|
+
this.pushEvent('generation-update', {
|
|
146
|
+
id: run.observationId,
|
|
147
|
+
traceId: run.traceId,
|
|
148
|
+
endTime: new Date().toISOString(),
|
|
149
|
+
level: 'ERROR',
|
|
150
|
+
statusMessage: err.message,
|
|
151
|
+
metadata: { error: err.stack ?? err.message },
|
|
152
|
+
});
|
|
153
|
+
this.runs.delete(runId);
|
|
154
|
+
}
|
|
155
|
+
// ---------------------------------------------------------------------------
|
|
156
|
+
// Chain callbacks
|
|
157
|
+
// ---------------------------------------------------------------------------
|
|
158
|
+
/**
|
|
159
|
+
* Called when a chain starts. Creates a span-create event.
|
|
160
|
+
* If this is the first callback, the root trace is also created.
|
|
161
|
+
* @param chain - Serialized chain descriptor
|
|
162
|
+
* @param inputs - The input object passed to the chain
|
|
163
|
+
* @param runId - Unique ID for this LangChain run
|
|
164
|
+
* @param parentRunId - Parent run ID if this is a nested call
|
|
165
|
+
*/
|
|
166
|
+
async handleChainStart(chain, inputs, runId, parentRunId) {
|
|
167
|
+
const traceId = this.ensureTrace(inputs);
|
|
168
|
+
const observationId = randomUUID();
|
|
169
|
+
const startTime = new Date().toISOString();
|
|
170
|
+
const name = chain.id?.[chain.id.length - 1] ?? 'Chain';
|
|
171
|
+
this.runs.set(runId, {
|
|
172
|
+
observationId,
|
|
173
|
+
traceId,
|
|
174
|
+
parentObservationId: parentRunId ? this.runs.get(parentRunId)?.observationId : undefined,
|
|
175
|
+
startTime,
|
|
176
|
+
type: 'span',
|
|
177
|
+
name,
|
|
178
|
+
});
|
|
179
|
+
this.pushEvent('span-create', {
|
|
180
|
+
id: observationId,
|
|
181
|
+
traceId,
|
|
182
|
+
parentObservationId: parentRunId ? this.runs.get(parentRunId)?.observationId : undefined,
|
|
183
|
+
name,
|
|
184
|
+
startTime,
|
|
185
|
+
input: inputs,
|
|
186
|
+
metadata: {
|
|
187
|
+
langchainRunId: runId,
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Called when a chain completes. Creates a span-update with the outputs.
|
|
193
|
+
* @param outputs - The output object returned by the chain
|
|
194
|
+
* @param runId - The run ID matching the preceding handleChainStart
|
|
195
|
+
*/
|
|
196
|
+
async handleChainEnd(outputs, runId) {
|
|
197
|
+
const run = this.runs.get(runId);
|
|
198
|
+
if (!run)
|
|
199
|
+
return;
|
|
200
|
+
this.pushEvent('span-update', {
|
|
201
|
+
id: run.observationId,
|
|
202
|
+
traceId: run.traceId,
|
|
203
|
+
endTime: new Date().toISOString(),
|
|
204
|
+
output: outputs,
|
|
205
|
+
});
|
|
206
|
+
this.runs.delete(runId);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Called when a chain errors. Creates a span-update with error status.
|
|
210
|
+
* @param err - The error that occurred
|
|
211
|
+
* @param runId - The run ID matching the preceding handleChainStart
|
|
212
|
+
*/
|
|
213
|
+
async handleChainError(err, runId) {
|
|
214
|
+
const run = this.runs.get(runId);
|
|
215
|
+
if (!run)
|
|
216
|
+
return;
|
|
217
|
+
this.pushEvent('span-update', {
|
|
218
|
+
id: run.observationId,
|
|
219
|
+
traceId: run.traceId,
|
|
220
|
+
endTime: new Date().toISOString(),
|
|
221
|
+
level: 'ERROR',
|
|
222
|
+
statusMessage: err.message,
|
|
223
|
+
metadata: { error: err.stack ?? err.message },
|
|
224
|
+
});
|
|
225
|
+
this.runs.delete(runId);
|
|
226
|
+
}
|
|
227
|
+
// ---------------------------------------------------------------------------
|
|
228
|
+
// Tool callbacks
|
|
229
|
+
// ---------------------------------------------------------------------------
|
|
230
|
+
/**
|
|
231
|
+
* Called when a tool invocation starts. Creates a span-create event
|
|
232
|
+
* with the tool name and input.
|
|
233
|
+
* @param tool - Serialized tool descriptor
|
|
234
|
+
* @param input - The input string passed to the tool
|
|
235
|
+
* @param runId - Unique ID for this LangChain run
|
|
236
|
+
* @param parentRunId - Parent run ID if this is a nested call
|
|
237
|
+
*/
|
|
238
|
+
async handleToolStart(tool, input, runId, parentRunId) {
|
|
239
|
+
const traceId = this.ensureTrace();
|
|
240
|
+
const observationId = randomUUID();
|
|
241
|
+
const startTime = new Date().toISOString();
|
|
242
|
+
const name = tool.id?.[tool.id.length - 1] ?? 'Tool';
|
|
243
|
+
this.runs.set(runId, {
|
|
244
|
+
observationId,
|
|
245
|
+
traceId,
|
|
246
|
+
parentObservationId: parentRunId ? this.runs.get(parentRunId)?.observationId : undefined,
|
|
247
|
+
startTime,
|
|
248
|
+
type: 'span',
|
|
249
|
+
name,
|
|
250
|
+
});
|
|
251
|
+
this.pushEvent('span-create', {
|
|
252
|
+
id: observationId,
|
|
253
|
+
traceId,
|
|
254
|
+
parentObservationId: parentRunId ? this.runs.get(parentRunId)?.observationId : undefined,
|
|
255
|
+
name: `Tool: ${name}`,
|
|
256
|
+
startTime,
|
|
257
|
+
input,
|
|
258
|
+
metadata: {
|
|
259
|
+
langchainRunId: runId,
|
|
260
|
+
observationType: 'tool',
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Called when a tool invocation completes. Creates a span-update with the output.
|
|
266
|
+
* @param output - The output string returned by the tool
|
|
267
|
+
* @param runId - The run ID matching the preceding handleToolStart
|
|
268
|
+
*/
|
|
269
|
+
async handleToolEnd(output, runId) {
|
|
270
|
+
const run = this.runs.get(runId);
|
|
271
|
+
if (!run)
|
|
272
|
+
return;
|
|
273
|
+
this.pushEvent('span-update', {
|
|
274
|
+
id: run.observationId,
|
|
275
|
+
traceId: run.traceId,
|
|
276
|
+
endTime: new Date().toISOString(),
|
|
277
|
+
output,
|
|
278
|
+
});
|
|
279
|
+
this.runs.delete(runId);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Called when a tool invocation errors. Creates a span-update with error status.
|
|
283
|
+
* @param err - The error that occurred
|
|
284
|
+
* @param runId - The run ID matching the preceding handleToolStart
|
|
285
|
+
*/
|
|
286
|
+
async handleToolError(err, runId) {
|
|
287
|
+
const run = this.runs.get(runId);
|
|
288
|
+
if (!run)
|
|
289
|
+
return;
|
|
290
|
+
this.pushEvent('span-update', {
|
|
291
|
+
id: run.observationId,
|
|
292
|
+
traceId: run.traceId,
|
|
293
|
+
endTime: new Date().toISOString(),
|
|
294
|
+
level: 'ERROR',
|
|
295
|
+
statusMessage: err.message,
|
|
296
|
+
metadata: { error: err.stack ?? err.message },
|
|
297
|
+
});
|
|
298
|
+
this.runs.delete(runId);
|
|
299
|
+
}
|
|
300
|
+
// ---------------------------------------------------------------------------
|
|
301
|
+
// Retriever callbacks
|
|
302
|
+
// ---------------------------------------------------------------------------
|
|
303
|
+
/**
|
|
304
|
+
* Called when a retriever query starts. Creates a span-create event
|
|
305
|
+
* for the retrieval operation.
|
|
306
|
+
* @param retriever - Serialized retriever descriptor
|
|
307
|
+
* @param query - The search query string
|
|
308
|
+
* @param runId - Unique ID for this LangChain run
|
|
309
|
+
* @param parentRunId - Parent run ID if this is a nested call
|
|
310
|
+
*/
|
|
311
|
+
async handleRetrieverStart(retriever, query, runId, parentRunId) {
|
|
312
|
+
const traceId = this.ensureTrace();
|
|
313
|
+
const observationId = randomUUID();
|
|
314
|
+
const startTime = new Date().toISOString();
|
|
315
|
+
const name = retriever.id?.[retriever.id.length - 1] ?? 'Retriever';
|
|
316
|
+
this.runs.set(runId, {
|
|
317
|
+
observationId,
|
|
318
|
+
traceId,
|
|
319
|
+
parentObservationId: parentRunId ? this.runs.get(parentRunId)?.observationId : undefined,
|
|
320
|
+
startTime,
|
|
321
|
+
type: 'span',
|
|
322
|
+
name,
|
|
323
|
+
});
|
|
324
|
+
this.pushEvent('span-create', {
|
|
325
|
+
id: observationId,
|
|
326
|
+
traceId,
|
|
327
|
+
parentObservationId: parentRunId ? this.runs.get(parentRunId)?.observationId : undefined,
|
|
328
|
+
name: `Retriever: ${name}`,
|
|
329
|
+
startTime,
|
|
330
|
+
input: query,
|
|
331
|
+
metadata: {
|
|
332
|
+
langchainRunId: runId,
|
|
333
|
+
observationType: 'retriever',
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Called when a retriever query completes. Creates a span-update
|
|
339
|
+
* with the retrieved documents.
|
|
340
|
+
* @param documents - The retrieved Document objects
|
|
341
|
+
* @param runId - The run ID matching the preceding handleRetrieverStart
|
|
342
|
+
*/
|
|
343
|
+
async handleRetrieverEnd(documents, runId) {
|
|
344
|
+
const run = this.runs.get(runId);
|
|
345
|
+
if (!run)
|
|
346
|
+
return;
|
|
347
|
+
// Serialize documents to a lightweight format for observability
|
|
348
|
+
const serializedDocs = documents.map((doc) => ({
|
|
349
|
+
pageContent: doc.pageContent,
|
|
350
|
+
metadata: doc.metadata,
|
|
351
|
+
}));
|
|
352
|
+
this.pushEvent('span-update', {
|
|
353
|
+
id: run.observationId,
|
|
354
|
+
traceId: run.traceId,
|
|
355
|
+
endTime: new Date().toISOString(),
|
|
356
|
+
output: serializedDocs,
|
|
357
|
+
metadata: {
|
|
358
|
+
documentCount: documents.length,
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
this.runs.delete(runId);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Called when a retriever query errors. Creates a span-update with error status.
|
|
365
|
+
* @param err - The error that occurred
|
|
366
|
+
* @param runId - The run ID matching the preceding handleRetrieverStart
|
|
367
|
+
*/
|
|
368
|
+
async handleRetrieverError(err, runId) {
|
|
369
|
+
const run = this.runs.get(runId);
|
|
370
|
+
if (!run)
|
|
371
|
+
return;
|
|
372
|
+
this.pushEvent('span-update', {
|
|
373
|
+
id: run.observationId,
|
|
374
|
+
traceId: run.traceId,
|
|
375
|
+
endTime: new Date().toISOString(),
|
|
376
|
+
level: 'ERROR',
|
|
377
|
+
statusMessage: err.message,
|
|
378
|
+
metadata: { error: err.stack ?? err.message },
|
|
379
|
+
});
|
|
380
|
+
this.runs.delete(runId);
|
|
381
|
+
}
|
|
382
|
+
// ---------------------------------------------------------------------------
|
|
383
|
+
// Public helpers
|
|
384
|
+
// ---------------------------------------------------------------------------
|
|
385
|
+
/**
|
|
386
|
+
* Returns the trace ID for this handler instance, or null if no trace
|
|
387
|
+
* has been created yet (i.e., no callbacks have fired).
|
|
388
|
+
*/
|
|
389
|
+
getTraceId() {
|
|
390
|
+
return this.rootTraceId;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Flush all pending events to the Illuma Observe API.
|
|
394
|
+
* Delegates to the underlying ObserveClient.flush().
|
|
395
|
+
*/
|
|
396
|
+
async flushAsync() {
|
|
397
|
+
await this.client.flush();
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Shut down the handler. If the handler owns the client (created via
|
|
401
|
+
* `clientOptions`), the client is fully shut down. Otherwise, only a
|
|
402
|
+
* flush is performed to avoid disrupting a shared client.
|
|
403
|
+
*/
|
|
404
|
+
async shutdown() {
|
|
405
|
+
if (this.ownsClient) {
|
|
406
|
+
await this.client.shutdown();
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
await this.client.flush();
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
// ---------------------------------------------------------------------------
|
|
413
|
+
// Private helpers
|
|
414
|
+
// ---------------------------------------------------------------------------
|
|
415
|
+
/**
|
|
416
|
+
* Lazily creates the root trace on the first callback.
|
|
417
|
+
* Subsequent calls return the existing trace ID.
|
|
418
|
+
*
|
|
419
|
+
* @param input - Optional input to record on the trace (from the first chain)
|
|
420
|
+
* @returns The trace ID for this handler instance
|
|
421
|
+
*/
|
|
422
|
+
ensureTrace(input) {
|
|
423
|
+
if (this.rootTraceId) {
|
|
424
|
+
return this.rootTraceId;
|
|
425
|
+
}
|
|
426
|
+
this.rootTraceId = randomUUID();
|
|
427
|
+
this.pushEvent('trace-create', {
|
|
428
|
+
id: this.rootTraceId,
|
|
429
|
+
name: this.traceName,
|
|
430
|
+
userId: this.userId,
|
|
431
|
+
sessionId: this.sessionId,
|
|
432
|
+
tags: this.traceTags,
|
|
433
|
+
metadata: this.traceMetadata,
|
|
434
|
+
input,
|
|
435
|
+
});
|
|
436
|
+
return this.rootTraceId;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Push a raw ingestion event into the ObserveClient's internal queue.
|
|
440
|
+
*
|
|
441
|
+
* The SDK's public API (TraceClient.generation/span) only supports *-create
|
|
442
|
+
* events, but our callback handler needs *-update events as well.
|
|
443
|
+
* Since both packages are owned by Illuma, we access the client's internal
|
|
444
|
+
* queue directly. The queue is a simple array that gets drained on flush.
|
|
445
|
+
*
|
|
446
|
+
* @param type - The ingestion event type (e.g., 'generation-create', 'span-update')
|
|
447
|
+
* @param body - The event body payload
|
|
448
|
+
*/
|
|
449
|
+
pushEvent(type, body) {
|
|
450
|
+
const event = {
|
|
451
|
+
id: randomUUID(),
|
|
452
|
+
type,
|
|
453
|
+
timestamp: new Date().toISOString(),
|
|
454
|
+
body,
|
|
455
|
+
};
|
|
456
|
+
// Access the client's internal queue and flush threshold.
|
|
457
|
+
// SCALE: This is O(1) per event - just an array push.
|
|
458
|
+
const internal = this.client;
|
|
459
|
+
if (internal.stopped) {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
internal.queue.push(event);
|
|
463
|
+
// Trigger auto-flush if batch size threshold is reached
|
|
464
|
+
if (internal.queue.length >= internal.flushAt) {
|
|
465
|
+
void internal.flush();
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
//# sourceMappingURL=callback-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callback-handler.js","sourceRoot":"","sources":["../src/callback-handler.ts"],"names":[],"mappings":"AAAA,OAAO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|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,YAAY,EAAE,mCAAmC,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@illuma-ai/observability-langchain",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "LangChain callback handler for Illuma Observability",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": { ".": { "import": "./dist/index.js", "types": "./dist/index.d.ts" } },
|
|
9
|
+
"files": ["dist"],
|
|
10
|
+
"scripts": { "build": "tsc", "prepublishOnly": "npm run build" },
|
|
11
|
+
"dependencies": { "@illuma-ai/observe-sdk": "^0.1.0" },
|
|
12
|
+
"peerDependencies": { "@langchain/core": ">=0.1.0" },
|
|
13
|
+
"devDependencies": { "typescript": "^5.4.5", "@types/node": "^20.14.2", "@langchain/core": "^0.3.0" },
|
|
14
|
+
"publishConfig": { "access": "public" },
|
|
15
|
+
"repository": { "type": "git", "url": "https://github.com/illuma-ai/observability.git", "directory": "packages/observability-langchain" },
|
|
16
|
+
"license": "MIT"
|
|
17
|
+
}
|