@juspay/neurolink 9.23.0 → 9.25.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/CHANGELOG.md +12 -0
- package/README.md +10 -13
- package/dist/adapters/tts/googleTTSHandler.js +26 -1
- package/dist/adapters/video/vertexVideoHandler.js +23 -17
- package/dist/cli/commands/config.d.ts +3 -3
- package/dist/cli/commands/observability.d.ts +53 -0
- package/dist/cli/commands/observability.js +453 -0
- package/dist/cli/commands/telemetry.d.ts +63 -0
- package/dist/cli/commands/telemetry.js +689 -0
- package/dist/cli/factories/commandFactory.d.ts +34 -0
- package/dist/cli/factories/commandFactory.js +321 -116
- package/dist/cli/parser.js +6 -9
- package/dist/cli/utils/formatters.d.ts +13 -0
- package/dist/cli/utils/formatters.js +23 -0
- package/dist/constants/contextWindows.js +6 -0
- package/dist/constants/enums.d.ts +6 -0
- package/dist/constants/enums.js +8 -2
- package/dist/context/budgetChecker.js +75 -48
- package/dist/context/contextCompactor.js +135 -127
- package/dist/core/baseProvider.d.ts +5 -0
- package/dist/core/baseProvider.js +158 -102
- package/dist/core/conversationMemoryInitializer.js +7 -4
- package/dist/core/conversationMemoryManager.d.ts +2 -0
- package/dist/core/conversationMemoryManager.js +6 -2
- package/dist/core/modules/GenerationHandler.d.ts +2 -2
- package/dist/core/modules/GenerationHandler.js +12 -12
- package/dist/evaluation/ragasEvaluator.js +39 -19
- package/dist/evaluation/scoring.js +46 -20
- package/dist/features/ppt/index.d.ts +1 -1
- package/dist/features/ppt/index.js +1 -1
- package/dist/features/ppt/presentationOrchestrator.js +23 -0
- package/dist/features/ppt/slideGenerator.js +13 -0
- package/dist/features/ppt/slideRenderers.d.ts +1 -1
- package/dist/features/ppt/slideRenderers.js +6 -4
- package/dist/features/ppt/slideTypeInference.d.ts +1 -1
- package/dist/features/ppt/slideTypeInference.js +75 -73
- package/dist/files/fileTools.d.ts +6 -6
- package/dist/index.d.ts +46 -12
- package/dist/index.js +79 -17
- package/dist/lib/adapters/tts/googleTTSHandler.js +26 -1
- package/dist/lib/adapters/video/vertexVideoHandler.js +23 -17
- package/dist/lib/constants/contextWindows.js +6 -0
- package/dist/lib/constants/enums.d.ts +6 -0
- package/dist/lib/constants/enums.js +8 -2
- package/dist/lib/context/budgetChecker.js +75 -48
- package/dist/lib/context/contextCompactor.js +135 -127
- package/dist/lib/core/baseProvider.d.ts +5 -0
- package/dist/lib/core/baseProvider.js +158 -102
- package/dist/lib/core/conversationMemoryInitializer.js +7 -4
- package/dist/lib/core/conversationMemoryManager.d.ts +2 -0
- package/dist/lib/core/conversationMemoryManager.js +6 -2
- package/dist/lib/core/modules/GenerationHandler.d.ts +2 -2
- package/dist/lib/core/modules/GenerationHandler.js +12 -12
- package/dist/lib/evaluation/ragasEvaluator.js +39 -19
- package/dist/lib/evaluation/scoring.js +46 -20
- package/dist/lib/features/ppt/index.d.ts +1 -1
- package/dist/lib/features/ppt/index.js +1 -1
- package/dist/lib/features/ppt/presentationOrchestrator.js +23 -0
- package/dist/lib/features/ppt/slideGenerator.js +13 -0
- package/dist/lib/features/ppt/slideRenderers.d.ts +1 -1
- package/dist/lib/features/ppt/slideRenderers.js +6 -4
- package/dist/lib/features/ppt/slideTypeInference.d.ts +1 -1
- package/dist/lib/features/ppt/slideTypeInference.js +75 -73
- package/dist/lib/files/fileTools.d.ts +6 -6
- package/dist/lib/index.d.ts +46 -12
- package/dist/lib/index.js +79 -17
- package/dist/lib/mcp/httpRateLimiter.js +39 -12
- package/dist/lib/mcp/httpRetryHandler.js +22 -1
- package/dist/lib/mcp/mcpClientFactory.js +13 -15
- package/dist/lib/memory/memoryRetrievalTools.js +22 -0
- package/dist/lib/neurolink.d.ts +64 -72
- package/dist/lib/neurolink.js +984 -566
- package/dist/lib/observability/exporterRegistry.d.ts +152 -0
- package/dist/lib/observability/exporterRegistry.js +414 -0
- package/dist/lib/observability/exporters/arizeExporter.d.ts +32 -0
- package/dist/lib/observability/exporters/arizeExporter.js +139 -0
- package/dist/lib/observability/exporters/baseExporter.d.ts +117 -0
- package/dist/lib/observability/exporters/baseExporter.js +191 -0
- package/dist/lib/observability/exporters/braintrustExporter.d.ts +30 -0
- package/dist/lib/observability/exporters/braintrustExporter.js +155 -0
- package/dist/lib/observability/exporters/datadogExporter.d.ts +37 -0
- package/dist/lib/observability/exporters/datadogExporter.js +197 -0
- package/dist/lib/observability/exporters/index.d.ts +13 -0
- package/dist/lib/observability/exporters/index.js +14 -0
- package/dist/lib/observability/exporters/laminarExporter.d.ts +48 -0
- package/dist/lib/observability/exporters/laminarExporter.js +303 -0
- package/dist/lib/observability/exporters/langfuseExporter.d.ts +47 -0
- package/dist/lib/observability/exporters/langfuseExporter.js +200 -0
- package/dist/lib/observability/exporters/langsmithExporter.d.ts +26 -0
- package/dist/lib/observability/exporters/langsmithExporter.js +124 -0
- package/dist/lib/observability/exporters/otelExporter.d.ts +39 -0
- package/dist/lib/observability/exporters/otelExporter.js +165 -0
- package/dist/lib/observability/exporters/posthogExporter.d.ts +48 -0
- package/dist/lib/observability/exporters/posthogExporter.js +288 -0
- package/dist/lib/observability/exporters/sentryExporter.d.ts +32 -0
- package/dist/lib/observability/exporters/sentryExporter.js +166 -0
- package/dist/lib/observability/index.d.ts +25 -0
- package/dist/lib/observability/index.js +32 -0
- package/dist/lib/observability/metricsAggregator.d.ts +260 -0
- package/dist/lib/observability/metricsAggregator.js +553 -0
- package/dist/lib/observability/otelBridge.d.ts +49 -0
- package/dist/lib/observability/otelBridge.js +132 -0
- package/dist/lib/observability/retryPolicy.d.ts +192 -0
- package/dist/lib/observability/retryPolicy.js +384 -0
- package/dist/lib/observability/sampling/index.d.ts +4 -0
- package/dist/lib/observability/sampling/index.js +5 -0
- package/dist/lib/observability/sampling/samplers.d.ts +116 -0
- package/dist/lib/observability/sampling/samplers.js +217 -0
- package/dist/lib/observability/spanProcessor.d.ts +129 -0
- package/dist/lib/observability/spanProcessor.js +288 -0
- package/dist/lib/observability/tokenTracker.d.ts +156 -0
- package/dist/lib/observability/tokenTracker.js +414 -0
- package/dist/lib/observability/types/exporterTypes.d.ts +250 -0
- package/dist/lib/observability/types/exporterTypes.js +6 -0
- package/dist/lib/observability/types/index.d.ts +6 -0
- package/dist/lib/observability/types/index.js +5 -0
- package/dist/lib/observability/types/spanTypes.d.ts +244 -0
- package/dist/lib/observability/types/spanTypes.js +93 -0
- package/dist/lib/observability/utils/index.d.ts +4 -0
- package/dist/lib/observability/utils/index.js +5 -0
- package/dist/lib/observability/utils/spanSerializer.d.ts +115 -0
- package/dist/lib/observability/utils/spanSerializer.js +287 -0
- package/dist/lib/providers/amazonSagemaker.d.ts +5 -4
- package/dist/lib/providers/amazonSagemaker.js +3 -4
- package/dist/lib/providers/googleVertex.d.ts +7 -0
- package/dist/lib/providers/googleVertex.js +80 -2
- package/dist/lib/rag/pipeline/RAGPipeline.d.ts +0 -5
- package/dist/lib/rag/pipeline/RAGPipeline.js +122 -87
- package/dist/lib/rag/ragIntegration.js +30 -0
- package/dist/lib/rag/retrieval/hybridSearch.js +22 -0
- package/dist/lib/server/abstract/baseServerAdapter.js +51 -19
- package/dist/lib/server/middleware/common.js +44 -12
- package/dist/lib/services/server/ai/observability/instrumentation.d.ts +2 -2
- package/dist/lib/services/server/ai/observability/instrumentation.js +10 -5
- package/dist/lib/types/cli.d.ts +18 -2
- package/dist/lib/types/conversationMemoryInterface.d.ts +2 -0
- package/dist/lib/types/generateTypes.d.ts +2 -2
- package/dist/lib/types/modelTypes.d.ts +18 -18
- package/dist/lib/types/providers.d.ts +5 -0
- package/dist/lib/utils/pricing.js +25 -1
- package/dist/lib/utils/ttsProcessor.js +74 -59
- package/dist/lib/workflow/config.d.ts +36 -36
- package/dist/lib/workflow/core/ensembleExecutor.js +10 -0
- package/dist/lib/workflow/core/judgeScorer.js +20 -2
- package/dist/lib/workflow/core/workflowRunner.js +34 -1
- package/dist/mcp/httpRateLimiter.js +39 -12
- package/dist/mcp/httpRetryHandler.js +22 -1
- package/dist/mcp/mcpClientFactory.js +13 -15
- package/dist/memory/memoryRetrievalTools.js +22 -0
- package/dist/neurolink.d.ts +64 -72
- package/dist/neurolink.js +984 -566
- package/dist/observability/FEATURE-STATUS.md +269 -0
- package/dist/observability/exporterRegistry.d.ts +152 -0
- package/dist/observability/exporterRegistry.js +413 -0
- package/dist/observability/exporters/arizeExporter.d.ts +32 -0
- package/dist/observability/exporters/arizeExporter.js +138 -0
- package/dist/observability/exporters/baseExporter.d.ts +117 -0
- package/dist/observability/exporters/baseExporter.js +190 -0
- package/dist/observability/exporters/braintrustExporter.d.ts +30 -0
- package/dist/observability/exporters/braintrustExporter.js +154 -0
- package/dist/observability/exporters/datadogExporter.d.ts +37 -0
- package/dist/observability/exporters/datadogExporter.js +196 -0
- package/dist/observability/exporters/index.d.ts +13 -0
- package/dist/observability/exporters/index.js +13 -0
- package/dist/observability/exporters/laminarExporter.d.ts +48 -0
- package/dist/observability/exporters/laminarExporter.js +302 -0
- package/dist/observability/exporters/langfuseExporter.d.ts +47 -0
- package/dist/observability/exporters/langfuseExporter.js +199 -0
- package/dist/observability/exporters/langsmithExporter.d.ts +26 -0
- package/dist/observability/exporters/langsmithExporter.js +123 -0
- package/dist/observability/exporters/otelExporter.d.ts +39 -0
- package/dist/observability/exporters/otelExporter.js +164 -0
- package/dist/observability/exporters/posthogExporter.d.ts +48 -0
- package/dist/observability/exporters/posthogExporter.js +287 -0
- package/dist/observability/exporters/sentryExporter.d.ts +32 -0
- package/dist/observability/exporters/sentryExporter.js +165 -0
- package/dist/observability/index.d.ts +25 -0
- package/dist/observability/index.js +31 -0
- package/dist/observability/metricsAggregator.d.ts +260 -0
- package/dist/observability/metricsAggregator.js +552 -0
- package/dist/observability/otelBridge.d.ts +49 -0
- package/dist/observability/otelBridge.js +131 -0
- package/dist/observability/retryPolicy.d.ts +192 -0
- package/dist/observability/retryPolicy.js +383 -0
- package/dist/observability/sampling/index.d.ts +4 -0
- package/dist/observability/sampling/index.js +4 -0
- package/dist/observability/sampling/samplers.d.ts +116 -0
- package/dist/observability/sampling/samplers.js +216 -0
- package/dist/observability/spanProcessor.d.ts +129 -0
- package/dist/observability/spanProcessor.js +287 -0
- package/dist/observability/tokenTracker.d.ts +156 -0
- package/dist/observability/tokenTracker.js +413 -0
- package/dist/observability/types/exporterTypes.d.ts +250 -0
- package/dist/observability/types/exporterTypes.js +5 -0
- package/dist/observability/types/index.d.ts +6 -0
- package/dist/observability/types/index.js +4 -0
- package/dist/observability/types/spanTypes.d.ts +244 -0
- package/dist/observability/types/spanTypes.js +92 -0
- package/dist/observability/utils/index.d.ts +4 -0
- package/dist/observability/utils/index.js +4 -0
- package/dist/observability/utils/spanSerializer.d.ts +115 -0
- package/dist/observability/utils/spanSerializer.js +286 -0
- package/dist/providers/amazonSagemaker.d.ts +5 -4
- package/dist/providers/amazonSagemaker.js +3 -4
- package/dist/providers/googleVertex.d.ts +7 -0
- package/dist/providers/googleVertex.js +80 -2
- package/dist/rag/pipeline/RAGPipeline.d.ts +0 -5
- package/dist/rag/pipeline/RAGPipeline.js +122 -87
- package/dist/rag/ragIntegration.js +30 -0
- package/dist/rag/retrieval/hybridSearch.js +22 -0
- package/dist/server/abstract/baseServerAdapter.js +51 -19
- package/dist/server/middleware/common.js +44 -12
- package/dist/services/server/ai/observability/instrumentation.d.ts +2 -2
- package/dist/services/server/ai/observability/instrumentation.js +10 -5
- package/dist/types/cli.d.ts +18 -2
- package/dist/types/conversationMemoryInterface.d.ts +2 -0
- package/dist/types/generateTypes.d.ts +2 -2
- package/dist/types/providers.d.ts +5 -0
- package/dist/utils/pricing.js +25 -1
- package/dist/utils/ttsProcessor.js +74 -59
- package/dist/workflow/config.d.ts +52 -52
- package/dist/workflow/core/ensembleExecutor.js +10 -0
- package/dist/workflow/core/judgeScorer.js +20 -2
- package/dist/workflow/core/workflowRunner.js +34 -1
- package/package.json +1 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentry Exporter
|
|
3
|
+
* Exports spans to Sentry error tracking and performance platform
|
|
4
|
+
*/
|
|
5
|
+
import { logger } from "../../utils/logger.js";
|
|
6
|
+
import { SpanStatus } from "../types/spanTypes.js";
|
|
7
|
+
import { BaseExporter } from "./baseExporter.js";
|
|
8
|
+
/**
|
|
9
|
+
* Sentry exporter for error tracking and performance monitoring
|
|
10
|
+
* Captures AI errors as exceptions and traces as transactions
|
|
11
|
+
*/
|
|
12
|
+
export class SentryExporter extends BaseExporter {
|
|
13
|
+
dsn;
|
|
14
|
+
tracesSampleRate;
|
|
15
|
+
release;
|
|
16
|
+
sentryHub = null;
|
|
17
|
+
constructor(config) {
|
|
18
|
+
super("sentry", config);
|
|
19
|
+
this.dsn = config.dsn;
|
|
20
|
+
this.tracesSampleRate = config.tracesSampleRate ?? 1.0;
|
|
21
|
+
this.release = config.release;
|
|
22
|
+
}
|
|
23
|
+
async initialize() {
|
|
24
|
+
if (this.initialized) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
// Dynamically import Sentry to avoid bundling issues
|
|
28
|
+
// @sentry/node is an optional peer dependency
|
|
29
|
+
const sentry = await this.loadSentry();
|
|
30
|
+
if (sentry) {
|
|
31
|
+
sentry.init({
|
|
32
|
+
dsn: this.dsn,
|
|
33
|
+
tracesSampleRate: this.tracesSampleRate,
|
|
34
|
+
release: this.release,
|
|
35
|
+
environment: this.config.environment ?? "production",
|
|
36
|
+
});
|
|
37
|
+
this.sentryHub = sentry;
|
|
38
|
+
}
|
|
39
|
+
this.initialized = true;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Load Sentry SDK dynamically as an optional dependency
|
|
43
|
+
* @returns Sentry module or null if not installed
|
|
44
|
+
*/
|
|
45
|
+
async loadSentry() {
|
|
46
|
+
try {
|
|
47
|
+
// Use standard dynamic import for optional peer dependency
|
|
48
|
+
// @ts-expect-error - @sentry/node is an optional peer dependency
|
|
49
|
+
const sentry = await import("@sentry/node");
|
|
50
|
+
return sentry;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
logger.warn("[Sentry] Sentry SDK not installed. Install @sentry/node to use SentryExporter.");
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async exportSpan(span) {
|
|
58
|
+
const startTime = Date.now();
|
|
59
|
+
if (!this.sentryHub) {
|
|
60
|
+
// Sentry not available, just succeed silently
|
|
61
|
+
return this.createSuccessResult(0, Date.now() - startTime);
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const Sentry = this.sentryHub;
|
|
65
|
+
// For errors, capture as Sentry exception
|
|
66
|
+
if (span.status === SpanStatus.ERROR) {
|
|
67
|
+
Sentry.withScope((scope) => {
|
|
68
|
+
scope.setTags({
|
|
69
|
+
"ai.provider": span.attributes["ai.provider"] ?? "",
|
|
70
|
+
"ai.model": span.attributes["ai.model"] ?? "",
|
|
71
|
+
"span.type": span.type,
|
|
72
|
+
});
|
|
73
|
+
scope.setContext("ai", {
|
|
74
|
+
tokens: {
|
|
75
|
+
input: span.attributes["ai.tokens.input"],
|
|
76
|
+
output: span.attributes["ai.tokens.output"],
|
|
77
|
+
total: span.attributes["ai.tokens.total"],
|
|
78
|
+
},
|
|
79
|
+
cost: span.attributes["ai.cost.total"],
|
|
80
|
+
duration_ms: span.durationMs,
|
|
81
|
+
});
|
|
82
|
+
if (span.attributes["user.id"]) {
|
|
83
|
+
scope.setUser({
|
|
84
|
+
id: span.attributes["user.id"],
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
Sentry.captureException(new Error(span.statusMessage ?? "AI operation failed"));
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// Create Sentry transaction for performance tracking
|
|
91
|
+
const transaction = Sentry.startInactiveSpan({
|
|
92
|
+
name: span.name,
|
|
93
|
+
op: span.type,
|
|
94
|
+
startTime: new Date(span.startTime).getTime() / 1000,
|
|
95
|
+
attributes: {
|
|
96
|
+
"ai.provider": span.attributes["ai.provider"],
|
|
97
|
+
"ai.model": span.attributes["ai.model"],
|
|
98
|
+
"ai.tokens.total": span.attributes["ai.tokens.total"],
|
|
99
|
+
"ai.cost.total": span.attributes["ai.cost.total"],
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
// End the transaction
|
|
103
|
+
if (span.endTime) {
|
|
104
|
+
transaction.end(new Date(span.endTime).getTime() / 1000);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
transaction.end();
|
|
108
|
+
}
|
|
109
|
+
return this.createSuccessResult(1, Date.now() - startTime);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
return this.createFailureResult([span.spanId], error instanceof Error ? error.message : String(error), Date.now() - startTime, false);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async exportBatch(spans) {
|
|
116
|
+
const results = await Promise.all(spans.map((s) => this.exportSpan(s)));
|
|
117
|
+
const successful = results.filter((r) => r.success).length;
|
|
118
|
+
const failed = spans.length - successful;
|
|
119
|
+
return {
|
|
120
|
+
success: failed === 0,
|
|
121
|
+
exportedCount: successful,
|
|
122
|
+
failedCount: failed,
|
|
123
|
+
errors: results.flatMap((r) => r.errors ?? []),
|
|
124
|
+
durationMs: results.reduce((sum, r) => sum + r.durationMs, 0),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
async flush() {
|
|
128
|
+
if (this.buffer.length > 0) {
|
|
129
|
+
const spans = [...this.buffer];
|
|
130
|
+
this.buffer = [];
|
|
131
|
+
await this.exportBatch(spans);
|
|
132
|
+
}
|
|
133
|
+
// Flush Sentry's internal buffer
|
|
134
|
+
if (this.sentryHub) {
|
|
135
|
+
await this.sentryHub.flush(2000);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async shutdown() {
|
|
139
|
+
await this.flush();
|
|
140
|
+
// Close Sentry SDK
|
|
141
|
+
if (this.sentryHub) {
|
|
142
|
+
await this.sentryHub.close(2000);
|
|
143
|
+
}
|
|
144
|
+
this.initialized = false;
|
|
145
|
+
}
|
|
146
|
+
async healthCheck() {
|
|
147
|
+
try {
|
|
148
|
+
await this.withRetry(() => this.ping(), "health check");
|
|
149
|
+
return this.createHealthStatus(true);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return this.createHealthStatus(false, ["Health check failed"]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Verify Sentry SDK is functional
|
|
157
|
+
*/
|
|
158
|
+
async ping() {
|
|
159
|
+
if (!this.sentryHub) {
|
|
160
|
+
throw new Error("Sentry SDK not initialized");
|
|
161
|
+
}
|
|
162
|
+
// Sentry SDK is available, consider it healthy
|
|
163
|
+
// Note: Sentry doesn't have a simple ping endpoint, but the SDK initialization verifies DSN
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observability Module
|
|
3
|
+
* Multi-platform observability with OpenTelemetry integration
|
|
4
|
+
*/
|
|
5
|
+
export { ExporterRegistry, getExporterRegistry, resetExporterRegistry, } from "./exporterRegistry.js";
|
|
6
|
+
export { ArizeExporter } from "./exporters/arizeExporter.js";
|
|
7
|
+
export { BaseExporter, NoOpExporter } from "./exporters/baseExporter.js";
|
|
8
|
+
export { BraintrustExporter } from "./exporters/braintrustExporter.js";
|
|
9
|
+
export { DatadogExporter } from "./exporters/datadogExporter.js";
|
|
10
|
+
export { LaminarExporter } from "./exporters/laminarExporter.js";
|
|
11
|
+
export { LangfuseExporter } from "./exporters/langfuseExporter.js";
|
|
12
|
+
export { LangSmithExporter } from "./exporters/langsmithExporter.js";
|
|
13
|
+
export { OtelExporter } from "./exporters/otelExporter.js";
|
|
14
|
+
export { PostHogExporter } from "./exporters/posthogExporter.js";
|
|
15
|
+
export { SentryExporter } from "./exporters/sentryExporter.js";
|
|
16
|
+
export { getMetricsAggregator, type LatencyStats, MetricsAggregator, type MetricsAggregatorConfig, type MetricsSummary, type ModelCostStats, type ProviderCostStats, resetMetricsAggregator, type TimeWindowStats, } from "./metricsAggregator.js";
|
|
17
|
+
export { OtelBridge } from "./otelBridge.js";
|
|
18
|
+
export { BaseRetryPolicy, CircuitBreakerAwarePolicy, ExponentialBackoffPolicy, FixedDelayPolicy, LinearBackoffPolicy, NoRetryPolicy, type RetryContext, type RetryDecision, RetryExecutor, type RetryPolicy, RetryPolicyFactory, } from "./retryPolicy.js";
|
|
19
|
+
export { AlwaysSampler, AttributeBasedSampler, CompositeSampler, CustomSampler, ErrorOnlySampler, NeverSampler, PrioritySampler, RatioSampler, type Sampler, SamplerFactory, TraceIdRatioSampler, } from "./sampling/samplers.js";
|
|
20
|
+
export { AttributeEnrichmentProcessor, BatchProcessor, CompositeProcessor, FilterProcessor, PassThroughProcessor, RedactionProcessor, type SpanProcessor, SpanProcessorFactory, TruncationProcessor, } from "./spanProcessor.js";
|
|
21
|
+
export { enrichSpanWithTokenUsage, getTokenTracker, type ModelPricing, type ModelTokenStats, type ProviderTokenStats, resetTokenTracker, TokenTracker, type TokenUsageStats, } from "./tokenTracker.js";
|
|
22
|
+
export type { ArizeExporterConfig, BraintrustExporterConfig, DatadogExporterConfig, ExportError, ExporterConfig, ExporterHealthStatus, ExporterPlugin, ExportResult, ExtendedObservabilityConfig, LaminarExporterConfig, LangfuseExporterConfig, LangSmithExporterConfig, OtelExporterConfig, OtelProtocol, PostHogExporterConfig, SamplerConfig, SamplingRule, SentryExporterConfig, } from "./types/exporterTypes.js";
|
|
23
|
+
export type { TraceView } from "./metricsAggregator.js";
|
|
24
|
+
export { AGENT_ATTRIBUTES, GENAI_ATTRIBUTES, type LangfuseSpan, type LangSmithRun, type OtelSpan, type SpanAttributes, type SpanData, type SpanEvent, type SpanLink, SpanStatus, SpanType, } from "./types/spanTypes.js";
|
|
25
|
+
export { SpanSerializer } from "./utils/spanSerializer.js";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observability Module
|
|
3
|
+
* Multi-platform observability with OpenTelemetry integration
|
|
4
|
+
*/
|
|
5
|
+
// Core - Registry with singleton pattern
|
|
6
|
+
export { ExporterRegistry, getExporterRegistry, resetExporterRegistry, } from "./exporterRegistry.js";
|
|
7
|
+
export { ArizeExporter } from "./exporters/arizeExporter.js";
|
|
8
|
+
// Exporters
|
|
9
|
+
export { BaseExporter, NoOpExporter } from "./exporters/baseExporter.js";
|
|
10
|
+
export { BraintrustExporter } from "./exporters/braintrustExporter.js";
|
|
11
|
+
export { DatadogExporter } from "./exporters/datadogExporter.js";
|
|
12
|
+
export { LaminarExporter } from "./exporters/laminarExporter.js";
|
|
13
|
+
export { LangfuseExporter } from "./exporters/langfuseExporter.js";
|
|
14
|
+
export { LangSmithExporter } from "./exporters/langsmithExporter.js";
|
|
15
|
+
export { OtelExporter } from "./exporters/otelExporter.js";
|
|
16
|
+
export { PostHogExporter } from "./exporters/posthogExporter.js";
|
|
17
|
+
export { SentryExporter } from "./exporters/sentryExporter.js";
|
|
18
|
+
// Metrics Aggregation with singleton pattern
|
|
19
|
+
export { getMetricsAggregator, MetricsAggregator, resetMetricsAggregator, } from "./metricsAggregator.js";
|
|
20
|
+
export { OtelBridge } from "./otelBridge.js";
|
|
21
|
+
// Retry Policies
|
|
22
|
+
export { BaseRetryPolicy, CircuitBreakerAwarePolicy, ExponentialBackoffPolicy, FixedDelayPolicy, LinearBackoffPolicy, NoRetryPolicy, RetryExecutor, RetryPolicyFactory, } from "./retryPolicy.js";
|
|
23
|
+
// Sampling
|
|
24
|
+
export { AlwaysSampler, AttributeBasedSampler, CompositeSampler, CustomSampler, ErrorOnlySampler, NeverSampler, PrioritySampler, RatioSampler, SamplerFactory, TraceIdRatioSampler, } from "./sampling/samplers.js";
|
|
25
|
+
// Span Processing
|
|
26
|
+
export { AttributeEnrichmentProcessor, BatchProcessor, CompositeProcessor, FilterProcessor, PassThroughProcessor, RedactionProcessor, SpanProcessorFactory, TruncationProcessor, } from "./spanProcessor.js";
|
|
27
|
+
export { enrichSpanWithTokenUsage, getTokenTracker, resetTokenTracker, TokenTracker, } from "./tokenTracker.js";
|
|
28
|
+
// Types
|
|
29
|
+
export { AGENT_ATTRIBUTES, GENAI_ATTRIBUTES, SpanStatus, SpanType, } from "./types/spanTypes.js";
|
|
30
|
+
// Utilities
|
|
31
|
+
export { SpanSerializer } from "./utils/spanSerializer.js";
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metrics Aggregator
|
|
3
|
+
* Comprehensive metrics aggregation with latency percentiles, token usage, and cost tracking
|
|
4
|
+
*/
|
|
5
|
+
import type { TokenUsageStats } from "./tokenTracker.js";
|
|
6
|
+
import { TokenTracker } from "./tokenTracker.js";
|
|
7
|
+
import type { SpanData } from "./types/spanTypes.js";
|
|
8
|
+
/**
|
|
9
|
+
* Latency statistics with percentile calculations
|
|
10
|
+
*/
|
|
11
|
+
export type LatencyStats = {
|
|
12
|
+
/** Minimum latency in milliseconds */
|
|
13
|
+
min: number;
|
|
14
|
+
/** Maximum latency in milliseconds */
|
|
15
|
+
max: number;
|
|
16
|
+
/** Mean/average latency in milliseconds */
|
|
17
|
+
mean: number;
|
|
18
|
+
/** Median latency (p50) in milliseconds */
|
|
19
|
+
median: number;
|
|
20
|
+
/** 50th percentile latency in milliseconds */
|
|
21
|
+
p50: number;
|
|
22
|
+
/** 75th percentile latency in milliseconds */
|
|
23
|
+
p75: number;
|
|
24
|
+
/** 90th percentile latency in milliseconds */
|
|
25
|
+
p90: number;
|
|
26
|
+
/** 95th percentile latency in milliseconds */
|
|
27
|
+
p95: number;
|
|
28
|
+
/** 99th percentile latency in milliseconds */
|
|
29
|
+
p99: number;
|
|
30
|
+
/** Standard deviation in milliseconds */
|
|
31
|
+
stdDev: number;
|
|
32
|
+
/** Total number of samples */
|
|
33
|
+
count: number;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Cost breakdown by provider
|
|
37
|
+
*/
|
|
38
|
+
export type ProviderCostStats = {
|
|
39
|
+
provider: string;
|
|
40
|
+
totalCost: number;
|
|
41
|
+
requestCount: number;
|
|
42
|
+
avgCostPerRequest: number;
|
|
43
|
+
inputCost: number;
|
|
44
|
+
outputCost: number;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Cost breakdown by model
|
|
48
|
+
*/
|
|
49
|
+
export type ModelCostStats = {
|
|
50
|
+
model: string;
|
|
51
|
+
provider: string;
|
|
52
|
+
totalCost: number;
|
|
53
|
+
requestCount: number;
|
|
54
|
+
avgCostPerRequest: number;
|
|
55
|
+
inputTokens: number;
|
|
56
|
+
outputTokens: number;
|
|
57
|
+
inputCost: number;
|
|
58
|
+
outputCost: number;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Time window statistics
|
|
62
|
+
*/
|
|
63
|
+
export type TimeWindowStats = {
|
|
64
|
+
windowStart: Date;
|
|
65
|
+
windowEnd: Date;
|
|
66
|
+
windowDurationMs: number;
|
|
67
|
+
requestCount: number;
|
|
68
|
+
errorCount: number;
|
|
69
|
+
successRate: number;
|
|
70
|
+
throughput: number;
|
|
71
|
+
latency: LatencyStats;
|
|
72
|
+
tokens: TokenUsageStats;
|
|
73
|
+
costByProvider: Map<string, ProviderCostStats>;
|
|
74
|
+
costByModel: Map<string, ModelCostStats>;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Aggregated metrics summary
|
|
78
|
+
*/
|
|
79
|
+
export type MetricsSummary = {
|
|
80
|
+
/** Total number of spans tracked */
|
|
81
|
+
totalSpans: number;
|
|
82
|
+
/** Number of successful spans */
|
|
83
|
+
successfulSpans: number;
|
|
84
|
+
/** Number of failed spans */
|
|
85
|
+
failedSpans: number;
|
|
86
|
+
/** Overall success rate (0-1) */
|
|
87
|
+
successRate: number;
|
|
88
|
+
/** Latency statistics */
|
|
89
|
+
latency: LatencyStats;
|
|
90
|
+
/** Token usage statistics */
|
|
91
|
+
tokens: TokenUsageStats;
|
|
92
|
+
/** Cost by provider */
|
|
93
|
+
costByProvider: ProviderCostStats[];
|
|
94
|
+
/** Cost by model */
|
|
95
|
+
costByModel: ModelCostStats[];
|
|
96
|
+
/** Total cost across all providers */
|
|
97
|
+
totalCost: number;
|
|
98
|
+
/** Span count by type */
|
|
99
|
+
spansByType: Record<string, number>;
|
|
100
|
+
/** Timestamp of first span */
|
|
101
|
+
firstSpanTime?: Date;
|
|
102
|
+
/** Timestamp of last span */
|
|
103
|
+
lastSpanTime?: Date;
|
|
104
|
+
/** Tracking duration in milliseconds */
|
|
105
|
+
trackingDurationMs?: number;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Hierarchical trace view grouping related spans
|
|
109
|
+
*/
|
|
110
|
+
export type TraceView = {
|
|
111
|
+
/** Trace identifier shared by all spans in this trace */
|
|
112
|
+
traceId: string;
|
|
113
|
+
/** The root/parent span of this trace */
|
|
114
|
+
rootSpan: SpanData;
|
|
115
|
+
/** Child spans linked to the root */
|
|
116
|
+
childSpans: SpanData[];
|
|
117
|
+
/** Total duration from first to last span */
|
|
118
|
+
totalDurationMs: number;
|
|
119
|
+
/** Total number of spans in this trace */
|
|
120
|
+
spanCount: number;
|
|
121
|
+
/** Overall trace status */
|
|
122
|
+
status: "ok" | "error" | "partial";
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Configuration for the metrics aggregator
|
|
126
|
+
*/
|
|
127
|
+
export type MetricsAggregatorConfig = {
|
|
128
|
+
/** Maximum spans to retain in memory */
|
|
129
|
+
maxSpansRetained?: number;
|
|
130
|
+
/** Enable time-window statistics */
|
|
131
|
+
enableTimeWindows?: boolean;
|
|
132
|
+
/** Time window size in milliseconds (default: 60000 = 1 minute) */
|
|
133
|
+
timeWindowMs?: number;
|
|
134
|
+
/** Maximum time windows to retain */
|
|
135
|
+
maxTimeWindows?: number;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Metrics Aggregator for comprehensive telemetry analysis
|
|
139
|
+
* Provides latency percentiles, token aggregation, and cost tracking
|
|
140
|
+
*/
|
|
141
|
+
export declare class MetricsAggregator {
|
|
142
|
+
private spans;
|
|
143
|
+
private latencyValues;
|
|
144
|
+
private tokenTracker;
|
|
145
|
+
private timeWindows;
|
|
146
|
+
private config;
|
|
147
|
+
private spansByType;
|
|
148
|
+
private costByProvider;
|
|
149
|
+
private costByModel;
|
|
150
|
+
private successCount;
|
|
151
|
+
private failureCount;
|
|
152
|
+
private firstSpanTime?;
|
|
153
|
+
private lastSpanTime?;
|
|
154
|
+
constructor(config?: MetricsAggregatorConfig);
|
|
155
|
+
/**
|
|
156
|
+
* Record a span for metrics aggregation
|
|
157
|
+
*/
|
|
158
|
+
recordSpan(span: SpanData): void;
|
|
159
|
+
/**
|
|
160
|
+
* Track cost aggregations from a span
|
|
161
|
+
*/
|
|
162
|
+
private trackCosts;
|
|
163
|
+
/**
|
|
164
|
+
* Update time window statistics
|
|
165
|
+
*/
|
|
166
|
+
private updateTimeWindow;
|
|
167
|
+
/**
|
|
168
|
+
* Create an empty time window
|
|
169
|
+
*/
|
|
170
|
+
private createEmptyTimeWindow;
|
|
171
|
+
/**
|
|
172
|
+
* Create empty latency stats
|
|
173
|
+
*/
|
|
174
|
+
private createEmptyLatencyStats;
|
|
175
|
+
/**
|
|
176
|
+
* Calculate latency percentile from sorted array
|
|
177
|
+
*/
|
|
178
|
+
private calculatePercentile;
|
|
179
|
+
/**
|
|
180
|
+
* Calculate standard deviation
|
|
181
|
+
*/
|
|
182
|
+
private calculateStdDev;
|
|
183
|
+
/**
|
|
184
|
+
* Get comprehensive latency statistics
|
|
185
|
+
*/
|
|
186
|
+
getLatencyStats(): LatencyStats;
|
|
187
|
+
/**
|
|
188
|
+
* Get token usage statistics
|
|
189
|
+
*/
|
|
190
|
+
getTokenStats(): TokenUsageStats;
|
|
191
|
+
/**
|
|
192
|
+
* Get cost breakdown by provider
|
|
193
|
+
*/
|
|
194
|
+
getCostByProvider(): ProviderCostStats[];
|
|
195
|
+
/**
|
|
196
|
+
* Get cost breakdown by model
|
|
197
|
+
*/
|
|
198
|
+
getCostByModel(): ModelCostStats[];
|
|
199
|
+
/**
|
|
200
|
+
* Get total cost across all providers
|
|
201
|
+
*/
|
|
202
|
+
getTotalCost(): number;
|
|
203
|
+
/**
|
|
204
|
+
* Get time window statistics
|
|
205
|
+
*/
|
|
206
|
+
getTimeWindows(): TimeWindowStats[];
|
|
207
|
+
/**
|
|
208
|
+
* Get statistics for a specific time range
|
|
209
|
+
*/
|
|
210
|
+
getStatsForTimeRange(startTime: Date, endTime: Date): TimeWindowStats;
|
|
211
|
+
/**
|
|
212
|
+
* Record a latency measurement for an operation
|
|
213
|
+
* Use this for standalone latency tracking without a full span
|
|
214
|
+
*/
|
|
215
|
+
recordLatency(operation: string, latencyMs: number): void;
|
|
216
|
+
/**
|
|
217
|
+
* Get comprehensive metrics summary (alias for getSummary)
|
|
218
|
+
*/
|
|
219
|
+
getMetrics(): MetricsSummary;
|
|
220
|
+
/**
|
|
221
|
+
* Get comprehensive metrics summary
|
|
222
|
+
*/
|
|
223
|
+
getSummary(): MetricsSummary;
|
|
224
|
+
/**
|
|
225
|
+
* Get all recorded spans (returns a copy)
|
|
226
|
+
*/
|
|
227
|
+
getSpans(): SpanData[];
|
|
228
|
+
/**
|
|
229
|
+
* Get spans grouped by traceId as hierarchical trace views
|
|
230
|
+
*/
|
|
231
|
+
getTraces(): TraceView[];
|
|
232
|
+
/**
|
|
233
|
+
* Get the underlying token tracker for custom pricing configuration
|
|
234
|
+
*/
|
|
235
|
+
getTokenTracker(): TokenTracker;
|
|
236
|
+
/**
|
|
237
|
+
* Reset all metrics
|
|
238
|
+
*/
|
|
239
|
+
reset(): void;
|
|
240
|
+
/**
|
|
241
|
+
* Export metrics as JSON
|
|
242
|
+
*/
|
|
243
|
+
toJSON(): Record<string, unknown>;
|
|
244
|
+
/**
|
|
245
|
+
* Format cost as currency string
|
|
246
|
+
*/
|
|
247
|
+
formatCost(cost: number, currency?: string): string;
|
|
248
|
+
/**
|
|
249
|
+
* Get a formatted summary string
|
|
250
|
+
*/
|
|
251
|
+
getFormattedSummary(): string;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Get the global metrics aggregator instance
|
|
255
|
+
*/
|
|
256
|
+
export declare function getMetricsAggregator(): MetricsAggregator;
|
|
257
|
+
/**
|
|
258
|
+
* Reset the global metrics aggregator (for testing)
|
|
259
|
+
*/
|
|
260
|
+
export declare function resetMetricsAggregator(): void;
|