@agentium/observability 1.0.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/README.md +42 -0
- package/dist/index.cjs +1370 -0
- package/dist/index.d.cts +279 -0
- package/dist/index.d.ts +279 -0
- package/dist/index.js +1333 -0
- package/package.json +48 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { EventBus, Agent } from '@agentium/core';
|
|
2
|
+
|
|
3
|
+
type SpanKind = "agent" | "llm" | "tool" | "guardrail" | "memory" | "cache" | "handoff" | "team" | "workflow" | "internal";
|
|
4
|
+
type SpanStatus = "ok" | "error" | "running";
|
|
5
|
+
interface SpanEvent {
|
|
6
|
+
name: string;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
attributes?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
interface Span {
|
|
11
|
+
traceId: string;
|
|
12
|
+
spanId: string;
|
|
13
|
+
parentSpanId?: string;
|
|
14
|
+
name: string;
|
|
15
|
+
kind: SpanKind;
|
|
16
|
+
startTime: number;
|
|
17
|
+
endTime?: number;
|
|
18
|
+
durationMs?: number;
|
|
19
|
+
status: SpanStatus;
|
|
20
|
+
attributes: Record<string, unknown>;
|
|
21
|
+
events: SpanEvent[];
|
|
22
|
+
}
|
|
23
|
+
interface Trace {
|
|
24
|
+
traceId: string;
|
|
25
|
+
spans: Span[];
|
|
26
|
+
rootSpanId: string;
|
|
27
|
+
startTime: number;
|
|
28
|
+
endTime?: number;
|
|
29
|
+
durationMs?: number;
|
|
30
|
+
metadata: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
interface TraceExporter {
|
|
33
|
+
name: string;
|
|
34
|
+
export(trace: Trace): Promise<void>;
|
|
35
|
+
flush?(): Promise<void>;
|
|
36
|
+
shutdown?(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
interface MetricsSnapshot {
|
|
39
|
+
counters: {
|
|
40
|
+
runs_total: number;
|
|
41
|
+
runs_success: number;
|
|
42
|
+
runs_error: number;
|
|
43
|
+
tool_calls_total: number;
|
|
44
|
+
handoffs_total: number;
|
|
45
|
+
cache_hits: number;
|
|
46
|
+
cache_misses: number;
|
|
47
|
+
};
|
|
48
|
+
histograms: {
|
|
49
|
+
run_duration_ms: number[];
|
|
50
|
+
tool_latency_ms: number[];
|
|
51
|
+
};
|
|
52
|
+
gauges: {
|
|
53
|
+
total_cost_usd: number;
|
|
54
|
+
total_tokens: number;
|
|
55
|
+
prompt_tokens: number;
|
|
56
|
+
completion_tokens: number;
|
|
57
|
+
reasoning_tokens: number;
|
|
58
|
+
cached_tokens: number;
|
|
59
|
+
audio_input_tokens: number;
|
|
60
|
+
audio_output_tokens: number;
|
|
61
|
+
};
|
|
62
|
+
rates: {
|
|
63
|
+
cache_hit_ratio: number;
|
|
64
|
+
error_rate: number;
|
|
65
|
+
};
|
|
66
|
+
timestamp: number;
|
|
67
|
+
}
|
|
68
|
+
type ExporterShorthand = "console" | "langfuse" | "json-file" | "otel";
|
|
69
|
+
interface ObservabilityConfig {
|
|
70
|
+
/** Exporter instances or shorthand strings like "console", "langfuse". */
|
|
71
|
+
exporters?: (TraceExporter | ExporterShorthand)[];
|
|
72
|
+
metrics?: boolean;
|
|
73
|
+
structuredLogs?: boolean | LogDrain;
|
|
74
|
+
}
|
|
75
|
+
type LogDrain = "console" | "json" | ((entry: LogEntry) => void);
|
|
76
|
+
interface LogEntry {
|
|
77
|
+
timestamp: string;
|
|
78
|
+
level: "debug" | "info" | "warn" | "error";
|
|
79
|
+
message: string;
|
|
80
|
+
traceId?: string;
|
|
81
|
+
spanId?: string;
|
|
82
|
+
agentName?: string;
|
|
83
|
+
attributes?: Record<string, unknown>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
declare class CallbackExporter implements TraceExporter {
|
|
87
|
+
name: string;
|
|
88
|
+
private callback;
|
|
89
|
+
constructor(callback: (trace: Trace) => void | Promise<void>);
|
|
90
|
+
export(trace: Trace): Promise<void>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
declare class ConsoleExporter implements TraceExporter {
|
|
94
|
+
name: string;
|
|
95
|
+
export(trace: Trace): Promise<void>;
|
|
96
|
+
private printSpan;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
interface JsonFileExporterConfig {
|
|
100
|
+
path?: string;
|
|
101
|
+
mode?: "overwrite" | "append";
|
|
102
|
+
pretty?: boolean;
|
|
103
|
+
}
|
|
104
|
+
declare class JsonFileExporter implements TraceExporter {
|
|
105
|
+
name: string;
|
|
106
|
+
private path;
|
|
107
|
+
private mode;
|
|
108
|
+
private pretty;
|
|
109
|
+
constructor(config?: JsonFileExporterConfig);
|
|
110
|
+
export(trace: Trace): Promise<void>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface LangfuseExporterConfig {
|
|
114
|
+
/** Defaults to LANGFUSE_PUBLIC_KEY env var. */
|
|
115
|
+
publicKey?: string;
|
|
116
|
+
/** Defaults to LANGFUSE_SECRET_KEY env var. */
|
|
117
|
+
secretKey?: string;
|
|
118
|
+
/** Defaults to LANGFUSE_BASE_URL env var or https://cloud.langfuse.com. */
|
|
119
|
+
baseUrl?: string;
|
|
120
|
+
}
|
|
121
|
+
declare class LangfuseExporter implements TraceExporter {
|
|
122
|
+
name: string;
|
|
123
|
+
private publicKey;
|
|
124
|
+
private secretKey;
|
|
125
|
+
private baseUrl;
|
|
126
|
+
constructor(config?: LangfuseExporterConfig);
|
|
127
|
+
private fetchWithRetry;
|
|
128
|
+
export(trace: Trace): Promise<void>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
interface OTelExporterConfig {
|
|
132
|
+
/** Defaults to OTEL_EXPORTER_OTLP_ENDPOINT env var. */
|
|
133
|
+
endpoint?: string;
|
|
134
|
+
/** Defaults to OTEL_EXPORTER_OTLP_HEADERS env var (comma-separated key=value pairs). */
|
|
135
|
+
headers?: Record<string, string>;
|
|
136
|
+
protocol?: "http/json" | "http/protobuf";
|
|
137
|
+
/** Defaults to OTEL_SERVICE_NAME env var or "agentium". */
|
|
138
|
+
serviceName?: string;
|
|
139
|
+
}
|
|
140
|
+
declare class OTelExporter implements TraceExporter {
|
|
141
|
+
name: string;
|
|
142
|
+
private endpoint;
|
|
143
|
+
private headers;
|
|
144
|
+
private serviceName;
|
|
145
|
+
constructor(config?: OTelExporterConfig);
|
|
146
|
+
private fetchWithRetry;
|
|
147
|
+
export(trace: Trace): Promise<void>;
|
|
148
|
+
private padHex;
|
|
149
|
+
private mapKind;
|
|
150
|
+
private toOtlpValue;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
declare class MetricsCollector {
|
|
154
|
+
private counters;
|
|
155
|
+
private histograms;
|
|
156
|
+
private gauges;
|
|
157
|
+
private readonly MAX_HISTOGRAM_SIZE;
|
|
158
|
+
private toolStartTimes;
|
|
159
|
+
private runStartTimes;
|
|
160
|
+
private listeners;
|
|
161
|
+
attach(eventBus: EventBus): void;
|
|
162
|
+
detach(eventBus: EventBus): void;
|
|
163
|
+
getMetrics(): MetricsSnapshot;
|
|
164
|
+
reset(): void;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
declare class Tracer {
|
|
168
|
+
private traces;
|
|
169
|
+
private runToTrace;
|
|
170
|
+
private runToRootSpan;
|
|
171
|
+
private activeSpans;
|
|
172
|
+
private exporters;
|
|
173
|
+
private listeners;
|
|
174
|
+
private pendingExports;
|
|
175
|
+
private maxTraces;
|
|
176
|
+
constructor(exporters?: TraceExporter[]);
|
|
177
|
+
attach(eventBus: EventBus): void;
|
|
178
|
+
detach(eventBus: EventBus): void;
|
|
179
|
+
getTrace(traceId: string): Trace | undefined;
|
|
180
|
+
getTraceByRunId(runId: string): Trace | undefined;
|
|
181
|
+
getAllTraces(): Trace[];
|
|
182
|
+
clear(): void;
|
|
183
|
+
flush(): Promise<void>;
|
|
184
|
+
shutdown(): Promise<void>;
|
|
185
|
+
private startSpan;
|
|
186
|
+
private endSpan;
|
|
187
|
+
private finalizeTrace;
|
|
188
|
+
private runExporters;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
declare class StructuredLogger {
|
|
192
|
+
private drain;
|
|
193
|
+
private tracer;
|
|
194
|
+
private listeners;
|
|
195
|
+
constructor(drain?: LogDrain, tracer?: Tracer);
|
|
196
|
+
attach(eventBus: EventBus): void;
|
|
197
|
+
detach(eventBus: EventBus): void;
|
|
198
|
+
private log;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
interface InstrumentResult {
|
|
202
|
+
tracer: Tracer;
|
|
203
|
+
metrics: MetricsCollector | null;
|
|
204
|
+
logger: StructuredLogger | null;
|
|
205
|
+
detach: () => void;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Attach observability to an agent in one call.
|
|
209
|
+
*
|
|
210
|
+
* ```ts
|
|
211
|
+
* import { instrument } from "@agentium/observability";
|
|
212
|
+
*
|
|
213
|
+
* // Minimal — just pass string shorthands:
|
|
214
|
+
* const obs = instrument(agent, { exporters: ["langfuse", "console"] });
|
|
215
|
+
*
|
|
216
|
+
* // Or bring your own exporter instances for custom config:
|
|
217
|
+
* const obs = instrument(agent, {
|
|
218
|
+
* exporters: [new LangfuseExporter({ baseUrl: "..." }), "console"],
|
|
219
|
+
* });
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
declare function instrument(agent: Agent, config?: ObservabilityConfig): InstrumentResult;
|
|
223
|
+
/**
|
|
224
|
+
* Attach observability to a raw EventBus (for teams, workflows, or custom setups).
|
|
225
|
+
*/
|
|
226
|
+
declare function instrumentBus(eventBus: EventBus, config?: ObservabilityConfig): InstrumentResult;
|
|
227
|
+
|
|
228
|
+
interface AgentMetrics {
|
|
229
|
+
runs: number;
|
|
230
|
+
errors: number;
|
|
231
|
+
avgDurationMs: number;
|
|
232
|
+
p95DurationMs: number;
|
|
233
|
+
totalCost: number;
|
|
234
|
+
totalTokens: number;
|
|
235
|
+
promptTokens: number;
|
|
236
|
+
completionTokens: number;
|
|
237
|
+
reasoningTokens: number;
|
|
238
|
+
cachedTokens: number;
|
|
239
|
+
audioInputTokens: number;
|
|
240
|
+
audioOutputTokens: number;
|
|
241
|
+
toolCallCount: number;
|
|
242
|
+
toolUsageFrequency: Record<string, number>;
|
|
243
|
+
errorRate: number;
|
|
244
|
+
tokensPerRun: number;
|
|
245
|
+
/** Estimated total KV cache memory (GB) across all sessions. Requires capacity module. */
|
|
246
|
+
estimatedKvCacheGb?: number;
|
|
247
|
+
/** Average context length (tokens) per run. */
|
|
248
|
+
avgContextLength?: number;
|
|
249
|
+
/** Session count by category (light/medium/heavy/extreme). */
|
|
250
|
+
sessionCategories?: Record<string, number>;
|
|
251
|
+
}
|
|
252
|
+
interface MetricEvent {
|
|
253
|
+
type: string;
|
|
254
|
+
agentName?: string;
|
|
255
|
+
timestamp: number;
|
|
256
|
+
data: Record<string, unknown>;
|
|
257
|
+
}
|
|
258
|
+
declare class MetricsExporter {
|
|
259
|
+
private runs;
|
|
260
|
+
private toolUsage;
|
|
261
|
+
private runStartTimes;
|
|
262
|
+
private runToolCounts;
|
|
263
|
+
private listeners;
|
|
264
|
+
private subscribers;
|
|
265
|
+
private maxRecords;
|
|
266
|
+
private sessionCategories;
|
|
267
|
+
private estimatedKvCacheGb?;
|
|
268
|
+
attach(eventBus: EventBus): void;
|
|
269
|
+
detach(eventBus: EventBus): void;
|
|
270
|
+
private addRecord;
|
|
271
|
+
private emit;
|
|
272
|
+
getMetrics(agentName?: string): AgentMetrics;
|
|
273
|
+
toPrometheus(): string;
|
|
274
|
+
toJSON(): object;
|
|
275
|
+
stream(): AsyncIterable<MetricEvent>;
|
|
276
|
+
reset(): void;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export { type AgentMetrics, CallbackExporter, ConsoleExporter, type ExporterShorthand, type InstrumentResult, JsonFileExporter, type JsonFileExporterConfig, LangfuseExporter, type LangfuseExporterConfig, type LogDrain, type LogEntry, type MetricEvent, MetricsCollector, MetricsExporter, type MetricsSnapshot, OTelExporter, type OTelExporterConfig, type ObservabilityConfig, type Span, type SpanEvent, type SpanKind, type SpanStatus, StructuredLogger, type Trace, type TraceExporter, Tracer, instrument, instrumentBus };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { EventBus, Agent } from '@agentium/core';
|
|
2
|
+
|
|
3
|
+
type SpanKind = "agent" | "llm" | "tool" | "guardrail" | "memory" | "cache" | "handoff" | "team" | "workflow" | "internal";
|
|
4
|
+
type SpanStatus = "ok" | "error" | "running";
|
|
5
|
+
interface SpanEvent {
|
|
6
|
+
name: string;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
attributes?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
interface Span {
|
|
11
|
+
traceId: string;
|
|
12
|
+
spanId: string;
|
|
13
|
+
parentSpanId?: string;
|
|
14
|
+
name: string;
|
|
15
|
+
kind: SpanKind;
|
|
16
|
+
startTime: number;
|
|
17
|
+
endTime?: number;
|
|
18
|
+
durationMs?: number;
|
|
19
|
+
status: SpanStatus;
|
|
20
|
+
attributes: Record<string, unknown>;
|
|
21
|
+
events: SpanEvent[];
|
|
22
|
+
}
|
|
23
|
+
interface Trace {
|
|
24
|
+
traceId: string;
|
|
25
|
+
spans: Span[];
|
|
26
|
+
rootSpanId: string;
|
|
27
|
+
startTime: number;
|
|
28
|
+
endTime?: number;
|
|
29
|
+
durationMs?: number;
|
|
30
|
+
metadata: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
interface TraceExporter {
|
|
33
|
+
name: string;
|
|
34
|
+
export(trace: Trace): Promise<void>;
|
|
35
|
+
flush?(): Promise<void>;
|
|
36
|
+
shutdown?(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
interface MetricsSnapshot {
|
|
39
|
+
counters: {
|
|
40
|
+
runs_total: number;
|
|
41
|
+
runs_success: number;
|
|
42
|
+
runs_error: number;
|
|
43
|
+
tool_calls_total: number;
|
|
44
|
+
handoffs_total: number;
|
|
45
|
+
cache_hits: number;
|
|
46
|
+
cache_misses: number;
|
|
47
|
+
};
|
|
48
|
+
histograms: {
|
|
49
|
+
run_duration_ms: number[];
|
|
50
|
+
tool_latency_ms: number[];
|
|
51
|
+
};
|
|
52
|
+
gauges: {
|
|
53
|
+
total_cost_usd: number;
|
|
54
|
+
total_tokens: number;
|
|
55
|
+
prompt_tokens: number;
|
|
56
|
+
completion_tokens: number;
|
|
57
|
+
reasoning_tokens: number;
|
|
58
|
+
cached_tokens: number;
|
|
59
|
+
audio_input_tokens: number;
|
|
60
|
+
audio_output_tokens: number;
|
|
61
|
+
};
|
|
62
|
+
rates: {
|
|
63
|
+
cache_hit_ratio: number;
|
|
64
|
+
error_rate: number;
|
|
65
|
+
};
|
|
66
|
+
timestamp: number;
|
|
67
|
+
}
|
|
68
|
+
type ExporterShorthand = "console" | "langfuse" | "json-file" | "otel";
|
|
69
|
+
interface ObservabilityConfig {
|
|
70
|
+
/** Exporter instances or shorthand strings like "console", "langfuse". */
|
|
71
|
+
exporters?: (TraceExporter | ExporterShorthand)[];
|
|
72
|
+
metrics?: boolean;
|
|
73
|
+
structuredLogs?: boolean | LogDrain;
|
|
74
|
+
}
|
|
75
|
+
type LogDrain = "console" | "json" | ((entry: LogEntry) => void);
|
|
76
|
+
interface LogEntry {
|
|
77
|
+
timestamp: string;
|
|
78
|
+
level: "debug" | "info" | "warn" | "error";
|
|
79
|
+
message: string;
|
|
80
|
+
traceId?: string;
|
|
81
|
+
spanId?: string;
|
|
82
|
+
agentName?: string;
|
|
83
|
+
attributes?: Record<string, unknown>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
declare class CallbackExporter implements TraceExporter {
|
|
87
|
+
name: string;
|
|
88
|
+
private callback;
|
|
89
|
+
constructor(callback: (trace: Trace) => void | Promise<void>);
|
|
90
|
+
export(trace: Trace): Promise<void>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
declare class ConsoleExporter implements TraceExporter {
|
|
94
|
+
name: string;
|
|
95
|
+
export(trace: Trace): Promise<void>;
|
|
96
|
+
private printSpan;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
interface JsonFileExporterConfig {
|
|
100
|
+
path?: string;
|
|
101
|
+
mode?: "overwrite" | "append";
|
|
102
|
+
pretty?: boolean;
|
|
103
|
+
}
|
|
104
|
+
declare class JsonFileExporter implements TraceExporter {
|
|
105
|
+
name: string;
|
|
106
|
+
private path;
|
|
107
|
+
private mode;
|
|
108
|
+
private pretty;
|
|
109
|
+
constructor(config?: JsonFileExporterConfig);
|
|
110
|
+
export(trace: Trace): Promise<void>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface LangfuseExporterConfig {
|
|
114
|
+
/** Defaults to LANGFUSE_PUBLIC_KEY env var. */
|
|
115
|
+
publicKey?: string;
|
|
116
|
+
/** Defaults to LANGFUSE_SECRET_KEY env var. */
|
|
117
|
+
secretKey?: string;
|
|
118
|
+
/** Defaults to LANGFUSE_BASE_URL env var or https://cloud.langfuse.com. */
|
|
119
|
+
baseUrl?: string;
|
|
120
|
+
}
|
|
121
|
+
declare class LangfuseExporter implements TraceExporter {
|
|
122
|
+
name: string;
|
|
123
|
+
private publicKey;
|
|
124
|
+
private secretKey;
|
|
125
|
+
private baseUrl;
|
|
126
|
+
constructor(config?: LangfuseExporterConfig);
|
|
127
|
+
private fetchWithRetry;
|
|
128
|
+
export(trace: Trace): Promise<void>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
interface OTelExporterConfig {
|
|
132
|
+
/** Defaults to OTEL_EXPORTER_OTLP_ENDPOINT env var. */
|
|
133
|
+
endpoint?: string;
|
|
134
|
+
/** Defaults to OTEL_EXPORTER_OTLP_HEADERS env var (comma-separated key=value pairs). */
|
|
135
|
+
headers?: Record<string, string>;
|
|
136
|
+
protocol?: "http/json" | "http/protobuf";
|
|
137
|
+
/** Defaults to OTEL_SERVICE_NAME env var or "agentium". */
|
|
138
|
+
serviceName?: string;
|
|
139
|
+
}
|
|
140
|
+
declare class OTelExporter implements TraceExporter {
|
|
141
|
+
name: string;
|
|
142
|
+
private endpoint;
|
|
143
|
+
private headers;
|
|
144
|
+
private serviceName;
|
|
145
|
+
constructor(config?: OTelExporterConfig);
|
|
146
|
+
private fetchWithRetry;
|
|
147
|
+
export(trace: Trace): Promise<void>;
|
|
148
|
+
private padHex;
|
|
149
|
+
private mapKind;
|
|
150
|
+
private toOtlpValue;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
declare class MetricsCollector {
|
|
154
|
+
private counters;
|
|
155
|
+
private histograms;
|
|
156
|
+
private gauges;
|
|
157
|
+
private readonly MAX_HISTOGRAM_SIZE;
|
|
158
|
+
private toolStartTimes;
|
|
159
|
+
private runStartTimes;
|
|
160
|
+
private listeners;
|
|
161
|
+
attach(eventBus: EventBus): void;
|
|
162
|
+
detach(eventBus: EventBus): void;
|
|
163
|
+
getMetrics(): MetricsSnapshot;
|
|
164
|
+
reset(): void;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
declare class Tracer {
|
|
168
|
+
private traces;
|
|
169
|
+
private runToTrace;
|
|
170
|
+
private runToRootSpan;
|
|
171
|
+
private activeSpans;
|
|
172
|
+
private exporters;
|
|
173
|
+
private listeners;
|
|
174
|
+
private pendingExports;
|
|
175
|
+
private maxTraces;
|
|
176
|
+
constructor(exporters?: TraceExporter[]);
|
|
177
|
+
attach(eventBus: EventBus): void;
|
|
178
|
+
detach(eventBus: EventBus): void;
|
|
179
|
+
getTrace(traceId: string): Trace | undefined;
|
|
180
|
+
getTraceByRunId(runId: string): Trace | undefined;
|
|
181
|
+
getAllTraces(): Trace[];
|
|
182
|
+
clear(): void;
|
|
183
|
+
flush(): Promise<void>;
|
|
184
|
+
shutdown(): Promise<void>;
|
|
185
|
+
private startSpan;
|
|
186
|
+
private endSpan;
|
|
187
|
+
private finalizeTrace;
|
|
188
|
+
private runExporters;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
declare class StructuredLogger {
|
|
192
|
+
private drain;
|
|
193
|
+
private tracer;
|
|
194
|
+
private listeners;
|
|
195
|
+
constructor(drain?: LogDrain, tracer?: Tracer);
|
|
196
|
+
attach(eventBus: EventBus): void;
|
|
197
|
+
detach(eventBus: EventBus): void;
|
|
198
|
+
private log;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
interface InstrumentResult {
|
|
202
|
+
tracer: Tracer;
|
|
203
|
+
metrics: MetricsCollector | null;
|
|
204
|
+
logger: StructuredLogger | null;
|
|
205
|
+
detach: () => void;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Attach observability to an agent in one call.
|
|
209
|
+
*
|
|
210
|
+
* ```ts
|
|
211
|
+
* import { instrument } from "@agentium/observability";
|
|
212
|
+
*
|
|
213
|
+
* // Minimal — just pass string shorthands:
|
|
214
|
+
* const obs = instrument(agent, { exporters: ["langfuse", "console"] });
|
|
215
|
+
*
|
|
216
|
+
* // Or bring your own exporter instances for custom config:
|
|
217
|
+
* const obs = instrument(agent, {
|
|
218
|
+
* exporters: [new LangfuseExporter({ baseUrl: "..." }), "console"],
|
|
219
|
+
* });
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
declare function instrument(agent: Agent, config?: ObservabilityConfig): InstrumentResult;
|
|
223
|
+
/**
|
|
224
|
+
* Attach observability to a raw EventBus (for teams, workflows, or custom setups).
|
|
225
|
+
*/
|
|
226
|
+
declare function instrumentBus(eventBus: EventBus, config?: ObservabilityConfig): InstrumentResult;
|
|
227
|
+
|
|
228
|
+
interface AgentMetrics {
|
|
229
|
+
runs: number;
|
|
230
|
+
errors: number;
|
|
231
|
+
avgDurationMs: number;
|
|
232
|
+
p95DurationMs: number;
|
|
233
|
+
totalCost: number;
|
|
234
|
+
totalTokens: number;
|
|
235
|
+
promptTokens: number;
|
|
236
|
+
completionTokens: number;
|
|
237
|
+
reasoningTokens: number;
|
|
238
|
+
cachedTokens: number;
|
|
239
|
+
audioInputTokens: number;
|
|
240
|
+
audioOutputTokens: number;
|
|
241
|
+
toolCallCount: number;
|
|
242
|
+
toolUsageFrequency: Record<string, number>;
|
|
243
|
+
errorRate: number;
|
|
244
|
+
tokensPerRun: number;
|
|
245
|
+
/** Estimated total KV cache memory (GB) across all sessions. Requires capacity module. */
|
|
246
|
+
estimatedKvCacheGb?: number;
|
|
247
|
+
/** Average context length (tokens) per run. */
|
|
248
|
+
avgContextLength?: number;
|
|
249
|
+
/** Session count by category (light/medium/heavy/extreme). */
|
|
250
|
+
sessionCategories?: Record<string, number>;
|
|
251
|
+
}
|
|
252
|
+
interface MetricEvent {
|
|
253
|
+
type: string;
|
|
254
|
+
agentName?: string;
|
|
255
|
+
timestamp: number;
|
|
256
|
+
data: Record<string, unknown>;
|
|
257
|
+
}
|
|
258
|
+
declare class MetricsExporter {
|
|
259
|
+
private runs;
|
|
260
|
+
private toolUsage;
|
|
261
|
+
private runStartTimes;
|
|
262
|
+
private runToolCounts;
|
|
263
|
+
private listeners;
|
|
264
|
+
private subscribers;
|
|
265
|
+
private maxRecords;
|
|
266
|
+
private sessionCategories;
|
|
267
|
+
private estimatedKvCacheGb?;
|
|
268
|
+
attach(eventBus: EventBus): void;
|
|
269
|
+
detach(eventBus: EventBus): void;
|
|
270
|
+
private addRecord;
|
|
271
|
+
private emit;
|
|
272
|
+
getMetrics(agentName?: string): AgentMetrics;
|
|
273
|
+
toPrometheus(): string;
|
|
274
|
+
toJSON(): object;
|
|
275
|
+
stream(): AsyncIterable<MetricEvent>;
|
|
276
|
+
reset(): void;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export { type AgentMetrics, CallbackExporter, ConsoleExporter, type ExporterShorthand, type InstrumentResult, JsonFileExporter, type JsonFileExporterConfig, LangfuseExporter, type LangfuseExporterConfig, type LogDrain, type LogEntry, type MetricEvent, MetricsCollector, MetricsExporter, type MetricsSnapshot, OTelExporter, type OTelExporterConfig, type ObservabilityConfig, type Span, type SpanEvent, type SpanKind, type SpanStatus, StructuredLogger, type Trace, type TraceExporter, Tracer, instrument, instrumentBus };
|