@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.
Files changed (225) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +10 -13
  3. package/dist/adapters/tts/googleTTSHandler.js +26 -1
  4. package/dist/adapters/video/vertexVideoHandler.js +23 -17
  5. package/dist/cli/commands/config.d.ts +3 -3
  6. package/dist/cli/commands/observability.d.ts +53 -0
  7. package/dist/cli/commands/observability.js +453 -0
  8. package/dist/cli/commands/telemetry.d.ts +63 -0
  9. package/dist/cli/commands/telemetry.js +689 -0
  10. package/dist/cli/factories/commandFactory.d.ts +34 -0
  11. package/dist/cli/factories/commandFactory.js +321 -116
  12. package/dist/cli/parser.js +6 -9
  13. package/dist/cli/utils/formatters.d.ts +13 -0
  14. package/dist/cli/utils/formatters.js +23 -0
  15. package/dist/constants/contextWindows.js +6 -0
  16. package/dist/constants/enums.d.ts +6 -0
  17. package/dist/constants/enums.js +8 -2
  18. package/dist/context/budgetChecker.js +75 -48
  19. package/dist/context/contextCompactor.js +135 -127
  20. package/dist/core/baseProvider.d.ts +5 -0
  21. package/dist/core/baseProvider.js +158 -102
  22. package/dist/core/conversationMemoryInitializer.js +7 -4
  23. package/dist/core/conversationMemoryManager.d.ts +2 -0
  24. package/dist/core/conversationMemoryManager.js +6 -2
  25. package/dist/core/modules/GenerationHandler.d.ts +2 -2
  26. package/dist/core/modules/GenerationHandler.js +12 -12
  27. package/dist/evaluation/ragasEvaluator.js +39 -19
  28. package/dist/evaluation/scoring.js +46 -20
  29. package/dist/features/ppt/index.d.ts +1 -1
  30. package/dist/features/ppt/index.js +1 -1
  31. package/dist/features/ppt/presentationOrchestrator.js +23 -0
  32. package/dist/features/ppt/slideGenerator.js +13 -0
  33. package/dist/features/ppt/slideRenderers.d.ts +1 -1
  34. package/dist/features/ppt/slideRenderers.js +6 -4
  35. package/dist/features/ppt/slideTypeInference.d.ts +1 -1
  36. package/dist/features/ppt/slideTypeInference.js +75 -73
  37. package/dist/files/fileTools.d.ts +6 -6
  38. package/dist/index.d.ts +46 -12
  39. package/dist/index.js +79 -17
  40. package/dist/lib/adapters/tts/googleTTSHandler.js +26 -1
  41. package/dist/lib/adapters/video/vertexVideoHandler.js +23 -17
  42. package/dist/lib/constants/contextWindows.js +6 -0
  43. package/dist/lib/constants/enums.d.ts +6 -0
  44. package/dist/lib/constants/enums.js +8 -2
  45. package/dist/lib/context/budgetChecker.js +75 -48
  46. package/dist/lib/context/contextCompactor.js +135 -127
  47. package/dist/lib/core/baseProvider.d.ts +5 -0
  48. package/dist/lib/core/baseProvider.js +158 -102
  49. package/dist/lib/core/conversationMemoryInitializer.js +7 -4
  50. package/dist/lib/core/conversationMemoryManager.d.ts +2 -0
  51. package/dist/lib/core/conversationMemoryManager.js +6 -2
  52. package/dist/lib/core/modules/GenerationHandler.d.ts +2 -2
  53. package/dist/lib/core/modules/GenerationHandler.js +12 -12
  54. package/dist/lib/evaluation/ragasEvaluator.js +39 -19
  55. package/dist/lib/evaluation/scoring.js +46 -20
  56. package/dist/lib/features/ppt/index.d.ts +1 -1
  57. package/dist/lib/features/ppt/index.js +1 -1
  58. package/dist/lib/features/ppt/presentationOrchestrator.js +23 -0
  59. package/dist/lib/features/ppt/slideGenerator.js +13 -0
  60. package/dist/lib/features/ppt/slideRenderers.d.ts +1 -1
  61. package/dist/lib/features/ppt/slideRenderers.js +6 -4
  62. package/dist/lib/features/ppt/slideTypeInference.d.ts +1 -1
  63. package/dist/lib/features/ppt/slideTypeInference.js +75 -73
  64. package/dist/lib/files/fileTools.d.ts +6 -6
  65. package/dist/lib/index.d.ts +46 -12
  66. package/dist/lib/index.js +79 -17
  67. package/dist/lib/mcp/httpRateLimiter.js +39 -12
  68. package/dist/lib/mcp/httpRetryHandler.js +22 -1
  69. package/dist/lib/mcp/mcpClientFactory.js +13 -15
  70. package/dist/lib/memory/memoryRetrievalTools.js +22 -0
  71. package/dist/lib/neurolink.d.ts +64 -72
  72. package/dist/lib/neurolink.js +984 -566
  73. package/dist/lib/observability/exporterRegistry.d.ts +152 -0
  74. package/dist/lib/observability/exporterRegistry.js +414 -0
  75. package/dist/lib/observability/exporters/arizeExporter.d.ts +32 -0
  76. package/dist/lib/observability/exporters/arizeExporter.js +139 -0
  77. package/dist/lib/observability/exporters/baseExporter.d.ts +117 -0
  78. package/dist/lib/observability/exporters/baseExporter.js +191 -0
  79. package/dist/lib/observability/exporters/braintrustExporter.d.ts +30 -0
  80. package/dist/lib/observability/exporters/braintrustExporter.js +155 -0
  81. package/dist/lib/observability/exporters/datadogExporter.d.ts +37 -0
  82. package/dist/lib/observability/exporters/datadogExporter.js +197 -0
  83. package/dist/lib/observability/exporters/index.d.ts +13 -0
  84. package/dist/lib/observability/exporters/index.js +14 -0
  85. package/dist/lib/observability/exporters/laminarExporter.d.ts +48 -0
  86. package/dist/lib/observability/exporters/laminarExporter.js +303 -0
  87. package/dist/lib/observability/exporters/langfuseExporter.d.ts +47 -0
  88. package/dist/lib/observability/exporters/langfuseExporter.js +200 -0
  89. package/dist/lib/observability/exporters/langsmithExporter.d.ts +26 -0
  90. package/dist/lib/observability/exporters/langsmithExporter.js +124 -0
  91. package/dist/lib/observability/exporters/otelExporter.d.ts +39 -0
  92. package/dist/lib/observability/exporters/otelExporter.js +165 -0
  93. package/dist/lib/observability/exporters/posthogExporter.d.ts +48 -0
  94. package/dist/lib/observability/exporters/posthogExporter.js +288 -0
  95. package/dist/lib/observability/exporters/sentryExporter.d.ts +32 -0
  96. package/dist/lib/observability/exporters/sentryExporter.js +166 -0
  97. package/dist/lib/observability/index.d.ts +25 -0
  98. package/dist/lib/observability/index.js +32 -0
  99. package/dist/lib/observability/metricsAggregator.d.ts +260 -0
  100. package/dist/lib/observability/metricsAggregator.js +553 -0
  101. package/dist/lib/observability/otelBridge.d.ts +49 -0
  102. package/dist/lib/observability/otelBridge.js +132 -0
  103. package/dist/lib/observability/retryPolicy.d.ts +192 -0
  104. package/dist/lib/observability/retryPolicy.js +384 -0
  105. package/dist/lib/observability/sampling/index.d.ts +4 -0
  106. package/dist/lib/observability/sampling/index.js +5 -0
  107. package/dist/lib/observability/sampling/samplers.d.ts +116 -0
  108. package/dist/lib/observability/sampling/samplers.js +217 -0
  109. package/dist/lib/observability/spanProcessor.d.ts +129 -0
  110. package/dist/lib/observability/spanProcessor.js +288 -0
  111. package/dist/lib/observability/tokenTracker.d.ts +156 -0
  112. package/dist/lib/observability/tokenTracker.js +414 -0
  113. package/dist/lib/observability/types/exporterTypes.d.ts +250 -0
  114. package/dist/lib/observability/types/exporterTypes.js +6 -0
  115. package/dist/lib/observability/types/index.d.ts +6 -0
  116. package/dist/lib/observability/types/index.js +5 -0
  117. package/dist/lib/observability/types/spanTypes.d.ts +244 -0
  118. package/dist/lib/observability/types/spanTypes.js +93 -0
  119. package/dist/lib/observability/utils/index.d.ts +4 -0
  120. package/dist/lib/observability/utils/index.js +5 -0
  121. package/dist/lib/observability/utils/spanSerializer.d.ts +115 -0
  122. package/dist/lib/observability/utils/spanSerializer.js +287 -0
  123. package/dist/lib/providers/amazonSagemaker.d.ts +5 -4
  124. package/dist/lib/providers/amazonSagemaker.js +3 -4
  125. package/dist/lib/providers/googleVertex.d.ts +7 -0
  126. package/dist/lib/providers/googleVertex.js +80 -2
  127. package/dist/lib/rag/pipeline/RAGPipeline.d.ts +0 -5
  128. package/dist/lib/rag/pipeline/RAGPipeline.js +122 -87
  129. package/dist/lib/rag/ragIntegration.js +30 -0
  130. package/dist/lib/rag/retrieval/hybridSearch.js +22 -0
  131. package/dist/lib/server/abstract/baseServerAdapter.js +51 -19
  132. package/dist/lib/server/middleware/common.js +44 -12
  133. package/dist/lib/services/server/ai/observability/instrumentation.d.ts +2 -2
  134. package/dist/lib/services/server/ai/observability/instrumentation.js +10 -5
  135. package/dist/lib/types/cli.d.ts +18 -2
  136. package/dist/lib/types/conversationMemoryInterface.d.ts +2 -0
  137. package/dist/lib/types/generateTypes.d.ts +2 -2
  138. package/dist/lib/types/modelTypes.d.ts +18 -18
  139. package/dist/lib/types/providers.d.ts +5 -0
  140. package/dist/lib/utils/pricing.js +25 -1
  141. package/dist/lib/utils/ttsProcessor.js +74 -59
  142. package/dist/lib/workflow/config.d.ts +36 -36
  143. package/dist/lib/workflow/core/ensembleExecutor.js +10 -0
  144. package/dist/lib/workflow/core/judgeScorer.js +20 -2
  145. package/dist/lib/workflow/core/workflowRunner.js +34 -1
  146. package/dist/mcp/httpRateLimiter.js +39 -12
  147. package/dist/mcp/httpRetryHandler.js +22 -1
  148. package/dist/mcp/mcpClientFactory.js +13 -15
  149. package/dist/memory/memoryRetrievalTools.js +22 -0
  150. package/dist/neurolink.d.ts +64 -72
  151. package/dist/neurolink.js +984 -566
  152. package/dist/observability/FEATURE-STATUS.md +269 -0
  153. package/dist/observability/exporterRegistry.d.ts +152 -0
  154. package/dist/observability/exporterRegistry.js +413 -0
  155. package/dist/observability/exporters/arizeExporter.d.ts +32 -0
  156. package/dist/observability/exporters/arizeExporter.js +138 -0
  157. package/dist/observability/exporters/baseExporter.d.ts +117 -0
  158. package/dist/observability/exporters/baseExporter.js +190 -0
  159. package/dist/observability/exporters/braintrustExporter.d.ts +30 -0
  160. package/dist/observability/exporters/braintrustExporter.js +154 -0
  161. package/dist/observability/exporters/datadogExporter.d.ts +37 -0
  162. package/dist/observability/exporters/datadogExporter.js +196 -0
  163. package/dist/observability/exporters/index.d.ts +13 -0
  164. package/dist/observability/exporters/index.js +13 -0
  165. package/dist/observability/exporters/laminarExporter.d.ts +48 -0
  166. package/dist/observability/exporters/laminarExporter.js +302 -0
  167. package/dist/observability/exporters/langfuseExporter.d.ts +47 -0
  168. package/dist/observability/exporters/langfuseExporter.js +199 -0
  169. package/dist/observability/exporters/langsmithExporter.d.ts +26 -0
  170. package/dist/observability/exporters/langsmithExporter.js +123 -0
  171. package/dist/observability/exporters/otelExporter.d.ts +39 -0
  172. package/dist/observability/exporters/otelExporter.js +164 -0
  173. package/dist/observability/exporters/posthogExporter.d.ts +48 -0
  174. package/dist/observability/exporters/posthogExporter.js +287 -0
  175. package/dist/observability/exporters/sentryExporter.d.ts +32 -0
  176. package/dist/observability/exporters/sentryExporter.js +165 -0
  177. package/dist/observability/index.d.ts +25 -0
  178. package/dist/observability/index.js +31 -0
  179. package/dist/observability/metricsAggregator.d.ts +260 -0
  180. package/dist/observability/metricsAggregator.js +552 -0
  181. package/dist/observability/otelBridge.d.ts +49 -0
  182. package/dist/observability/otelBridge.js +131 -0
  183. package/dist/observability/retryPolicy.d.ts +192 -0
  184. package/dist/observability/retryPolicy.js +383 -0
  185. package/dist/observability/sampling/index.d.ts +4 -0
  186. package/dist/observability/sampling/index.js +4 -0
  187. package/dist/observability/sampling/samplers.d.ts +116 -0
  188. package/dist/observability/sampling/samplers.js +216 -0
  189. package/dist/observability/spanProcessor.d.ts +129 -0
  190. package/dist/observability/spanProcessor.js +287 -0
  191. package/dist/observability/tokenTracker.d.ts +156 -0
  192. package/dist/observability/tokenTracker.js +413 -0
  193. package/dist/observability/types/exporterTypes.d.ts +250 -0
  194. package/dist/observability/types/exporterTypes.js +5 -0
  195. package/dist/observability/types/index.d.ts +6 -0
  196. package/dist/observability/types/index.js +4 -0
  197. package/dist/observability/types/spanTypes.d.ts +244 -0
  198. package/dist/observability/types/spanTypes.js +92 -0
  199. package/dist/observability/utils/index.d.ts +4 -0
  200. package/dist/observability/utils/index.js +4 -0
  201. package/dist/observability/utils/spanSerializer.d.ts +115 -0
  202. package/dist/observability/utils/spanSerializer.js +286 -0
  203. package/dist/providers/amazonSagemaker.d.ts +5 -4
  204. package/dist/providers/amazonSagemaker.js +3 -4
  205. package/dist/providers/googleVertex.d.ts +7 -0
  206. package/dist/providers/googleVertex.js +80 -2
  207. package/dist/rag/pipeline/RAGPipeline.d.ts +0 -5
  208. package/dist/rag/pipeline/RAGPipeline.js +122 -87
  209. package/dist/rag/ragIntegration.js +30 -0
  210. package/dist/rag/retrieval/hybridSearch.js +22 -0
  211. package/dist/server/abstract/baseServerAdapter.js +51 -19
  212. package/dist/server/middleware/common.js +44 -12
  213. package/dist/services/server/ai/observability/instrumentation.d.ts +2 -2
  214. package/dist/services/server/ai/observability/instrumentation.js +10 -5
  215. package/dist/types/cli.d.ts +18 -2
  216. package/dist/types/conversationMemoryInterface.d.ts +2 -0
  217. package/dist/types/generateTypes.d.ts +2 -2
  218. package/dist/types/providers.d.ts +5 -0
  219. package/dist/utils/pricing.js +25 -1
  220. package/dist/utils/ttsProcessor.js +74 -59
  221. package/dist/workflow/config.d.ts +52 -52
  222. package/dist/workflow/core/ensembleExecutor.js +10 -0
  223. package/dist/workflow/core/judgeScorer.js +20 -2
  224. package/dist/workflow/core/workflowRunner.js +34 -1
  225. 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;