@juspay/neurolink 9.24.0 → 9.25.1
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/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.js +29 -15
- 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 +117 -110
- 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/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 +117 -110
- 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/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 +1007 -564
- 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 +204 -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 +557 -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 +304 -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/safeMetadata.d.ts +10 -0
- package/dist/lib/observability/utils/safeMetadata.js +26 -0
- package/dist/lib/observability/utils/spanSerializer.d.ts +115 -0
- package/dist/lib/observability/utils/spanSerializer.js +291 -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 +76 -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/conversationMemoryInterface.d.ts +2 -0
- 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 +1007 -564
- 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 +203 -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 +556 -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 +303 -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/safeMetadata.d.ts +10 -0
- package/dist/observability/utils/safeMetadata.js +25 -0
- package/dist/observability/utils/spanSerializer.d.ts +115 -0
- package/dist/observability/utils/spanSerializer.js +290 -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 +76 -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/conversationMemoryInterface.d.ts +2 -0
- 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,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Datadog Exporter
|
|
3
|
+
* Exports spans to Datadog APM platform
|
|
4
|
+
*/
|
|
5
|
+
import { logger } from "../../utils/logger.js";
|
|
6
|
+
import { SpanStatus } from "../types/spanTypes.js";
|
|
7
|
+
import { BaseExporter } from "./baseExporter.js";
|
|
8
|
+
/**
|
|
9
|
+
* Datadog exporter for enterprise APM integration
|
|
10
|
+
* Supports trace correlation and AI-specific custom metrics
|
|
11
|
+
*/
|
|
12
|
+
export class DatadogExporter extends BaseExporter {
|
|
13
|
+
apiKey;
|
|
14
|
+
appKey;
|
|
15
|
+
site;
|
|
16
|
+
service;
|
|
17
|
+
source;
|
|
18
|
+
logsEndpoint;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
super("datadog", config);
|
|
21
|
+
this.apiKey = config.apiKey;
|
|
22
|
+
this.appKey = config.appKey;
|
|
23
|
+
this.site = config.site ?? "us1";
|
|
24
|
+
this.service = config.service ?? "neurolink";
|
|
25
|
+
this.source = config.source ?? "neurolink-ai";
|
|
26
|
+
const baseDomain = this.site === "us1" ? "datadoghq.com" : `${this.site}.datadoghq.com`;
|
|
27
|
+
this.logsEndpoint = `https://http-intake.logs.${baseDomain}/api/v2/logs`;
|
|
28
|
+
}
|
|
29
|
+
async initialize() {
|
|
30
|
+
if (this.initialized) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
// Validate API key
|
|
34
|
+
try {
|
|
35
|
+
const validateUrl = this.site === "us1"
|
|
36
|
+
? "https://api.datadoghq.com/api/v1/validate"
|
|
37
|
+
: `https://api.${this.site}.datadoghq.com/api/v1/validate`;
|
|
38
|
+
const response = await fetch(validateUrl, {
|
|
39
|
+
headers: {
|
|
40
|
+
"DD-API-KEY": this.apiKey,
|
|
41
|
+
...(this.appKey && { "DD-APPLICATION-KEY": this.appKey }),
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
throw new Error(`Datadog API key validation failed: ${response.statusText}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
// Allow initialization to proceed even if API is unreachable
|
|
50
|
+
logger.warn("[Datadog] Could not verify API connection:", error instanceof Error ? error.message : error);
|
|
51
|
+
}
|
|
52
|
+
this.initialized = true;
|
|
53
|
+
this.startFlushInterval(this.config.flushIntervalMs ?? 10000);
|
|
54
|
+
}
|
|
55
|
+
async exportSpan(span) {
|
|
56
|
+
const startTime = Date.now();
|
|
57
|
+
try {
|
|
58
|
+
const log = this.convertToDatadogLog(span);
|
|
59
|
+
const response = await fetch(this.logsEndpoint, {
|
|
60
|
+
method: "POST",
|
|
61
|
+
headers: {
|
|
62
|
+
"Content-Type": "application/json",
|
|
63
|
+
"DD-API-KEY": this.apiKey,
|
|
64
|
+
},
|
|
65
|
+
body: JSON.stringify([log]),
|
|
66
|
+
});
|
|
67
|
+
if (!response.ok) {
|
|
68
|
+
throw new Error(`Export failed: ${response.statusText}`);
|
|
69
|
+
}
|
|
70
|
+
return this.createSuccessResult(1, Date.now() - startTime);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
return this.createFailureResult([span.spanId], error instanceof Error ? error.message : String(error), Date.now() - startTime);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async exportBatch(spans) {
|
|
77
|
+
const startTime = Date.now();
|
|
78
|
+
try {
|
|
79
|
+
const logs = spans.map((s) => this.convertToDatadogLog(s));
|
|
80
|
+
const response = await fetch(this.logsEndpoint, {
|
|
81
|
+
method: "POST",
|
|
82
|
+
headers: {
|
|
83
|
+
"Content-Type": "application/json",
|
|
84
|
+
"DD-API-KEY": this.apiKey,
|
|
85
|
+
},
|
|
86
|
+
body: JSON.stringify(logs),
|
|
87
|
+
});
|
|
88
|
+
if (!response.ok) {
|
|
89
|
+
throw new Error(`Batch export failed: ${response.statusText}`);
|
|
90
|
+
}
|
|
91
|
+
return this.createSuccessResult(spans.length, Date.now() - startTime);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
return this.createFailureResult(spans.map((s) => s.spanId), error instanceof Error ? error.message : String(error), Date.now() - startTime);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async flush() {
|
|
98
|
+
if (this.buffer.length > 0) {
|
|
99
|
+
const spans = [...this.buffer];
|
|
100
|
+
this.buffer = [];
|
|
101
|
+
await this.exportBatch(spans);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async shutdown() {
|
|
105
|
+
await this.flush();
|
|
106
|
+
this.stopFlushInterval();
|
|
107
|
+
this.initialized = false;
|
|
108
|
+
}
|
|
109
|
+
async healthCheck() {
|
|
110
|
+
try {
|
|
111
|
+
await this.withRetry(() => this.ping(), "health check");
|
|
112
|
+
return this.createHealthStatus(true);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return this.createHealthStatus(false, ["Health check failed"]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Verify connectivity to Datadog API
|
|
120
|
+
*/
|
|
121
|
+
async ping() {
|
|
122
|
+
const validateUrl = this.site === "us1"
|
|
123
|
+
? "https://api.datadoghq.com/api/v1/validate"
|
|
124
|
+
: `https://api.${this.site}.datadoghq.com/api/v1/validate`;
|
|
125
|
+
const response = await fetch(validateUrl, {
|
|
126
|
+
headers: { "DD-API-KEY": this.apiKey },
|
|
127
|
+
});
|
|
128
|
+
if (!response.ok) {
|
|
129
|
+
throw new Error(`Datadog API validation failed: ${response.status}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Convert span to Datadog log format with trace correlation
|
|
134
|
+
*/
|
|
135
|
+
convertToDatadogLog(span) {
|
|
136
|
+
return {
|
|
137
|
+
ddsource: this.source,
|
|
138
|
+
ddtags: this.buildTags(span),
|
|
139
|
+
hostname: process.env.HOSTNAME || "unknown",
|
|
140
|
+
message: `${span.type}: ${span.name}`,
|
|
141
|
+
service: this.service,
|
|
142
|
+
status: span.status === SpanStatus.ERROR ? "error" : "info",
|
|
143
|
+
timestamp: new Date(span.startTime).getTime(),
|
|
144
|
+
// Trace correlation
|
|
145
|
+
dd: {
|
|
146
|
+
trace_id: span.traceId,
|
|
147
|
+
span_id: span.spanId,
|
|
148
|
+
},
|
|
149
|
+
// AI-specific attributes
|
|
150
|
+
ai: {
|
|
151
|
+
provider: span.attributes["ai.provider"],
|
|
152
|
+
model: span.attributes["ai.model"],
|
|
153
|
+
tokens: {
|
|
154
|
+
input: span.attributes["ai.tokens.input"],
|
|
155
|
+
output: span.attributes["ai.tokens.output"],
|
|
156
|
+
total: span.attributes["ai.tokens.total"],
|
|
157
|
+
},
|
|
158
|
+
cost: span.attributes["ai.cost.total"],
|
|
159
|
+
duration_ms: span.durationMs,
|
|
160
|
+
},
|
|
161
|
+
// User context
|
|
162
|
+
usr: {
|
|
163
|
+
id: span.attributes["user.id"],
|
|
164
|
+
session_id: span.attributes["session.id"],
|
|
165
|
+
},
|
|
166
|
+
// Error details
|
|
167
|
+
...(span.status === SpanStatus.ERROR && {
|
|
168
|
+
error: {
|
|
169
|
+
message: span.statusMessage,
|
|
170
|
+
type: span.attributes["error.type"],
|
|
171
|
+
stack: span.attributes["error.stack"],
|
|
172
|
+
},
|
|
173
|
+
}),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Build Datadog tags from span attributes
|
|
178
|
+
*/
|
|
179
|
+
buildTags(span) {
|
|
180
|
+
const tags = [
|
|
181
|
+
`env:${this.config.environment ?? "production"}`,
|
|
182
|
+
`version:${this.config.version ?? "unknown"}`,
|
|
183
|
+
`span_type:${span.type}`,
|
|
184
|
+
];
|
|
185
|
+
if (span.attributes["ai.provider"]) {
|
|
186
|
+
tags.push(`ai_provider:${span.attributes["ai.provider"]}`);
|
|
187
|
+
}
|
|
188
|
+
if (span.attributes["ai.model"]) {
|
|
189
|
+
tags.push(`ai_model:${span.attributes["ai.model"]}`);
|
|
190
|
+
}
|
|
191
|
+
if (span.attributes["tool.name"]) {
|
|
192
|
+
tags.push(`tool:${span.attributes["tool.name"]}`);
|
|
193
|
+
}
|
|
194
|
+
return tags.join(",");
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=datadogExporter.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observability exporters exports
|
|
3
|
+
*/
|
|
4
|
+
export { ArizeExporter } from "./arizeExporter.js";
|
|
5
|
+
export { BaseExporter, NoOpExporter } from "./baseExporter.js";
|
|
6
|
+
export { BraintrustExporter } from "./braintrustExporter.js";
|
|
7
|
+
export { DatadogExporter } from "./datadogExporter.js";
|
|
8
|
+
export { LaminarExporter } from "./laminarExporter.js";
|
|
9
|
+
export { LangfuseExporter } from "./langfuseExporter.js";
|
|
10
|
+
export { LangSmithExporter } from "./langsmithExporter.js";
|
|
11
|
+
export { OtelExporter } from "./otelExporter.js";
|
|
12
|
+
export { PostHogExporter } from "./posthogExporter.js";
|
|
13
|
+
export { SentryExporter } from "./sentryExporter.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observability exporters exports
|
|
3
|
+
*/
|
|
4
|
+
export { ArizeExporter } from "./arizeExporter.js";
|
|
5
|
+
export { BaseExporter, NoOpExporter } from "./baseExporter.js";
|
|
6
|
+
export { BraintrustExporter } from "./braintrustExporter.js";
|
|
7
|
+
export { DatadogExporter } from "./datadogExporter.js";
|
|
8
|
+
export { LaminarExporter } from "./laminarExporter.js";
|
|
9
|
+
export { LangfuseExporter } from "./langfuseExporter.js";
|
|
10
|
+
export { LangSmithExporter } from "./langsmithExporter.js";
|
|
11
|
+
export { OtelExporter } from "./otelExporter.js";
|
|
12
|
+
export { PostHogExporter } from "./posthogExporter.js";
|
|
13
|
+
export { SentryExporter } from "./sentryExporter.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Laminar Exporter
|
|
3
|
+
* Exports spans to Laminar LLM tracing platform
|
|
4
|
+
* @see https://docs.laminar.run/
|
|
5
|
+
*/
|
|
6
|
+
import type { ExporterHealthStatus, ExportResult, LaminarExporterConfig, SpanData } from "../types/index.js";
|
|
7
|
+
import { BaseExporter } from "./baseExporter.js";
|
|
8
|
+
/**
|
|
9
|
+
* Laminar exporter for LLM pipeline tracing and monitoring
|
|
10
|
+
* Supports detailed traces with input/output tracking
|
|
11
|
+
*/
|
|
12
|
+
export declare class LaminarExporter extends BaseExporter {
|
|
13
|
+
private readonly apiKey;
|
|
14
|
+
private readonly projectApiKey?;
|
|
15
|
+
private readonly baseUrl;
|
|
16
|
+
constructor(config: LaminarExporterConfig);
|
|
17
|
+
initialize(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Get authorization headers
|
|
20
|
+
*/
|
|
21
|
+
private getHeaders;
|
|
22
|
+
exportSpan(span: SpanData): Promise<ExportResult>;
|
|
23
|
+
exportBatch(spans: SpanData[]): Promise<ExportResult>;
|
|
24
|
+
flush(): Promise<void>;
|
|
25
|
+
shutdown(): Promise<void>;
|
|
26
|
+
healthCheck(): Promise<ExporterHealthStatus>;
|
|
27
|
+
/**
|
|
28
|
+
* Verify connectivity to Laminar API
|
|
29
|
+
*/
|
|
30
|
+
protected ping(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Convert span to Laminar trace format
|
|
33
|
+
*/
|
|
34
|
+
private convertToLaminarTrace;
|
|
35
|
+
/**
|
|
36
|
+
* Map NeuroLink span type to Laminar type
|
|
37
|
+
*/
|
|
38
|
+
private mapSpanTypeToLaminarType;
|
|
39
|
+
/**
|
|
40
|
+
* Map span status to Laminar status format
|
|
41
|
+
*/
|
|
42
|
+
private mapSpanStatus;
|
|
43
|
+
/**
|
|
44
|
+
* Extract additional metadata from span attributes
|
|
45
|
+
* Filters out standard attributes that are already handled
|
|
46
|
+
*/
|
|
47
|
+
private extractMetadata;
|
|
48
|
+
}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Laminar Exporter
|
|
3
|
+
* Exports spans to Laminar LLM tracing platform
|
|
4
|
+
* @see https://docs.laminar.run/
|
|
5
|
+
*/
|
|
6
|
+
import { logger } from "../../utils/logger.js";
|
|
7
|
+
import { SpanStatus, SpanType } from "../types/spanTypes.js";
|
|
8
|
+
import { BaseExporter } from "./baseExporter.js";
|
|
9
|
+
/**
|
|
10
|
+
* Laminar exporter for LLM pipeline tracing and monitoring
|
|
11
|
+
* Supports detailed traces with input/output tracking
|
|
12
|
+
*/
|
|
13
|
+
export class LaminarExporter extends BaseExporter {
|
|
14
|
+
apiKey;
|
|
15
|
+
projectApiKey;
|
|
16
|
+
baseUrl;
|
|
17
|
+
constructor(config) {
|
|
18
|
+
super("laminar", config);
|
|
19
|
+
this.apiKey = config.apiKey;
|
|
20
|
+
this.projectApiKey = config.projectApiKey;
|
|
21
|
+
this.baseUrl = config.baseUrl ?? "https://api.laminar.run";
|
|
22
|
+
}
|
|
23
|
+
async initialize() {
|
|
24
|
+
if (this.initialized) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
// Verify API key by making a test call
|
|
28
|
+
try {
|
|
29
|
+
const response = await fetch(`${this.baseUrl}/v1/health`, {
|
|
30
|
+
headers: this.getHeaders(),
|
|
31
|
+
});
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
logger.warn("[Laminar] Could not verify API connection:", response.statusText);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
logger.warn("[Laminar] Could not verify API connection:", error instanceof Error ? error.message : error);
|
|
38
|
+
}
|
|
39
|
+
this.initialized = true;
|
|
40
|
+
this.startFlushInterval(this.config.flushIntervalMs ?? 5000);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get authorization headers
|
|
44
|
+
*/
|
|
45
|
+
getHeaders() {
|
|
46
|
+
const headers = {
|
|
47
|
+
"Content-Type": "application/json",
|
|
48
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
49
|
+
};
|
|
50
|
+
// Add project API key if provided
|
|
51
|
+
if (this.projectApiKey) {
|
|
52
|
+
headers["X-Project-Api-Key"] = this.projectApiKey;
|
|
53
|
+
}
|
|
54
|
+
return headers;
|
|
55
|
+
}
|
|
56
|
+
async exportSpan(span) {
|
|
57
|
+
const startTime = Date.now();
|
|
58
|
+
try {
|
|
59
|
+
const trace = this.convertToLaminarTrace(span);
|
|
60
|
+
const response = await fetch(`${this.baseUrl}/v1/traces`, {
|
|
61
|
+
method: "POST",
|
|
62
|
+
headers: this.getHeaders(),
|
|
63
|
+
body: JSON.stringify(trace),
|
|
64
|
+
});
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
throw new Error(`Export failed: ${response.statusText}`);
|
|
67
|
+
}
|
|
68
|
+
return this.createSuccessResult(1, Date.now() - startTime);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
return this.createFailureResult([span.spanId], error instanceof Error ? error.message : String(error), Date.now() - startTime);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async exportBatch(spans) {
|
|
75
|
+
const startTime = Date.now();
|
|
76
|
+
try {
|
|
77
|
+
const traces = spans.map((s) => this.convertToLaminarTrace(s));
|
|
78
|
+
const response = await fetch(`${this.baseUrl}/v1/traces/batch`, {
|
|
79
|
+
method: "POST",
|
|
80
|
+
headers: this.getHeaders(),
|
|
81
|
+
body: JSON.stringify({ traces }),
|
|
82
|
+
});
|
|
83
|
+
if (!response.ok) {
|
|
84
|
+
throw new Error(`Batch export failed: ${response.statusText}`);
|
|
85
|
+
}
|
|
86
|
+
return this.createSuccessResult(spans.length, Date.now() - startTime);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
return this.createFailureResult(spans.map((s) => s.spanId), error instanceof Error ? error.message : String(error), Date.now() - startTime);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async flush() {
|
|
93
|
+
if (this.buffer.length > 0) {
|
|
94
|
+
const spans = [...this.buffer];
|
|
95
|
+
this.buffer = [];
|
|
96
|
+
await this.exportBatch(spans);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async shutdown() {
|
|
100
|
+
await this.flush();
|
|
101
|
+
this.stopFlushInterval();
|
|
102
|
+
this.initialized = false;
|
|
103
|
+
}
|
|
104
|
+
async healthCheck() {
|
|
105
|
+
try {
|
|
106
|
+
await this.withRetry(() => this.ping(), "health check");
|
|
107
|
+
return this.createHealthStatus(true);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return this.createHealthStatus(false, ["Health check failed"]);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Verify connectivity to Laminar API
|
|
115
|
+
*/
|
|
116
|
+
async ping() {
|
|
117
|
+
const response = await fetch(`${this.baseUrl}/v1/health`, {
|
|
118
|
+
headers: this.getHeaders(),
|
|
119
|
+
});
|
|
120
|
+
if (!response.ok) {
|
|
121
|
+
throw new Error(`Laminar API unreachable: ${response.status}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Convert span to Laminar trace format
|
|
126
|
+
*/
|
|
127
|
+
convertToLaminarTrace(span) {
|
|
128
|
+
return {
|
|
129
|
+
// Core identifiers
|
|
130
|
+
trace_id: span.traceId,
|
|
131
|
+
span_id: span.spanId,
|
|
132
|
+
parent_span_id: span.parentSpanId,
|
|
133
|
+
// Trace metadata
|
|
134
|
+
name: span.name,
|
|
135
|
+
type: this.mapSpanTypeToLaminarType(span.type),
|
|
136
|
+
start_time: span.startTime,
|
|
137
|
+
end_time: span.endTime,
|
|
138
|
+
duration_ms: span.durationMs,
|
|
139
|
+
// Status
|
|
140
|
+
status: this.mapSpanStatus(span.status),
|
|
141
|
+
status_message: span.statusMessage,
|
|
142
|
+
// Model information
|
|
143
|
+
model: {
|
|
144
|
+
provider: span.attributes["ai.provider"],
|
|
145
|
+
name: span.attributes["ai.model"],
|
|
146
|
+
version: span.attributes["ai.model.version"],
|
|
147
|
+
},
|
|
148
|
+
// Token usage
|
|
149
|
+
usage: {
|
|
150
|
+
input_tokens: span.attributes["ai.tokens.input"],
|
|
151
|
+
output_tokens: span.attributes["ai.tokens.output"],
|
|
152
|
+
total_tokens: span.attributes["ai.tokens.total"],
|
|
153
|
+
cache_read_tokens: span.attributes["ai.tokens.cache_read"],
|
|
154
|
+
cache_creation_tokens: span.attributes["ai.tokens.cache_creation"],
|
|
155
|
+
reasoning_tokens: span.attributes["ai.tokens.reasoning"],
|
|
156
|
+
},
|
|
157
|
+
// Cost tracking
|
|
158
|
+
cost: {
|
|
159
|
+
input: span.attributes["ai.cost.input"],
|
|
160
|
+
output: span.attributes["ai.cost.output"],
|
|
161
|
+
total: span.attributes["ai.cost.total"],
|
|
162
|
+
currency: span.attributes["ai.cost.currency"] || "USD",
|
|
163
|
+
},
|
|
164
|
+
// Generation parameters
|
|
165
|
+
parameters: {
|
|
166
|
+
temperature: span.attributes["ai.temperature"],
|
|
167
|
+
max_tokens: span.attributes["ai.max_tokens"],
|
|
168
|
+
top_p: span.attributes["ai.top_p"],
|
|
169
|
+
stop_sequences: span.attributes["ai.stop_sequences"],
|
|
170
|
+
},
|
|
171
|
+
// Input/Output
|
|
172
|
+
input: span.attributes["input"],
|
|
173
|
+
output: span.attributes["output"],
|
|
174
|
+
// Tool information
|
|
175
|
+
tool: span.attributes["tool.name"]
|
|
176
|
+
? {
|
|
177
|
+
name: span.attributes["tool.name"],
|
|
178
|
+
server: span.attributes["tool.server"],
|
|
179
|
+
success: span.attributes["tool.success"],
|
|
180
|
+
}
|
|
181
|
+
: undefined,
|
|
182
|
+
// Error information
|
|
183
|
+
error: span.status === SpanStatus.ERROR
|
|
184
|
+
? {
|
|
185
|
+
type: span.attributes["error.type"],
|
|
186
|
+
message: span.attributes["error.message"],
|
|
187
|
+
stack: span.attributes["error.stack"],
|
|
188
|
+
}
|
|
189
|
+
: undefined,
|
|
190
|
+
// User and session context
|
|
191
|
+
context: {
|
|
192
|
+
user_id: span.attributes["user.id"],
|
|
193
|
+
session_id: span.attributes["session.id"],
|
|
194
|
+
environment: span.attributes["deployment.environment"] || this.config.environment,
|
|
195
|
+
service: {
|
|
196
|
+
name: span.attributes["service.name"],
|
|
197
|
+
version: span.attributes["service.version"] || this.config.version,
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
// Events
|
|
201
|
+
events: span.events.map((event) => ({
|
|
202
|
+
name: event.name,
|
|
203
|
+
timestamp: event.timestamp,
|
|
204
|
+
attributes: event.attributes,
|
|
205
|
+
})),
|
|
206
|
+
// Links to related spans
|
|
207
|
+
links: span.links.map((link) => ({
|
|
208
|
+
trace_id: link.traceId,
|
|
209
|
+
span_id: link.spanId,
|
|
210
|
+
attributes: link.attributes,
|
|
211
|
+
})),
|
|
212
|
+
// Additional metadata
|
|
213
|
+
metadata: this.extractMetadata(span.attributes),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Map NeuroLink span type to Laminar type
|
|
218
|
+
*/
|
|
219
|
+
mapSpanTypeToLaminarType(type) {
|
|
220
|
+
const typeMap = {
|
|
221
|
+
[SpanType.AGENT_RUN]: "agent",
|
|
222
|
+
[SpanType.WORKFLOW_STEP]: "workflow",
|
|
223
|
+
[SpanType.TOOL_CALL]: "tool",
|
|
224
|
+
[SpanType.MODEL_GENERATION]: "llm",
|
|
225
|
+
[SpanType.EMBEDDING]: "embedding",
|
|
226
|
+
[SpanType.RETRIEVAL]: "retrieval",
|
|
227
|
+
[SpanType.MEMORY]: "memory",
|
|
228
|
+
[SpanType.CONTEXT_COMPACTION]: "custom",
|
|
229
|
+
[SpanType.RAG]: "retrieval",
|
|
230
|
+
[SpanType.EVALUATION]: "custom",
|
|
231
|
+
[SpanType.MCP_TRANSPORT]: "tool",
|
|
232
|
+
[SpanType.MEDIA_GENERATION]: "llm",
|
|
233
|
+
[SpanType.PPT_GENERATION]: "custom",
|
|
234
|
+
[SpanType.WORKFLOW]: "workflow",
|
|
235
|
+
[SpanType.TTS]: "custom",
|
|
236
|
+
[SpanType.SERVER_REQUEST]: "custom",
|
|
237
|
+
[SpanType.CUSTOM]: "custom",
|
|
238
|
+
};
|
|
239
|
+
return typeMap[type] || "custom";
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Map span status to Laminar status format
|
|
243
|
+
*/
|
|
244
|
+
mapSpanStatus(status) {
|
|
245
|
+
switch (status) {
|
|
246
|
+
case SpanStatus.OK:
|
|
247
|
+
return "success";
|
|
248
|
+
case SpanStatus.ERROR:
|
|
249
|
+
return "error";
|
|
250
|
+
default:
|
|
251
|
+
return "unset";
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Extract additional metadata from span attributes
|
|
256
|
+
* Filters out standard attributes that are already handled
|
|
257
|
+
*/
|
|
258
|
+
extractMetadata(attributes) {
|
|
259
|
+
const standardKeys = new Set([
|
|
260
|
+
"service.name",
|
|
261
|
+
"service.version",
|
|
262
|
+
"deployment.environment",
|
|
263
|
+
"user.id",
|
|
264
|
+
"session.id",
|
|
265
|
+
"ai.provider",
|
|
266
|
+
"ai.model",
|
|
267
|
+
"ai.model.version",
|
|
268
|
+
"ai.tokens.input",
|
|
269
|
+
"ai.tokens.output",
|
|
270
|
+
"ai.tokens.total",
|
|
271
|
+
"ai.tokens.cache_read",
|
|
272
|
+
"ai.tokens.cache_creation",
|
|
273
|
+
"ai.tokens.reasoning",
|
|
274
|
+
"ai.cost.input",
|
|
275
|
+
"ai.cost.output",
|
|
276
|
+
"ai.cost.total",
|
|
277
|
+
"ai.cost.currency",
|
|
278
|
+
"ai.temperature",
|
|
279
|
+
"ai.max_tokens",
|
|
280
|
+
"ai.top_p",
|
|
281
|
+
"ai.stop_sequences",
|
|
282
|
+
"tool.name",
|
|
283
|
+
"tool.server",
|
|
284
|
+
"tool.success",
|
|
285
|
+
"error.type",
|
|
286
|
+
"error.message",
|
|
287
|
+
"error.stack",
|
|
288
|
+
"error",
|
|
289
|
+
"input",
|
|
290
|
+
"output",
|
|
291
|
+
"expected",
|
|
292
|
+
"scores",
|
|
293
|
+
]);
|
|
294
|
+
const metadata = {};
|
|
295
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
296
|
+
if (!standardKeys.has(key) && value !== undefined) {
|
|
297
|
+
metadata[key] = value;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return metadata;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
//# sourceMappingURL=laminarExporter.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Langfuse Exporter
|
|
3
|
+
* Exports spans to Langfuse observability platform
|
|
4
|
+
*/
|
|
5
|
+
import type { ExporterHealthStatus, ExportResult, LangfuseExporterConfig, SpanData } from "../types/index.js";
|
|
6
|
+
import { BaseExporter } from "./baseExporter.js";
|
|
7
|
+
/**
|
|
8
|
+
* Langfuse exporter for LLM observability
|
|
9
|
+
* Supports traces, generations, spans, and scores
|
|
10
|
+
*/
|
|
11
|
+
export declare class LangfuseExporter extends BaseExporter {
|
|
12
|
+
private readonly publicKey;
|
|
13
|
+
private readonly secretKey;
|
|
14
|
+
private readonly baseUrl;
|
|
15
|
+
private readonly release?;
|
|
16
|
+
constructor(config: LangfuseExporterConfig);
|
|
17
|
+
initialize(): Promise<void>;
|
|
18
|
+
exportSpan(span: SpanData): Promise<ExportResult>;
|
|
19
|
+
exportBatch(spans: SpanData[]): Promise<ExportResult>;
|
|
20
|
+
flush(): Promise<void>;
|
|
21
|
+
shutdown(): Promise<void>;
|
|
22
|
+
healthCheck(): Promise<ExporterHealthStatus>;
|
|
23
|
+
/**
|
|
24
|
+
* Verify connectivity to Langfuse API
|
|
25
|
+
*/
|
|
26
|
+
protected ping(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Create a Langfuse trace
|
|
29
|
+
*/
|
|
30
|
+
private createTrace;
|
|
31
|
+
/**
|
|
32
|
+
* Create a Langfuse span
|
|
33
|
+
*/
|
|
34
|
+
private createSpan;
|
|
35
|
+
/**
|
|
36
|
+
* Create a Langfuse generation (for LLM calls)
|
|
37
|
+
*/
|
|
38
|
+
private createGeneration;
|
|
39
|
+
/**
|
|
40
|
+
* Make API call to Langfuse
|
|
41
|
+
*/
|
|
42
|
+
private apiCall;
|
|
43
|
+
/**
|
|
44
|
+
* Extract tags from span attributes
|
|
45
|
+
*/
|
|
46
|
+
private extractTags;
|
|
47
|
+
}
|