@cloudbase/agent-observability 1.0.1-alpha.9
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/README.md +231 -0
- package/dist/chunk-NFEGQTCC.mjs +27 -0
- package/dist/chunk-NFEGQTCC.mjs.map +1 -0
- package/dist/chunk-ZGEMAYS4.mjs +716 -0
- package/dist/chunk-ZGEMAYS4.mjs.map +1 -0
- package/dist/esm-PGEDANAI.mjs +1030 -0
- package/dist/esm-PGEDANAI.mjs.map +1 -0
- package/dist/index.d.mts +728 -0
- package/dist/index.d.ts +728 -0
- package/dist/index.js +732 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +52 -0
- package/dist/index.mjs.map +1 -0
- package/dist/langchain.d.mts +108 -0
- package/dist/langchain.d.ts +108 -0
- package/dist/langchain.js +1237 -0
- package/dist/langchain.js.map +1 -0
- package/dist/langchain.mjs +535 -0
- package/dist/langchain.mjs.map +1 -0
- package/dist/server.d.mts +163 -0
- package/dist/server.d.ts +163 -0
- package/dist/server.js +1528 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +175 -0
- package/dist/server.mjs.map +1 -0
- package/package.json +91 -0
- package/src/core/attributes.ts +233 -0
- package/src/core/constants.ts +75 -0
- package/src/core/spanWrapper.ts +417 -0
- package/src/core/tracerProvider.ts +136 -0
- package/src/index.ts +775 -0
- package/src/langchain/CallbackHandler.ts +893 -0
- package/src/langchain/index.ts +7 -0
- package/src/server/config.ts +160 -0
- package/src/server/index.ts +21 -0
- package/src/server/setup.ts +344 -0
- package/src/types.ts +254 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,728 @@
|
|
|
1
|
+
import * as _opentelemetry_api from '@opentelemetry/api';
|
|
2
|
+
import { Span, TimeInput, Attributes, TracerProvider, SpanContext } from '@opentelemetry/api';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Types of observations (spans) supported by AG-Kit observability.
|
|
6
|
+
*
|
|
7
|
+
* These types align with OpenInference semantic conventions:
|
|
8
|
+
* https://github.com/Arize-ai/openinference/tree/main/spec
|
|
9
|
+
*
|
|
10
|
+
* - `span`: General-purpose operations (OpenInference: internal/span)
|
|
11
|
+
* - `llm`: Language model calls (OpenInference: LLM)
|
|
12
|
+
* - `embedding`: Text embedding operations (OpenInference: EMBEDDING)
|
|
13
|
+
* - `agent`: AI agent workflows (OpenInference: AGENT)
|
|
14
|
+
* - `tool`: Tool/function calls (OpenInference: TOOL)
|
|
15
|
+
* - `chain`: Multi-step workflows (OpenInference: CHAIN)
|
|
16
|
+
* - `retriever`: Document retrieval (OpenInference: RETRIEVER)
|
|
17
|
+
* - `reranker`: Result reranking (OpenInference: RERANKER)
|
|
18
|
+
* - `guardrail`: Safety checks (OpenInference: GUARDRAIL)
|
|
19
|
+
* - `evaluator`: Quality assessment (OpenInference: EVALUATOR)
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
type ObservationType = "span" | "llm" | "embedding" | "agent" | "tool" | "chain" | "retriever" | "reranker" | "guardrail" | "evaluator";
|
|
24
|
+
/**
|
|
25
|
+
* Severity levels for observations.
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
type ObservationLevel = "DEBUG" | "DEFAULT" | "WARNING" | "ERROR";
|
|
30
|
+
/**
|
|
31
|
+
* Token usage details for LLM calls.
|
|
32
|
+
*
|
|
33
|
+
* Follows OpenInference semantic convention:
|
|
34
|
+
* - llm.token_count.prompt
|
|
35
|
+
* - llm.token_count.completion
|
|
36
|
+
* - llm.token_count.total
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
type TokenUsage = {
|
|
41
|
+
/** Number of tokens in the prompt */
|
|
42
|
+
promptTokens?: number;
|
|
43
|
+
/** Number of tokens in the completion */
|
|
44
|
+
completionTokens?: number;
|
|
45
|
+
/** Total number of tokens */
|
|
46
|
+
totalTokens?: number;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Base attributes for all observation types.
|
|
50
|
+
*
|
|
51
|
+
* Uses OpenInference semantic conventions where applicable:
|
|
52
|
+
* - input.value: Input data
|
|
53
|
+
* - output.value: Output data
|
|
54
|
+
*
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
type BaseSpanAttributes = {
|
|
58
|
+
/** Input data for the operation */
|
|
59
|
+
input?: unknown;
|
|
60
|
+
/** Output data from the operation */
|
|
61
|
+
output?: unknown;
|
|
62
|
+
/** Additional metadata as key-value pairs */
|
|
63
|
+
metadata?: Record<string, unknown>;
|
|
64
|
+
/** Severity level of the observation */
|
|
65
|
+
level?: ObservationLevel;
|
|
66
|
+
/** Human-readable status message */
|
|
67
|
+
statusMessage?: string;
|
|
68
|
+
/** Version identifier for the code/model being tracked */
|
|
69
|
+
version?: string;
|
|
70
|
+
/** Environment where the operation is running (e.g., 'production', 'staging') */
|
|
71
|
+
environment?: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* LLM-specific attributes following OpenInference semantic conventions.
|
|
75
|
+
*
|
|
76
|
+
* Uses attributes like:
|
|
77
|
+
* - llm.model_name
|
|
78
|
+
* - llm.parameters.*
|
|
79
|
+
* - llm.token_count.*
|
|
80
|
+
* - llm.invocation_parameters
|
|
81
|
+
*
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
type LLMAttributes = BaseSpanAttributes & {
|
|
85
|
+
/** Timestamp when the model started generating completion */
|
|
86
|
+
completionStartTime?: Date;
|
|
87
|
+
/** Name of the language model (e.g., 'gpt-4', 'claude-3-opus') */
|
|
88
|
+
model?: string;
|
|
89
|
+
/** Parameters passed to the model (temperature, max_tokens, etc.) */
|
|
90
|
+
modelParameters?: Record<string, string | number>;
|
|
91
|
+
/** Token usage metrics */
|
|
92
|
+
usageDetails?: TokenUsage | Record<string, number>;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Embedding-specific attributes following OpenInference semantic conventions.
|
|
96
|
+
*
|
|
97
|
+
* Uses attributes like:
|
|
98
|
+
* - embedding.model_name
|
|
99
|
+
* - embedding.embeddings.*
|
|
100
|
+
*
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
103
|
+
type EmbeddingAttributes = LLMAttributes;
|
|
104
|
+
/**
|
|
105
|
+
* Tool-specific attributes following OpenInference semantic conventions.
|
|
106
|
+
*
|
|
107
|
+
* Uses attributes like:
|
|
108
|
+
* - tool.name
|
|
109
|
+
* - tool.description
|
|
110
|
+
* - tool.parameters
|
|
111
|
+
*
|
|
112
|
+
* @public
|
|
113
|
+
*/
|
|
114
|
+
type ToolAttributes = BaseSpanAttributes;
|
|
115
|
+
/**
|
|
116
|
+
* Agent-specific attributes following OpenInference semantic conventions.
|
|
117
|
+
*
|
|
118
|
+
* Uses attributes like:
|
|
119
|
+
* - agent.name
|
|
120
|
+
* - agent.* (various agent-specific metadata)
|
|
121
|
+
*
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
type AgentAttributes = BaseSpanAttributes;
|
|
125
|
+
/**
|
|
126
|
+
* Chain-specific attributes following OpenInference semantic conventions.
|
|
127
|
+
*
|
|
128
|
+
* Uses attributes like:
|
|
129
|
+
* - chain.name
|
|
130
|
+
* - chain.* (various chain-specific metadata)
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
type ChainAttributes = BaseSpanAttributes;
|
|
135
|
+
/**
|
|
136
|
+
* Retriever-specific attributes following OpenInference semantic conventions.
|
|
137
|
+
*
|
|
138
|
+
* Uses attributes like:
|
|
139
|
+
* - retriever.name
|
|
140
|
+
* - retriever.query
|
|
141
|
+
* - retriever.*
|
|
142
|
+
*
|
|
143
|
+
* @public
|
|
144
|
+
*/
|
|
145
|
+
type RetrieverAttributes = BaseSpanAttributes;
|
|
146
|
+
/**
|
|
147
|
+
* Reranker-specific attributes following OpenInference semantic conventions.
|
|
148
|
+
*
|
|
149
|
+
* Uses attributes like:
|
|
150
|
+
* - reranker.model_name
|
|
151
|
+
* - reranker.top_k
|
|
152
|
+
* - reranker.*
|
|
153
|
+
*
|
|
154
|
+
* @public
|
|
155
|
+
*/
|
|
156
|
+
type RerankerAttributes = BaseSpanAttributes;
|
|
157
|
+
/**
|
|
158
|
+
* Evaluator-specific attributes.
|
|
159
|
+
*
|
|
160
|
+
* @public
|
|
161
|
+
*/
|
|
162
|
+
type EvaluatorAttributes = BaseSpanAttributes;
|
|
163
|
+
/**
|
|
164
|
+
* Guardrail-specific attributes following OpenInference semantic conventions.
|
|
165
|
+
*
|
|
166
|
+
* Uses attributes like:
|
|
167
|
+
* - guardrail.name
|
|
168
|
+
* - guardrail.*
|
|
169
|
+
*
|
|
170
|
+
* @public
|
|
171
|
+
*/
|
|
172
|
+
type GuardrailAttributes = BaseSpanAttributes;
|
|
173
|
+
/**
|
|
174
|
+
* Union type for all observation attributes.
|
|
175
|
+
*
|
|
176
|
+
* @public
|
|
177
|
+
*/
|
|
178
|
+
type ObservationAttributes = BaseSpanAttributes & LLMAttributes & ToolAttributes & AgentAttributes & ChainAttributes & RetrieverAttributes & RerankerAttributes & EvaluatorAttributes & GuardrailAttributes;
|
|
179
|
+
/**
|
|
180
|
+
* Attributes for traces.
|
|
181
|
+
*
|
|
182
|
+
* Traces are the top-level containers that group related observations together.
|
|
183
|
+
* Uses OpenInference semantic conventions where applicable.
|
|
184
|
+
*
|
|
185
|
+
* @public
|
|
186
|
+
*/
|
|
187
|
+
type TraceAttributes = {
|
|
188
|
+
/** Human-readable name for the trace */
|
|
189
|
+
name?: string;
|
|
190
|
+
/** Identifier for the user associated with this trace */
|
|
191
|
+
userId?: string;
|
|
192
|
+
/** Session identifier for grouping related traces */
|
|
193
|
+
sessionId?: string;
|
|
194
|
+
/** Version identifier for the code/application */
|
|
195
|
+
version?: string;
|
|
196
|
+
/** Release identifier for deployment tracking */
|
|
197
|
+
release?: string;
|
|
198
|
+
/** Input data that initiated the trace */
|
|
199
|
+
input?: unknown;
|
|
200
|
+
/** Final output data from the trace */
|
|
201
|
+
output?: unknown;
|
|
202
|
+
/** Additional metadata for the trace */
|
|
203
|
+
metadata?: unknown;
|
|
204
|
+
/** Tags for categorizing and filtering traces */
|
|
205
|
+
tags?: string[];
|
|
206
|
+
/** Whether this trace should be publicly visible */
|
|
207
|
+
public?: boolean;
|
|
208
|
+
/** Environment where the trace was captured */
|
|
209
|
+
environment?: string;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Union type representing any observation wrapper.
|
|
214
|
+
*
|
|
215
|
+
* @public
|
|
216
|
+
*/
|
|
217
|
+
type Observation = ObservationSpan | ObservationLLM | ObservationEmbedding | ObservationAgent | ObservationTool | ObservationChain | ObservationRetriever | ObservationReranker | ObservationEvaluator | ObservationGuardrail;
|
|
218
|
+
/**
|
|
219
|
+
* Parameters for creating an observation wrapper.
|
|
220
|
+
*
|
|
221
|
+
* @internal
|
|
222
|
+
*/
|
|
223
|
+
type ObservationParams = {
|
|
224
|
+
otelSpan: Span;
|
|
225
|
+
type: ObservationType;
|
|
226
|
+
attributes?: BaseSpanAttributes | LLMAttributes;
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Base class for all observation wrappers.
|
|
230
|
+
*
|
|
231
|
+
* Provides common functionality for all observation types including:
|
|
232
|
+
* - OpenTelemetry span integration
|
|
233
|
+
* - Unique identification (span ID, trace ID)
|
|
234
|
+
* - Lifecycle management (update, end)
|
|
235
|
+
* - Trace context management
|
|
236
|
+
* - Child observation creation
|
|
237
|
+
*
|
|
238
|
+
* @internal
|
|
239
|
+
*/
|
|
240
|
+
declare abstract class BaseObservation {
|
|
241
|
+
/** The underlying OpenTelemetry span */
|
|
242
|
+
readonly otelSpan: Span;
|
|
243
|
+
/** The observation type */
|
|
244
|
+
readonly type: ObservationType;
|
|
245
|
+
/** The span ID from the OpenTelemetry span context */
|
|
246
|
+
id: string;
|
|
247
|
+
/** The trace ID from the OpenTelemetry span context */
|
|
248
|
+
traceId: string;
|
|
249
|
+
constructor(params: ObservationParams);
|
|
250
|
+
/** Gets the AG-Kit OpenTelemetry tracer instance */
|
|
251
|
+
protected get tracer(): _opentelemetry_api.Tracer;
|
|
252
|
+
/**
|
|
253
|
+
* Ends the observation, marking it as complete.
|
|
254
|
+
*
|
|
255
|
+
* @param endTime - Optional end time, defaults to current time
|
|
256
|
+
*/
|
|
257
|
+
end(endTime?: TimeInput): void;
|
|
258
|
+
/**
|
|
259
|
+
* Updates the OTEL span attributes.
|
|
260
|
+
*
|
|
261
|
+
* @param attributes - Attributes to update
|
|
262
|
+
* @internal
|
|
263
|
+
*/
|
|
264
|
+
updateOtelSpanAttributes(attributes: ObservationAttributes): void;
|
|
265
|
+
/**
|
|
266
|
+
* Updates the parent trace with new attributes.
|
|
267
|
+
*
|
|
268
|
+
* @param attributes - Trace attributes to set
|
|
269
|
+
* @returns This observation for method chaining
|
|
270
|
+
*/
|
|
271
|
+
updateTrace(attributes: TraceAttributes): this;
|
|
272
|
+
/**
|
|
273
|
+
* Creates a new child observation within this observation's context.
|
|
274
|
+
*
|
|
275
|
+
* @param name - Name for the child observation
|
|
276
|
+
* @param attributes - Type-specific attributes
|
|
277
|
+
* @param options - Configuration including observation type
|
|
278
|
+
* @returns Child observation instance
|
|
279
|
+
*/
|
|
280
|
+
startObservation(name: string, attributes: LLMAttributes, options: {
|
|
281
|
+
asType: "llm";
|
|
282
|
+
}): ObservationLLM;
|
|
283
|
+
startObservation(name: string, attributes: EmbeddingAttributes, options: {
|
|
284
|
+
asType: "embedding";
|
|
285
|
+
}): ObservationEmbedding;
|
|
286
|
+
startObservation(name: string, attributes: AgentAttributes, options: {
|
|
287
|
+
asType: "agent";
|
|
288
|
+
}): ObservationAgent;
|
|
289
|
+
startObservation(name: string, attributes: ToolAttributes, options: {
|
|
290
|
+
asType: "tool";
|
|
291
|
+
}): ObservationTool;
|
|
292
|
+
startObservation(name: string, attributes: ChainAttributes, options: {
|
|
293
|
+
asType: "chain";
|
|
294
|
+
}): ObservationChain;
|
|
295
|
+
startObservation(name: string, attributes: RetrieverAttributes, options: {
|
|
296
|
+
asType: "retriever";
|
|
297
|
+
}): ObservationRetriever;
|
|
298
|
+
startObservation(name: string, attributes: RerankerAttributes, options: {
|
|
299
|
+
asType: "reranker";
|
|
300
|
+
}): ObservationReranker;
|
|
301
|
+
startObservation(name: string, attributes: EvaluatorAttributes, options: {
|
|
302
|
+
asType: "evaluator";
|
|
303
|
+
}): ObservationEvaluator;
|
|
304
|
+
startObservation(name: string, attributes: GuardrailAttributes, options: {
|
|
305
|
+
asType: "guardrail";
|
|
306
|
+
}): ObservationGuardrail;
|
|
307
|
+
startObservation(name: string, attributes?: BaseSpanAttributes, options?: {
|
|
308
|
+
asType?: "span";
|
|
309
|
+
}): ObservationSpan;
|
|
310
|
+
}
|
|
311
|
+
type ObservationSpanParams = {
|
|
312
|
+
otelSpan: Span;
|
|
313
|
+
attributes?: BaseSpanAttributes;
|
|
314
|
+
};
|
|
315
|
+
/**
|
|
316
|
+
* General-purpose observation for tracking operations.
|
|
317
|
+
*
|
|
318
|
+
* @public
|
|
319
|
+
*/
|
|
320
|
+
declare class ObservationSpan extends BaseObservation {
|
|
321
|
+
constructor(params: ObservationSpanParams);
|
|
322
|
+
update(attributes: BaseSpanAttributes): ObservationSpan;
|
|
323
|
+
}
|
|
324
|
+
type ObservationLLMParams = {
|
|
325
|
+
otelSpan: Span;
|
|
326
|
+
attributes?: LLMAttributes;
|
|
327
|
+
};
|
|
328
|
+
/**
|
|
329
|
+
* LLM observation for tracking language model calls.
|
|
330
|
+
*
|
|
331
|
+
* @public
|
|
332
|
+
*/
|
|
333
|
+
declare class ObservationLLM extends BaseObservation {
|
|
334
|
+
constructor(params: ObservationLLMParams);
|
|
335
|
+
update(attributes: LLMAttributes): ObservationLLM;
|
|
336
|
+
}
|
|
337
|
+
type ObservationEmbeddingParams = {
|
|
338
|
+
otelSpan: Span;
|
|
339
|
+
attributes?: EmbeddingAttributes;
|
|
340
|
+
};
|
|
341
|
+
/**
|
|
342
|
+
* Embedding observation for tracking embedding operations.
|
|
343
|
+
*
|
|
344
|
+
* @public
|
|
345
|
+
*/
|
|
346
|
+
declare class ObservationEmbedding extends BaseObservation {
|
|
347
|
+
constructor(params: ObservationEmbeddingParams);
|
|
348
|
+
update(attributes: EmbeddingAttributes): ObservationEmbedding;
|
|
349
|
+
}
|
|
350
|
+
type ObservationAgentParams = {
|
|
351
|
+
otelSpan: Span;
|
|
352
|
+
attributes?: AgentAttributes;
|
|
353
|
+
};
|
|
354
|
+
/**
|
|
355
|
+
* Agent observation for tracking AI agent workflows.
|
|
356
|
+
*
|
|
357
|
+
* @public
|
|
358
|
+
*/
|
|
359
|
+
declare class ObservationAgent extends BaseObservation {
|
|
360
|
+
constructor(params: ObservationAgentParams);
|
|
361
|
+
update(attributes: AgentAttributes): ObservationAgent;
|
|
362
|
+
}
|
|
363
|
+
type ObservationToolParams = {
|
|
364
|
+
otelSpan: Span;
|
|
365
|
+
attributes?: ToolAttributes;
|
|
366
|
+
};
|
|
367
|
+
/**
|
|
368
|
+
* Tool observation for tracking tool calls.
|
|
369
|
+
*
|
|
370
|
+
* @public
|
|
371
|
+
*/
|
|
372
|
+
declare class ObservationTool extends BaseObservation {
|
|
373
|
+
constructor(params: ObservationToolParams);
|
|
374
|
+
update(attributes: ToolAttributes): ObservationTool;
|
|
375
|
+
}
|
|
376
|
+
type ObservationChainParams = {
|
|
377
|
+
otelSpan: Span;
|
|
378
|
+
attributes?: ChainAttributes;
|
|
379
|
+
};
|
|
380
|
+
/**
|
|
381
|
+
* Chain observation for tracking multi-step workflows.
|
|
382
|
+
*
|
|
383
|
+
* @public
|
|
384
|
+
*/
|
|
385
|
+
declare class ObservationChain extends BaseObservation {
|
|
386
|
+
constructor(params: ObservationChainParams);
|
|
387
|
+
update(attributes: ChainAttributes): ObservationChain;
|
|
388
|
+
}
|
|
389
|
+
type ObservationRetrieverParams = {
|
|
390
|
+
otelSpan: Span;
|
|
391
|
+
attributes?: RetrieverAttributes;
|
|
392
|
+
};
|
|
393
|
+
/**
|
|
394
|
+
* Retriever observation for tracking document retrieval.
|
|
395
|
+
*
|
|
396
|
+
* @public
|
|
397
|
+
*/
|
|
398
|
+
declare class ObservationRetriever extends BaseObservation {
|
|
399
|
+
constructor(params: ObservationRetrieverParams);
|
|
400
|
+
update(attributes: RetrieverAttributes): ObservationRetriever;
|
|
401
|
+
}
|
|
402
|
+
type ObservationRerankerParams = {
|
|
403
|
+
otelSpan: Span;
|
|
404
|
+
attributes?: RerankerAttributes;
|
|
405
|
+
};
|
|
406
|
+
/**
|
|
407
|
+
* Reranker observation for tracking reranking operations.
|
|
408
|
+
*
|
|
409
|
+
* @public
|
|
410
|
+
*/
|
|
411
|
+
declare class ObservationReranker extends BaseObservation {
|
|
412
|
+
constructor(params: ObservationRerankerParams);
|
|
413
|
+
update(attributes: RerankerAttributes): ObservationReranker;
|
|
414
|
+
}
|
|
415
|
+
type ObservationEvaluatorParams = {
|
|
416
|
+
otelSpan: Span;
|
|
417
|
+
attributes?: EvaluatorAttributes;
|
|
418
|
+
};
|
|
419
|
+
/**
|
|
420
|
+
* Evaluator observation for tracking evaluation operations.
|
|
421
|
+
*
|
|
422
|
+
* @public
|
|
423
|
+
*/
|
|
424
|
+
declare class ObservationEvaluator extends BaseObservation {
|
|
425
|
+
constructor(params: ObservationEvaluatorParams);
|
|
426
|
+
update(attributes: EvaluatorAttributes): ObservationEvaluator;
|
|
427
|
+
}
|
|
428
|
+
type ObservationGuardrailParams = {
|
|
429
|
+
otelSpan: Span;
|
|
430
|
+
attributes?: GuardrailAttributes;
|
|
431
|
+
};
|
|
432
|
+
/**
|
|
433
|
+
* Guardrail observation for tracking safety checks.
|
|
434
|
+
*
|
|
435
|
+
* @public
|
|
436
|
+
*/
|
|
437
|
+
declare class ObservationGuardrail extends BaseObservation {
|
|
438
|
+
constructor(params: ObservationGuardrailParams);
|
|
439
|
+
update(attributes: GuardrailAttributes): ObservationGuardrail;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Creates OpenTelemetry attributes from trace attributes.
|
|
444
|
+
*
|
|
445
|
+
* Converts user-friendly trace attributes into OpenTelemetry attribute format
|
|
446
|
+
* using OpenInference semantic conventions where applicable.
|
|
447
|
+
*
|
|
448
|
+
* @param attributes - Trace attributes to convert
|
|
449
|
+
* @returns OpenTelemetry attributes object
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
* ```typescript
|
|
453
|
+
* const otelAttributes = createTraceAttributes({
|
|
454
|
+
* name: 'user-workflow',
|
|
455
|
+
* userId: 'user-123',
|
|
456
|
+
* sessionId: 'session-456',
|
|
457
|
+
* tags: ['checkout', 'payment']
|
|
458
|
+
* });
|
|
459
|
+
* ```
|
|
460
|
+
*
|
|
461
|
+
* @public
|
|
462
|
+
*/
|
|
463
|
+
declare function createTraceAttributes({ name, userId, sessionId, version, release, input, output, metadata, tags, environment, public: isPublic, }?: TraceAttributes): Attributes;
|
|
464
|
+
/**
|
|
465
|
+
* Creates OpenTelemetry attributes from observation attributes.
|
|
466
|
+
*
|
|
467
|
+
* Maps observation attributes to OpenInference semantic conventions:
|
|
468
|
+
* - Uses `openinference.span.kind` for span type
|
|
469
|
+
* - Uses `llm.*` for LLM-specific attributes
|
|
470
|
+
* - Uses `tool.*` for tool-specific attributes
|
|
471
|
+
* - Falls back to `agkit.observation.*` for non-standard attributes
|
|
472
|
+
*
|
|
473
|
+
* @param type - Observation type (llm, tool, chain, etc.)
|
|
474
|
+
* @param attributes - Observation attributes to convert
|
|
475
|
+
* @returns OpenTelemetry attributes object
|
|
476
|
+
*
|
|
477
|
+
* @public
|
|
478
|
+
*/
|
|
479
|
+
declare function createObservationAttributes(type: ObservationType, attributes: ObservationAttributes): Attributes;
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Sets an isolated TracerProvider for tracing tracing operations.
|
|
483
|
+
*
|
|
484
|
+
* This allows tracing to use its own TracerProvider instance, separate from
|
|
485
|
+
* the global OpenTelemetry TracerProvider.
|
|
486
|
+
*
|
|
487
|
+
* Note: While this isolates span processing and export, it does NOT provide
|
|
488
|
+
* complete trace isolation. OpenTelemetry context (trace IDs, parent spans)
|
|
489
|
+
* is still shared between the global and isolated providers.
|
|
490
|
+
*
|
|
491
|
+
* @param provider - The TracerProvider instance to use, or null to clear
|
|
492
|
+
*
|
|
493
|
+
* @example
|
|
494
|
+
* ```typescript
|
|
495
|
+
* import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
|
|
496
|
+
* import { setTracerProvider } from './observability';
|
|
497
|
+
*
|
|
498
|
+
* const provider = new NodeTracerProvider();
|
|
499
|
+
* setTracerProvider(provider);
|
|
500
|
+
* ```
|
|
501
|
+
*
|
|
502
|
+
* @public
|
|
503
|
+
*/
|
|
504
|
+
declare function setTracerProvider(provider: TracerProvider | null): void;
|
|
505
|
+
/**
|
|
506
|
+
* Gets the TracerProvider for tracing tracing operations.
|
|
507
|
+
*
|
|
508
|
+
* Returns the isolated TracerProvider if one has been set via setTracerProvider(),
|
|
509
|
+
* otherwise falls back to the global OpenTelemetry TracerProvider.
|
|
510
|
+
*
|
|
511
|
+
* @returns The TracerProvider instance to use for tracing tracing
|
|
512
|
+
*
|
|
513
|
+
* @example
|
|
514
|
+
* ```typescript
|
|
515
|
+
* import { getTracerProvider } from './observability';
|
|
516
|
+
*
|
|
517
|
+
* const provider = getTracerProvider();
|
|
518
|
+
* const tracer = provider.getTracer('my-tracer', '1.0.0');
|
|
519
|
+
* ```
|
|
520
|
+
*
|
|
521
|
+
* @public
|
|
522
|
+
*/
|
|
523
|
+
declare function getTracerProvider(): TracerProvider;
|
|
524
|
+
/**
|
|
525
|
+
* Gets the OpenTelemetry tracer instance for tracing.
|
|
526
|
+
*
|
|
527
|
+
* Returns a tracer specifically configured for tracing with the correct
|
|
528
|
+
* tracer name and version.
|
|
529
|
+
*
|
|
530
|
+
* @returns The tracing OpenTelemetry tracer instance
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* ```typescript
|
|
534
|
+
* import { getTracer } from './observability';
|
|
535
|
+
*
|
|
536
|
+
* const tracer = getTracer();
|
|
537
|
+
* const span = tracer.startSpan('my-operation');
|
|
538
|
+
* ```
|
|
539
|
+
*
|
|
540
|
+
* @public
|
|
541
|
+
*/
|
|
542
|
+
declare function getTracer(): _opentelemetry_api.Tracer;
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Observability - OpenTelemetry-based tracing with OpenInference semantic conventions
|
|
546
|
+
*
|
|
547
|
+
* @packageDocumentation
|
|
548
|
+
*/
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Options for starting observations (spans).
|
|
552
|
+
*
|
|
553
|
+
* @public
|
|
554
|
+
*/
|
|
555
|
+
type StartObservationOptions = {
|
|
556
|
+
/** Custom start time for the observation */
|
|
557
|
+
startTime?: Date;
|
|
558
|
+
/** Parent span context to attach this observation to */
|
|
559
|
+
parentSpanContext?: SpanContext;
|
|
560
|
+
};
|
|
561
|
+
/**
|
|
562
|
+
* Options for startObservation function.
|
|
563
|
+
*
|
|
564
|
+
* @public
|
|
565
|
+
*/
|
|
566
|
+
type StartObservationOpts = StartObservationOptions & {
|
|
567
|
+
/** Type of observation to create. Defaults to 'span' */
|
|
568
|
+
asType?: ObservationType;
|
|
569
|
+
};
|
|
570
|
+
declare function startObservation(name: string, attributes?: BaseSpanAttributes, options?: StartObservationOpts & {
|
|
571
|
+
asType?: ObservationType;
|
|
572
|
+
}): Observation;
|
|
573
|
+
declare function startObservation(name: string, attributes: LLMAttributes, options: StartObservationOpts & {
|
|
574
|
+
asType: "llm";
|
|
575
|
+
}): ObservationLLM;
|
|
576
|
+
declare function startObservation(name: string, attributes: EmbeddingAttributes, options: StartObservationOpts & {
|
|
577
|
+
asType: "embedding";
|
|
578
|
+
}): ObservationEmbedding;
|
|
579
|
+
declare function startObservation(name: string, attributes: AgentAttributes, options: StartObservationOpts & {
|
|
580
|
+
asType: "agent";
|
|
581
|
+
}): ObservationAgent;
|
|
582
|
+
declare function startObservation(name: string, attributes: ToolAttributes, options: StartObservationOpts & {
|
|
583
|
+
asType: "tool";
|
|
584
|
+
}): ObservationTool;
|
|
585
|
+
declare function startObservation(name: string, attributes: ChainAttributes, options: StartObservationOpts & {
|
|
586
|
+
asType: "chain";
|
|
587
|
+
}): ObservationChain;
|
|
588
|
+
declare function startObservation(name: string, attributes: RetrieverAttributes, options: StartObservationOpts & {
|
|
589
|
+
asType: "retriever";
|
|
590
|
+
}): ObservationRetriever;
|
|
591
|
+
declare function startObservation(name: string, attributes: RerankerAttributes, options: StartObservationOpts & {
|
|
592
|
+
asType: "reranker";
|
|
593
|
+
}): ObservationReranker;
|
|
594
|
+
declare function startObservation(name: string, attributes: EvaluatorAttributes, options: StartObservationOpts & {
|
|
595
|
+
asType: "evaluator";
|
|
596
|
+
}): ObservationEvaluator;
|
|
597
|
+
declare function startObservation(name: string, attributes: GuardrailAttributes, options: StartObservationOpts & {
|
|
598
|
+
asType: "guardrail";
|
|
599
|
+
}): ObservationGuardrail;
|
|
600
|
+
declare function startObservation(name: string, attributes?: BaseSpanAttributes, options?: StartObservationOpts & {
|
|
601
|
+
asType?: "span";
|
|
602
|
+
}): ObservationSpan;
|
|
603
|
+
/**
|
|
604
|
+
* Updates the currently active trace with new attributes.
|
|
605
|
+
*
|
|
606
|
+
* @param attributes - Trace attributes to set
|
|
607
|
+
*
|
|
608
|
+
* @example
|
|
609
|
+
* ```typescript
|
|
610
|
+
* import { updateActiveTrace } from './observability';
|
|
611
|
+
*
|
|
612
|
+
* updateActiveTrace({
|
|
613
|
+
* name: 'user-workflow',
|
|
614
|
+
* userId: 'user-123',
|
|
615
|
+
* tags: ['production']
|
|
616
|
+
* });
|
|
617
|
+
* ```
|
|
618
|
+
*
|
|
619
|
+
* @public
|
|
620
|
+
*/
|
|
621
|
+
declare function updateActiveTrace(attributes: TraceAttributes): void;
|
|
622
|
+
/**
|
|
623
|
+
* Gets the current active trace ID.
|
|
624
|
+
*
|
|
625
|
+
* @returns The trace ID of the currently active span, or undefined
|
|
626
|
+
*
|
|
627
|
+
* @public
|
|
628
|
+
*/
|
|
629
|
+
declare function getActiveTraceId(): string | undefined;
|
|
630
|
+
/**
|
|
631
|
+
* Gets the current active observation ID.
|
|
632
|
+
*
|
|
633
|
+
* @returns The span ID of the currently active span, or undefined
|
|
634
|
+
*
|
|
635
|
+
* @public
|
|
636
|
+
*/
|
|
637
|
+
declare function getActiveSpanId(): string | undefined;
|
|
638
|
+
/**
|
|
639
|
+
* Options for startActiveObservation.
|
|
640
|
+
*
|
|
641
|
+
* @public
|
|
642
|
+
*/
|
|
643
|
+
type StartActiveObservationOpts = StartObservationOpts & {
|
|
644
|
+
/** Whether to automatically end the observation when the function exits. Default: true */
|
|
645
|
+
endOnExit?: boolean;
|
|
646
|
+
};
|
|
647
|
+
declare function startActiveObservation<F extends (observation: ObservationSpan) => unknown>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;
|
|
648
|
+
declare function startActiveObservation<F extends (observation: ObservationLLM) => unknown>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;
|
|
649
|
+
declare function startActiveObservation<F extends (observation: ObservationEmbedding) => unknown>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;
|
|
650
|
+
declare function startActiveObservation<F extends (observation: ObservationAgent) => unknown>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;
|
|
651
|
+
declare function startActiveObservation<F extends (observation: ObservationTool) => unknown>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;
|
|
652
|
+
declare function startActiveObservation<F extends (observation: ObservationChain) => unknown>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;
|
|
653
|
+
declare function startActiveObservation<F extends (observation: ObservationRetriever) => unknown>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;
|
|
654
|
+
declare function startActiveObservation<F extends (observation: ObservationReranker) => unknown>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;
|
|
655
|
+
declare function startActiveObservation<F extends (observation: ObservationEvaluator) => unknown>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;
|
|
656
|
+
declare function startActiveObservation<F extends (observation: ObservationGuardrail) => unknown>(name: string, fn: F, options?: StartActiveObservationOpts): ReturnType<F>;
|
|
657
|
+
/**
|
|
658
|
+
* Updates the currently active observation with new attributes.
|
|
659
|
+
*
|
|
660
|
+
* @param attributes - Observation attributes to set
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* ```typescript
|
|
664
|
+
* import { updateActiveObservation } from './observability';
|
|
665
|
+
*
|
|
666
|
+
* // Within an active observation context
|
|
667
|
+
* updateActiveObservation({
|
|
668
|
+
* metadata: { stage: 'processing' }
|
|
669
|
+
* });
|
|
670
|
+
* ```
|
|
671
|
+
*
|
|
672
|
+
* @public
|
|
673
|
+
*/
|
|
674
|
+
declare function updateActiveObservation(attributes: BaseSpanAttributes): void;
|
|
675
|
+
/**
|
|
676
|
+
* Options for the observe decorator.
|
|
677
|
+
*
|
|
678
|
+
* @public
|
|
679
|
+
*/
|
|
680
|
+
type ObserveOptions = Omit<StartObservationOpts, "name"> & {
|
|
681
|
+
/** Whether to capture function arguments as input. Default: true */
|
|
682
|
+
captureInput?: boolean;
|
|
683
|
+
/** Whether to capture return value as output. Default: true */
|
|
684
|
+
captureOutput?: boolean;
|
|
685
|
+
};
|
|
686
|
+
/**
|
|
687
|
+
* Decorator function to add observability to any function.
|
|
688
|
+
*
|
|
689
|
+
* Wraps a function with automatic observation creation, input/output capture,
|
|
690
|
+
* and lifecycle management. The observation is automatically ended when the
|
|
691
|
+
* function completes.
|
|
692
|
+
*
|
|
693
|
+
* @param fn - Function to wrap
|
|
694
|
+
* @param options - Configuration options
|
|
695
|
+
* @returns Wrapped function with observability
|
|
696
|
+
*
|
|
697
|
+
* @example
|
|
698
|
+
* ```typescript
|
|
699
|
+
* import { observe } from './observability';
|
|
700
|
+
*
|
|
701
|
+
* // Wrap an existing function
|
|
702
|
+
* const fetchData = observe(async (url: string) => {
|
|
703
|
+
* const response = await fetch(url);
|
|
704
|
+
* return response.json();
|
|
705
|
+
* }, { asType: 'tool' });
|
|
706
|
+
*
|
|
707
|
+
* // Wrap with custom name
|
|
708
|
+
* const processPayment = observe(
|
|
709
|
+
* async (amount: number, currency: string) => {
|
|
710
|
+
* return await paymentGateway.charge(amount, currency);
|
|
711
|
+
* },
|
|
712
|
+
* { name: 'payment-gateway-call', asType: 'tool' }
|
|
713
|
+
* );
|
|
714
|
+
*
|
|
715
|
+
* // Class method decoration
|
|
716
|
+
* class UserService {
|
|
717
|
+
* @observe({ asType: 'chain' })
|
|
718
|
+
* async getUser(id: string) {
|
|
719
|
+
* return await db.users.find(id);
|
|
720
|
+
* }
|
|
721
|
+
* }
|
|
722
|
+
* ```
|
|
723
|
+
*
|
|
724
|
+
* @public
|
|
725
|
+
*/
|
|
726
|
+
declare function observe<T extends (...args: any[]) => any>(fn: T, options?: ObserveOptions): T;
|
|
727
|
+
|
|
728
|
+
export { type AgentAttributes, type BaseSpanAttributes, type ChainAttributes, type EmbeddingAttributes, type EvaluatorAttributes, type GuardrailAttributes, type LLMAttributes, type Observation, ObservationAgent, type ObservationAttributes, ObservationChain, ObservationEmbedding, ObservationEvaluator, ObservationGuardrail, ObservationLLM, type ObservationLevel, ObservationReranker, ObservationRetriever, ObservationSpan, ObservationTool, type ObservationType, type ObserveOptions, type RerankerAttributes, type RetrieverAttributes, type StartActiveObservationOpts, type StartObservationOptions, type StartObservationOpts, type ToolAttributes, type TraceAttributes, createObservationAttributes, createTraceAttributes, getActiveSpanId, getActiveTraceId, getTracer, getTracerProvider, observe, setTracerProvider, startActiveObservation, startObservation, updateActiveObservation, updateActiveTrace };
|