@juspay/neurolink 9.24.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 +6 -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 +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/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/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/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 +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/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,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostHog Exporter
|
|
3
|
+
* Exports spans to PostHog product analytics platform
|
|
4
|
+
* @see https://posthog.com/docs/api
|
|
5
|
+
*/
|
|
6
|
+
import { logger } from "../../utils/logger.js";
|
|
7
|
+
import { SpanStatus, SpanType } from "../types/spanTypes.js";
|
|
8
|
+
import { BaseExporter } from "./baseExporter.js";
|
|
9
|
+
/**
|
|
10
|
+
* PostHog exporter for product analytics and LLM event tracking
|
|
11
|
+
* Supports capturing LLM interactions as events with properties
|
|
12
|
+
*/
|
|
13
|
+
export class PostHogExporter extends BaseExporter {
|
|
14
|
+
apiKey;
|
|
15
|
+
host;
|
|
16
|
+
personalApiKey;
|
|
17
|
+
constructor(config) {
|
|
18
|
+
super("posthog", config);
|
|
19
|
+
this.apiKey = config.apiKey;
|
|
20
|
+
this.host = config.host ?? "https://app.posthog.com";
|
|
21
|
+
this.personalApiKey = config.personalApiKey;
|
|
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.host}/api/projects/`, {
|
|
30
|
+
headers: this.getHeaders(),
|
|
31
|
+
});
|
|
32
|
+
if (!response.ok && response.status !== 401) {
|
|
33
|
+
// 401 is expected with project API key
|
|
34
|
+
logger.warn("[PostHog] Could not verify API connection:", response.statusText);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
logger.warn("[PostHog] Could not verify API connection:", error instanceof Error ? error.message : error);
|
|
39
|
+
}
|
|
40
|
+
this.initialized = true;
|
|
41
|
+
this.startFlushInterval(this.config.flushIntervalMs ?? 5000);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get authorization headers
|
|
45
|
+
*/
|
|
46
|
+
getHeaders() {
|
|
47
|
+
const headers = {
|
|
48
|
+
"Content-Type": "application/json",
|
|
49
|
+
};
|
|
50
|
+
// Use personal API key for management endpoints, project API key for events
|
|
51
|
+
if (this.personalApiKey) {
|
|
52
|
+
headers["Authorization"] = `Bearer ${this.personalApiKey}`;
|
|
53
|
+
}
|
|
54
|
+
return headers;
|
|
55
|
+
}
|
|
56
|
+
async exportSpan(span) {
|
|
57
|
+
const startTime = Date.now();
|
|
58
|
+
try {
|
|
59
|
+
const event = this.convertToPostHogEvent(span);
|
|
60
|
+
const response = await fetch(`${this.host}/capture/`, {
|
|
61
|
+
method: "POST",
|
|
62
|
+
headers: {
|
|
63
|
+
"Content-Type": "application/json",
|
|
64
|
+
},
|
|
65
|
+
body: JSON.stringify(event),
|
|
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 events = spans.map((s) => this.convertToPostHogEvent(s));
|
|
80
|
+
const response = await fetch(`${this.host}/batch/`, {
|
|
81
|
+
method: "POST",
|
|
82
|
+
headers: {
|
|
83
|
+
"Content-Type": "application/json",
|
|
84
|
+
},
|
|
85
|
+
body: JSON.stringify({
|
|
86
|
+
api_key: this.apiKey,
|
|
87
|
+
batch: events.map((e) => ({
|
|
88
|
+
...e,
|
|
89
|
+
// For batch, we don't include api_key in each event
|
|
90
|
+
api_key: undefined,
|
|
91
|
+
})),
|
|
92
|
+
}),
|
|
93
|
+
});
|
|
94
|
+
if (!response.ok) {
|
|
95
|
+
throw new Error(`Batch export failed: ${response.statusText}`);
|
|
96
|
+
}
|
|
97
|
+
return this.createSuccessResult(spans.length, Date.now() - startTime);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
return this.createFailureResult(spans.map((s) => s.spanId), error instanceof Error ? error.message : String(error), Date.now() - startTime);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async flush() {
|
|
104
|
+
if (this.buffer.length > 0) {
|
|
105
|
+
const spans = [...this.buffer];
|
|
106
|
+
this.buffer = [];
|
|
107
|
+
await this.exportBatch(spans);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async shutdown() {
|
|
111
|
+
await this.flush();
|
|
112
|
+
this.stopFlushInterval();
|
|
113
|
+
this.initialized = false;
|
|
114
|
+
}
|
|
115
|
+
async healthCheck() {
|
|
116
|
+
try {
|
|
117
|
+
await this.withRetry(() => this.ping(), "health check");
|
|
118
|
+
return this.createHealthStatus(true);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return this.createHealthStatus(false, ["Health check failed"]);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Verify connectivity to PostHog API
|
|
126
|
+
*/
|
|
127
|
+
async ping() {
|
|
128
|
+
// PostHog doesn't have a dedicated health endpoint, so we use decide endpoint
|
|
129
|
+
const response = await fetch(`${this.host}/decide/?v=3`, {
|
|
130
|
+
method: "POST",
|
|
131
|
+
headers: {
|
|
132
|
+
"Content-Type": "application/json",
|
|
133
|
+
},
|
|
134
|
+
body: JSON.stringify({
|
|
135
|
+
api_key: this.apiKey,
|
|
136
|
+
distinct_id: "health_check",
|
|
137
|
+
}),
|
|
138
|
+
});
|
|
139
|
+
if (!response.ok) {
|
|
140
|
+
throw new Error(`PostHog API unreachable: ${response.status}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Convert span to PostHog event format
|
|
145
|
+
*/
|
|
146
|
+
convertToPostHogEvent(span) {
|
|
147
|
+
// Determine the event name based on span type
|
|
148
|
+
const eventName = this.getEventName(span);
|
|
149
|
+
// Get distinct ID from user.id or session.id, or use trace ID as fallback
|
|
150
|
+
const distinctId = span.attributes["user.id"] ||
|
|
151
|
+
span.attributes["session.id"] ||
|
|
152
|
+
span.traceId;
|
|
153
|
+
return {
|
|
154
|
+
api_key: this.apiKey,
|
|
155
|
+
event: eventName,
|
|
156
|
+
distinct_id: distinctId,
|
|
157
|
+
timestamp: span.startTime,
|
|
158
|
+
properties: {
|
|
159
|
+
// Core span data
|
|
160
|
+
$span_id: span.spanId,
|
|
161
|
+
$trace_id: span.traceId,
|
|
162
|
+
$parent_span_id: span.parentSpanId,
|
|
163
|
+
// AI-specific properties
|
|
164
|
+
ai_provider: span.attributes["ai.provider"],
|
|
165
|
+
ai_model: span.attributes["ai.model"],
|
|
166
|
+
ai_tokens_input: span.attributes["ai.tokens.input"],
|
|
167
|
+
ai_tokens_output: span.attributes["ai.tokens.output"],
|
|
168
|
+
ai_tokens_total: span.attributes["ai.tokens.total"],
|
|
169
|
+
ai_cost_total: span.attributes["ai.cost.total"],
|
|
170
|
+
ai_cost_currency: span.attributes["ai.cost.currency"] || "USD",
|
|
171
|
+
// Generation parameters
|
|
172
|
+
ai_temperature: span.attributes["ai.temperature"],
|
|
173
|
+
ai_max_tokens: span.attributes["ai.max_tokens"],
|
|
174
|
+
// Performance metrics
|
|
175
|
+
duration_ms: span.durationMs,
|
|
176
|
+
status: this.getStatusString(span.status),
|
|
177
|
+
status_message: span.statusMessage,
|
|
178
|
+
// Error tracking
|
|
179
|
+
is_error: span.status === SpanStatus.ERROR,
|
|
180
|
+
error_type: span.attributes["error.type"],
|
|
181
|
+
error_message: span.attributes["error.message"],
|
|
182
|
+
// Tool attributes
|
|
183
|
+
tool_name: span.attributes["tool.name"],
|
|
184
|
+
tool_server: span.attributes["tool.server"],
|
|
185
|
+
tool_success: span.attributes["tool.success"],
|
|
186
|
+
// Environment
|
|
187
|
+
environment: span.attributes["deployment.environment"] || this.config.environment,
|
|
188
|
+
service_name: span.attributes["service.name"],
|
|
189
|
+
service_version: span.attributes["service.version"] || this.config.version,
|
|
190
|
+
// Span type for filtering
|
|
191
|
+
span_type: span.type,
|
|
192
|
+
// Session tracking
|
|
193
|
+
$session_id: span.attributes["session.id"],
|
|
194
|
+
// Custom properties from attributes (filtered)
|
|
195
|
+
...this.extractCustomProperties(span.attributes),
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get event name based on span type
|
|
201
|
+
*/
|
|
202
|
+
getEventName(span) {
|
|
203
|
+
const eventNameMap = {
|
|
204
|
+
[SpanType.AGENT_RUN]: "ai_agent_run",
|
|
205
|
+
[SpanType.WORKFLOW_STEP]: "ai_workflow_step",
|
|
206
|
+
[SpanType.TOOL_CALL]: "ai_tool_call",
|
|
207
|
+
[SpanType.MODEL_GENERATION]: "ai_generation",
|
|
208
|
+
[SpanType.EMBEDDING]: "ai_embedding",
|
|
209
|
+
[SpanType.RETRIEVAL]: "ai_retrieval",
|
|
210
|
+
[SpanType.MEMORY]: "ai_memory_operation",
|
|
211
|
+
[SpanType.CONTEXT_COMPACTION]: "ai_context_compaction",
|
|
212
|
+
[SpanType.RAG]: "ai_rag_operation",
|
|
213
|
+
[SpanType.EVALUATION]: "ai_evaluation",
|
|
214
|
+
[SpanType.MCP_TRANSPORT]: "ai_mcp_transport",
|
|
215
|
+
[SpanType.MEDIA_GENERATION]: "ai_media_generation",
|
|
216
|
+
[SpanType.PPT_GENERATION]: "ai_ppt_generation",
|
|
217
|
+
[SpanType.WORKFLOW]: "ai_workflow",
|
|
218
|
+
[SpanType.TTS]: "ai_tts_synthesis",
|
|
219
|
+
[SpanType.SERVER_REQUEST]: "ai_server_request",
|
|
220
|
+
[SpanType.CUSTOM]: "ai_custom_span",
|
|
221
|
+
};
|
|
222
|
+
return eventNameMap[span.type] || "ai_span";
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Convert span status to string
|
|
226
|
+
*/
|
|
227
|
+
getStatusString(status) {
|
|
228
|
+
switch (status) {
|
|
229
|
+
case SpanStatus.OK:
|
|
230
|
+
return "ok";
|
|
231
|
+
case SpanStatus.ERROR:
|
|
232
|
+
return "error";
|
|
233
|
+
default:
|
|
234
|
+
return "unset";
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Extract custom properties from span attributes
|
|
239
|
+
* Filters out standard attributes that are already handled
|
|
240
|
+
*/
|
|
241
|
+
extractCustomProperties(attributes) {
|
|
242
|
+
const standardKeys = new Set([
|
|
243
|
+
"service.name",
|
|
244
|
+
"service.version",
|
|
245
|
+
"deployment.environment",
|
|
246
|
+
"user.id",
|
|
247
|
+
"session.id",
|
|
248
|
+
"ai.provider",
|
|
249
|
+
"ai.model",
|
|
250
|
+
"ai.model.version",
|
|
251
|
+
"ai.tokens.input",
|
|
252
|
+
"ai.tokens.output",
|
|
253
|
+
"ai.tokens.total",
|
|
254
|
+
"ai.tokens.cache_read",
|
|
255
|
+
"ai.tokens.cache_creation",
|
|
256
|
+
"ai.tokens.reasoning",
|
|
257
|
+
"ai.cost.input",
|
|
258
|
+
"ai.cost.output",
|
|
259
|
+
"ai.cost.total",
|
|
260
|
+
"ai.cost.currency",
|
|
261
|
+
"ai.temperature",
|
|
262
|
+
"ai.max_tokens",
|
|
263
|
+
"ai.top_p",
|
|
264
|
+
"ai.stop_sequences",
|
|
265
|
+
"tool.name",
|
|
266
|
+
"tool.server",
|
|
267
|
+
"tool.success",
|
|
268
|
+
"error.type",
|
|
269
|
+
"error.message",
|
|
270
|
+
"error.stack",
|
|
271
|
+
"error",
|
|
272
|
+
"input",
|
|
273
|
+
"output",
|
|
274
|
+
"expected",
|
|
275
|
+
"scores",
|
|
276
|
+
]);
|
|
277
|
+
const custom = {};
|
|
278
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
279
|
+
if (!standardKeys.has(key) && value !== undefined) {
|
|
280
|
+
// PostHog recommends snake_case for property names
|
|
281
|
+
const snakeCaseKey = key.replace(/\./g, "_").replace(/-/g, "_");
|
|
282
|
+
custom[snakeCaseKey] = value;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return custom;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
//# sourceMappingURL=posthogExporter.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentry Exporter
|
|
3
|
+
* Exports spans to Sentry error tracking and performance platform
|
|
4
|
+
*/
|
|
5
|
+
import type { ExporterHealthStatus, ExportResult, SentryExporterConfig, SpanData } from "../types/index.js";
|
|
6
|
+
import { BaseExporter } from "./baseExporter.js";
|
|
7
|
+
/**
|
|
8
|
+
* Sentry exporter for error tracking and performance monitoring
|
|
9
|
+
* Captures AI errors as exceptions and traces as transactions
|
|
10
|
+
*/
|
|
11
|
+
export declare class SentryExporter extends BaseExporter {
|
|
12
|
+
private readonly dsn;
|
|
13
|
+
private readonly tracesSampleRate;
|
|
14
|
+
private readonly release?;
|
|
15
|
+
private sentryHub;
|
|
16
|
+
constructor(config: SentryExporterConfig);
|
|
17
|
+
initialize(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Load Sentry SDK dynamically as an optional dependency
|
|
20
|
+
* @returns Sentry module or null if not installed
|
|
21
|
+
*/
|
|
22
|
+
private loadSentry;
|
|
23
|
+
exportSpan(span: SpanData): Promise<ExportResult>;
|
|
24
|
+
exportBatch(spans: SpanData[]): Promise<ExportResult>;
|
|
25
|
+
flush(): Promise<void>;
|
|
26
|
+
shutdown(): Promise<void>;
|
|
27
|
+
healthCheck(): Promise<ExporterHealthStatus>;
|
|
28
|
+
/**
|
|
29
|
+
* Verify Sentry SDK is functional
|
|
30
|
+
*/
|
|
31
|
+
protected ping(): Promise<void>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
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
|
+
}
|
|
166
|
+
//# sourceMappingURL=sentryExporter.js.map
|
|
@@ -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,32 @@
|
|
|
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";
|
|
32
|
+
//# sourceMappingURL=index.js.map
|