@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.
Files changed (215) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/adapters/tts/googleTTSHandler.js +26 -1
  3. package/dist/adapters/video/vertexVideoHandler.js +23 -17
  4. package/dist/cli/commands/config.d.ts +3 -3
  5. package/dist/cli/commands/observability.d.ts +53 -0
  6. package/dist/cli/commands/observability.js +453 -0
  7. package/dist/cli/commands/telemetry.d.ts +63 -0
  8. package/dist/cli/commands/telemetry.js +689 -0
  9. package/dist/cli/factories/commandFactory.js +29 -15
  10. package/dist/cli/parser.js +6 -9
  11. package/dist/cli/utils/formatters.d.ts +13 -0
  12. package/dist/cli/utils/formatters.js +23 -0
  13. package/dist/constants/contextWindows.js +6 -0
  14. package/dist/constants/enums.d.ts +6 -0
  15. package/dist/constants/enums.js +8 -2
  16. package/dist/context/budgetChecker.js +75 -48
  17. package/dist/context/contextCompactor.js +135 -127
  18. package/dist/core/baseProvider.d.ts +5 -0
  19. package/dist/core/baseProvider.js +158 -102
  20. package/dist/core/conversationMemoryInitializer.js +7 -4
  21. package/dist/core/conversationMemoryManager.d.ts +2 -0
  22. package/dist/core/conversationMemoryManager.js +6 -2
  23. package/dist/core/modules/GenerationHandler.d.ts +2 -2
  24. package/dist/core/modules/GenerationHandler.js +12 -12
  25. package/dist/evaluation/ragasEvaluator.js +39 -19
  26. package/dist/evaluation/scoring.js +46 -20
  27. package/dist/features/ppt/presentationOrchestrator.js +23 -0
  28. package/dist/features/ppt/slideGenerator.js +13 -0
  29. package/dist/features/ppt/slideRenderers.d.ts +1 -1
  30. package/dist/features/ppt/slideRenderers.js +6 -4
  31. package/dist/features/ppt/slideTypeInference.d.ts +1 -1
  32. package/dist/features/ppt/slideTypeInference.js +75 -73
  33. package/dist/files/fileTools.d.ts +6 -6
  34. package/dist/index.d.ts +46 -12
  35. package/dist/index.js +79 -17
  36. package/dist/lib/adapters/tts/googleTTSHandler.js +26 -1
  37. package/dist/lib/adapters/video/vertexVideoHandler.js +23 -17
  38. package/dist/lib/constants/contextWindows.js +6 -0
  39. package/dist/lib/constants/enums.d.ts +6 -0
  40. package/dist/lib/constants/enums.js +8 -2
  41. package/dist/lib/context/budgetChecker.js +75 -48
  42. package/dist/lib/context/contextCompactor.js +135 -127
  43. package/dist/lib/core/baseProvider.d.ts +5 -0
  44. package/dist/lib/core/baseProvider.js +158 -102
  45. package/dist/lib/core/conversationMemoryInitializer.js +7 -4
  46. package/dist/lib/core/conversationMemoryManager.d.ts +2 -0
  47. package/dist/lib/core/conversationMemoryManager.js +6 -2
  48. package/dist/lib/core/modules/GenerationHandler.d.ts +2 -2
  49. package/dist/lib/core/modules/GenerationHandler.js +12 -12
  50. package/dist/lib/evaluation/ragasEvaluator.js +39 -19
  51. package/dist/lib/evaluation/scoring.js +46 -20
  52. package/dist/lib/features/ppt/presentationOrchestrator.js +23 -0
  53. package/dist/lib/features/ppt/slideGenerator.js +13 -0
  54. package/dist/lib/features/ppt/slideRenderers.d.ts +1 -1
  55. package/dist/lib/features/ppt/slideRenderers.js +6 -4
  56. package/dist/lib/features/ppt/slideTypeInference.d.ts +1 -1
  57. package/dist/lib/features/ppt/slideTypeInference.js +75 -73
  58. package/dist/lib/files/fileTools.d.ts +6 -6
  59. package/dist/lib/index.d.ts +46 -12
  60. package/dist/lib/index.js +79 -17
  61. package/dist/lib/mcp/httpRateLimiter.js +39 -12
  62. package/dist/lib/mcp/httpRetryHandler.js +22 -1
  63. package/dist/lib/mcp/mcpClientFactory.js +13 -15
  64. package/dist/lib/memory/memoryRetrievalTools.js +22 -0
  65. package/dist/lib/neurolink.d.ts +64 -72
  66. package/dist/lib/neurolink.js +984 -566
  67. package/dist/lib/observability/exporterRegistry.d.ts +152 -0
  68. package/dist/lib/observability/exporterRegistry.js +414 -0
  69. package/dist/lib/observability/exporters/arizeExporter.d.ts +32 -0
  70. package/dist/lib/observability/exporters/arizeExporter.js +139 -0
  71. package/dist/lib/observability/exporters/baseExporter.d.ts +117 -0
  72. package/dist/lib/observability/exporters/baseExporter.js +191 -0
  73. package/dist/lib/observability/exporters/braintrustExporter.d.ts +30 -0
  74. package/dist/lib/observability/exporters/braintrustExporter.js +155 -0
  75. package/dist/lib/observability/exporters/datadogExporter.d.ts +37 -0
  76. package/dist/lib/observability/exporters/datadogExporter.js +197 -0
  77. package/dist/lib/observability/exporters/index.d.ts +13 -0
  78. package/dist/lib/observability/exporters/index.js +14 -0
  79. package/dist/lib/observability/exporters/laminarExporter.d.ts +48 -0
  80. package/dist/lib/observability/exporters/laminarExporter.js +303 -0
  81. package/dist/lib/observability/exporters/langfuseExporter.d.ts +47 -0
  82. package/dist/lib/observability/exporters/langfuseExporter.js +200 -0
  83. package/dist/lib/observability/exporters/langsmithExporter.d.ts +26 -0
  84. package/dist/lib/observability/exporters/langsmithExporter.js +124 -0
  85. package/dist/lib/observability/exporters/otelExporter.d.ts +39 -0
  86. package/dist/lib/observability/exporters/otelExporter.js +165 -0
  87. package/dist/lib/observability/exporters/posthogExporter.d.ts +48 -0
  88. package/dist/lib/observability/exporters/posthogExporter.js +288 -0
  89. package/dist/lib/observability/exporters/sentryExporter.d.ts +32 -0
  90. package/dist/lib/observability/exporters/sentryExporter.js +166 -0
  91. package/dist/lib/observability/index.d.ts +25 -0
  92. package/dist/lib/observability/index.js +32 -0
  93. package/dist/lib/observability/metricsAggregator.d.ts +260 -0
  94. package/dist/lib/observability/metricsAggregator.js +553 -0
  95. package/dist/lib/observability/otelBridge.d.ts +49 -0
  96. package/dist/lib/observability/otelBridge.js +132 -0
  97. package/dist/lib/observability/retryPolicy.d.ts +192 -0
  98. package/dist/lib/observability/retryPolicy.js +384 -0
  99. package/dist/lib/observability/sampling/index.d.ts +4 -0
  100. package/dist/lib/observability/sampling/index.js +5 -0
  101. package/dist/lib/observability/sampling/samplers.d.ts +116 -0
  102. package/dist/lib/observability/sampling/samplers.js +217 -0
  103. package/dist/lib/observability/spanProcessor.d.ts +129 -0
  104. package/dist/lib/observability/spanProcessor.js +288 -0
  105. package/dist/lib/observability/tokenTracker.d.ts +156 -0
  106. package/dist/lib/observability/tokenTracker.js +414 -0
  107. package/dist/lib/observability/types/exporterTypes.d.ts +250 -0
  108. package/dist/lib/observability/types/exporterTypes.js +6 -0
  109. package/dist/lib/observability/types/index.d.ts +6 -0
  110. package/dist/lib/observability/types/index.js +5 -0
  111. package/dist/lib/observability/types/spanTypes.d.ts +244 -0
  112. package/dist/lib/observability/types/spanTypes.js +93 -0
  113. package/dist/lib/observability/utils/index.d.ts +4 -0
  114. package/dist/lib/observability/utils/index.js +5 -0
  115. package/dist/lib/observability/utils/spanSerializer.d.ts +115 -0
  116. package/dist/lib/observability/utils/spanSerializer.js +287 -0
  117. package/dist/lib/providers/amazonSagemaker.d.ts +5 -4
  118. package/dist/lib/providers/amazonSagemaker.js +3 -4
  119. package/dist/lib/providers/googleVertex.d.ts +7 -0
  120. package/dist/lib/providers/googleVertex.js +80 -2
  121. package/dist/lib/rag/pipeline/RAGPipeline.d.ts +0 -5
  122. package/dist/lib/rag/pipeline/RAGPipeline.js +122 -87
  123. package/dist/lib/rag/ragIntegration.js +30 -0
  124. package/dist/lib/rag/retrieval/hybridSearch.js +22 -0
  125. package/dist/lib/server/abstract/baseServerAdapter.js +51 -19
  126. package/dist/lib/server/middleware/common.js +44 -12
  127. package/dist/lib/services/server/ai/observability/instrumentation.d.ts +2 -2
  128. package/dist/lib/services/server/ai/observability/instrumentation.js +10 -5
  129. package/dist/lib/types/conversationMemoryInterface.d.ts +2 -0
  130. package/dist/lib/types/modelTypes.d.ts +18 -18
  131. package/dist/lib/types/providers.d.ts +5 -0
  132. package/dist/lib/utils/pricing.js +25 -1
  133. package/dist/lib/utils/ttsProcessor.js +74 -59
  134. package/dist/lib/workflow/config.d.ts +36 -36
  135. package/dist/lib/workflow/core/ensembleExecutor.js +10 -0
  136. package/dist/lib/workflow/core/judgeScorer.js +20 -2
  137. package/dist/lib/workflow/core/workflowRunner.js +34 -1
  138. package/dist/mcp/httpRateLimiter.js +39 -12
  139. package/dist/mcp/httpRetryHandler.js +22 -1
  140. package/dist/mcp/mcpClientFactory.js +13 -15
  141. package/dist/memory/memoryRetrievalTools.js +22 -0
  142. package/dist/neurolink.d.ts +64 -72
  143. package/dist/neurolink.js +984 -566
  144. package/dist/observability/FEATURE-STATUS.md +269 -0
  145. package/dist/observability/exporterRegistry.d.ts +152 -0
  146. package/dist/observability/exporterRegistry.js +413 -0
  147. package/dist/observability/exporters/arizeExporter.d.ts +32 -0
  148. package/dist/observability/exporters/arizeExporter.js +138 -0
  149. package/dist/observability/exporters/baseExporter.d.ts +117 -0
  150. package/dist/observability/exporters/baseExporter.js +190 -0
  151. package/dist/observability/exporters/braintrustExporter.d.ts +30 -0
  152. package/dist/observability/exporters/braintrustExporter.js +154 -0
  153. package/dist/observability/exporters/datadogExporter.d.ts +37 -0
  154. package/dist/observability/exporters/datadogExporter.js +196 -0
  155. package/dist/observability/exporters/index.d.ts +13 -0
  156. package/dist/observability/exporters/index.js +13 -0
  157. package/dist/observability/exporters/laminarExporter.d.ts +48 -0
  158. package/dist/observability/exporters/laminarExporter.js +302 -0
  159. package/dist/observability/exporters/langfuseExporter.d.ts +47 -0
  160. package/dist/observability/exporters/langfuseExporter.js +199 -0
  161. package/dist/observability/exporters/langsmithExporter.d.ts +26 -0
  162. package/dist/observability/exporters/langsmithExporter.js +123 -0
  163. package/dist/observability/exporters/otelExporter.d.ts +39 -0
  164. package/dist/observability/exporters/otelExporter.js +164 -0
  165. package/dist/observability/exporters/posthogExporter.d.ts +48 -0
  166. package/dist/observability/exporters/posthogExporter.js +287 -0
  167. package/dist/observability/exporters/sentryExporter.d.ts +32 -0
  168. package/dist/observability/exporters/sentryExporter.js +165 -0
  169. package/dist/observability/index.d.ts +25 -0
  170. package/dist/observability/index.js +31 -0
  171. package/dist/observability/metricsAggregator.d.ts +260 -0
  172. package/dist/observability/metricsAggregator.js +552 -0
  173. package/dist/observability/otelBridge.d.ts +49 -0
  174. package/dist/observability/otelBridge.js +131 -0
  175. package/dist/observability/retryPolicy.d.ts +192 -0
  176. package/dist/observability/retryPolicy.js +383 -0
  177. package/dist/observability/sampling/index.d.ts +4 -0
  178. package/dist/observability/sampling/index.js +4 -0
  179. package/dist/observability/sampling/samplers.d.ts +116 -0
  180. package/dist/observability/sampling/samplers.js +216 -0
  181. package/dist/observability/spanProcessor.d.ts +129 -0
  182. package/dist/observability/spanProcessor.js +287 -0
  183. package/dist/observability/tokenTracker.d.ts +156 -0
  184. package/dist/observability/tokenTracker.js +413 -0
  185. package/dist/observability/types/exporterTypes.d.ts +250 -0
  186. package/dist/observability/types/exporterTypes.js +5 -0
  187. package/dist/observability/types/index.d.ts +6 -0
  188. package/dist/observability/types/index.js +4 -0
  189. package/dist/observability/types/spanTypes.d.ts +244 -0
  190. package/dist/observability/types/spanTypes.js +92 -0
  191. package/dist/observability/utils/index.d.ts +4 -0
  192. package/dist/observability/utils/index.js +4 -0
  193. package/dist/observability/utils/spanSerializer.d.ts +115 -0
  194. package/dist/observability/utils/spanSerializer.js +286 -0
  195. package/dist/providers/amazonSagemaker.d.ts +5 -4
  196. package/dist/providers/amazonSagemaker.js +3 -4
  197. package/dist/providers/googleVertex.d.ts +7 -0
  198. package/dist/providers/googleVertex.js +80 -2
  199. package/dist/rag/pipeline/RAGPipeline.d.ts +0 -5
  200. package/dist/rag/pipeline/RAGPipeline.js +122 -87
  201. package/dist/rag/ragIntegration.js +30 -0
  202. package/dist/rag/retrieval/hybridSearch.js +22 -0
  203. package/dist/server/abstract/baseServerAdapter.js +51 -19
  204. package/dist/server/middleware/common.js +44 -12
  205. package/dist/services/server/ai/observability/instrumentation.d.ts +2 -2
  206. package/dist/services/server/ai/observability/instrumentation.js +10 -5
  207. package/dist/types/conversationMemoryInterface.d.ts +2 -0
  208. package/dist/types/providers.d.ts +5 -0
  209. package/dist/utils/pricing.js +25 -1
  210. package/dist/utils/ttsProcessor.js +74 -59
  211. package/dist/workflow/config.d.ts +52 -52
  212. package/dist/workflow/core/ensembleExecutor.js +10 -0
  213. package/dist/workflow/core/judgeScorer.js +20 -2
  214. package/dist/workflow/core/workflowRunner.js +34 -1
  215. package/package.json +1 -1
@@ -0,0 +1,269 @@
1
+ # Observability - Status
2
+
3
+ **Completion:** Beta (Stream token counts and memory trace hierarchy pending verification)
4
+ **Last Updated:** March 9, 2026
5
+
6
+ ## Exporters (9/9)
7
+
8
+ - Langfuse
9
+ - LangSmith
10
+ - Datadog
11
+ - Sentry
12
+ - Braintrust
13
+ - Arize
14
+ - PostHog
15
+ - Laminar
16
+ - OTel (OpenTelemetry)
17
+
18
+ ## Core Components
19
+
20
+ | Component | Status | Notes |
21
+ | ------------------ | -------- | ----------------------------------------------------------------------------------------------- |
22
+ | ExporterRegistry | Complete | Circuit breaker protection, multi-exporter support |
23
+ | OtelBridge | Complete | Bidirectional context propagation |
24
+ | TokenTracker | Complete | Multi-provider pricing, custom pricing support |
25
+ | MetricsAggregator | Complete | Full percentile support (p50, p75, p90, p95, p99) |
26
+ | SpanSerializer | Complete | Langfuse, LangSmith, OTel format conversion |
27
+ | Samplers (9 types) | Complete | Always, Never, Ratio, TraceIdRatio, AttributeBased, Priority, ErrorOnly, Composite, Custom |
28
+ | SpanProcessor | Complete | 7 processors: PassThrough, AttributeEnrichment, Filter, Redaction, Truncation, Composite, Batch |
29
+ | RetryPolicy | Complete | 5 policies: Exponential, Linear, Fixed, NoRetry, CircuitBreakerAware + RetryExecutor |
30
+ | CLI Commands | Complete | status, metrics, exporters, costs subcommands |
31
+ | Tests | Complete | 100+ test cases across unit and integration |
32
+
33
+ ## Sampler Types
34
+
35
+ 1. **AlwaysSampler** - Samples 100% of spans
36
+ 2. **NeverSampler** - Samples 0% of spans
37
+ 3. **RatioSampler** - Probabilistic sampling by ratio
38
+ 4. **TraceIdRatioSampler** - Consistent sampling per trace
39
+ 5. **AttributeBasedSampler** - Rule-based sampling with priorities
40
+ 6. **PrioritySampler** - Always sample errors and high-priority span types
41
+ 7. **ErrorOnlySampler** - Only sample error spans
42
+ 8. **CompositeSampler** - Weighted combination of multiple samplers
43
+ 9. **CustomSampler** - User-provided sampling function
44
+
45
+ ## Span Processor Types
46
+
47
+ 1. **PassThroughProcessor** - Passes spans unchanged
48
+ 2. **AttributeEnrichmentProcessor** - Adds static/dynamic attributes
49
+ 3. **FilterProcessor** - Drops spans based on predicates
50
+ 4. **RedactionProcessor** - Removes sensitive data from spans
51
+ 5. **TruncationProcessor** - Truncates large attribute values
52
+ 6. **CompositeProcessor** - Chains multiple processors together
53
+ 7. **BatchProcessor** - Collects spans for batch processing
54
+
55
+ ## Retry Policy Types
56
+
57
+ 1. **ExponentialBackoffPolicy** - Delay increases exponentially (2^n)
58
+ 2. **LinearBackoffPolicy** - Delay increases linearly
59
+ 3. **FixedDelayPolicy** - Same delay for all retries
60
+ 4. **NoRetryPolicy** - Never retries
61
+ 5. **CircuitBreakerAwarePolicy** - Integrates with circuit breaker state
62
+
63
+ ## Architecture
64
+
65
+ ### Span Processing Pipeline
66
+
67
+ ```
68
+ Span Creation → SpanProcessor(s) → Sampler → Exporter(s)
69
+ ↓ ↓
70
+ Enrichment/Filter RetryPolicy + CircuitBreaker
71
+ ```
72
+
73
+ ### Retry Strategy
74
+
75
+ The `BaseExporter` abstract class provides basic retry via `withRetry()`. For advanced scenarios, use the `RetryExecutor` with configurable policies:
76
+
77
+ ```typescript
78
+ import { RetryExecutor, RetryPolicyFactory } from "neurolink/observability";
79
+
80
+ const executor = new RetryExecutor(
81
+ RetryPolicyFactory.createWithCircuitBreaker(),
82
+ );
83
+
84
+ await executor.execute(() => exporter.exportBatch(spans), "export-batch");
85
+ ```
86
+
87
+ ### Span Processing
88
+
89
+ Use `SpanProcessorFactory` for pre-configured pipelines:
90
+
91
+ ```typescript
92
+ import { SpanProcessorFactory } from "neurolink/observability";
93
+
94
+ const pipeline = SpanProcessorFactory.createProductionPipeline({
95
+ serviceName: "my-service",
96
+ environment: "production",
97
+ });
98
+
99
+ const processedSpan = pipeline.process(span);
100
+ ```
101
+
102
+ ## Pattern Compliance
103
+
104
+ **Score:** 100/100
105
+
106
+ ### Compliant Patterns
107
+
108
+ - Factory + Registry pattern (ExporterRegistry)
109
+ - Abstract base class pattern (BaseExporter, BaseRetryPolicy)
110
+ - Singleton pattern (global registry, token tracker, metrics aggregator)
111
+ - Strategy pattern (Sampler interface, RetryPolicy interface, SpanProcessor interface)
112
+ - Builder pattern (SpanSerializer helpers, SpanProcessorFactory)
113
+ - Composite pattern (CompositeProcessor, CompositeSampler)
114
+ - Circuit breaker pattern (ExporterRegistry, CircuitBreakerAwarePolicy)
115
+ - Chain of responsibility pattern (SpanProcessor pipeline)
116
+
117
+ ## Files
118
+
119
+ ```
120
+ src/lib/observability/
121
+ ├── index.ts # Main exports
122
+ ├── exporterRegistry.ts # Multi-exporter management
123
+ ├── otelBridge.ts # OpenTelemetry bridge
124
+ ├── tokenTracker.ts # Token usage and cost tracking
125
+ ├── metricsAggregator.ts # Metrics with percentiles
126
+ ├── spanProcessor.ts # Span processing pipeline (NEW)
127
+ ├── retryPolicy.ts # Configurable retry strategies (NEW)
128
+ ├── FEATURE-STATUS.md # This file
129
+ ├── exporters/
130
+ │ ├── index.ts
131
+ │ ├── baseExporter.ts # Abstract base class
132
+ │ ├── langfuseExporter.ts
133
+ │ ├── langsmithExporter.ts
134
+ │ ├── datadogExporter.ts
135
+ │ ├── sentryExporter.ts
136
+ │ ├── braintrustExporter.ts
137
+ │ ├── arizeExporter.ts
138
+ │ ├── posthogExporter.ts
139
+ │ ├── laminarExporter.ts
140
+ │ └── otelExporter.ts
141
+ ├── sampling/
142
+ │ ├── index.ts
143
+ │ └── samplers.ts # 9 sampler implementations
144
+ ├── types/
145
+ │ ├── index.ts
146
+ │ ├── exporterTypes.ts
147
+ │ └── spanTypes.ts
148
+ └── utils/
149
+ ├── index.ts
150
+ └── spanSerializer.ts
151
+ ```
152
+
153
+ ## CLI Commands
154
+
155
+ ```bash
156
+ # Status overview
157
+ neurolink observability status
158
+
159
+ # Metrics summary
160
+ neurolink observability metrics
161
+ neurolink obs metrics --detailed
162
+
163
+ # List exporters
164
+ neurolink observability exporters
165
+ neurolink obs exp --format json
166
+
167
+ # Cost breakdown
168
+ neurolink observability costs
169
+ neurolink obs costs --by-model --by-provider
170
+ ```
171
+
172
+ ## Usage Example
173
+
174
+ ```typescript
175
+ import {
176
+ ExporterRegistry,
177
+ LangfuseExporter,
178
+ OtelExporter,
179
+ RatioSampler,
180
+ SpanProcessorFactory,
181
+ RetryPolicyFactory,
182
+ RetryExecutor,
183
+ SpanSerializer,
184
+ SpanType,
185
+ } from "neurolink/observability";
186
+
187
+ // Create exporters
188
+ const langfuse = new LangfuseExporter({
189
+ enabled: true,
190
+ publicKey: process.env.LANGFUSE_PUBLIC_KEY!,
191
+ secretKey: process.env.LANGFUSE_SECRET_KEY!,
192
+ });
193
+
194
+ const otel = new OtelExporter({
195
+ enabled: true,
196
+ endpoint: "https://otel-collector.example.com",
197
+ });
198
+
199
+ // Setup registry with sampling
200
+ const registry = new ExporterRegistry();
201
+ registry.register(langfuse);
202
+ registry.register(otel);
203
+ registry.setSampler(new RatioSampler(0.1)); // 10% sampling
204
+
205
+ // Create span processor pipeline
206
+ const processor = SpanProcessorFactory.createProductionPipeline({
207
+ serviceName: "my-ai-service",
208
+ environment: "production",
209
+ });
210
+
211
+ // Create retry executor for resilience
212
+ const retryExecutor = new RetryExecutor(
213
+ RetryPolicyFactory.createWithCircuitBreaker({
214
+ failureThreshold: 5,
215
+ resetTimeoutMs: 30000,
216
+ }),
217
+ );
218
+
219
+ // Initialize
220
+ await registry.initializeAll();
221
+
222
+ // Create and export spans
223
+ const span = SpanSerializer.createGenerationSpan({
224
+ provider: "openai",
225
+ model: "gpt-4o",
226
+ userId: "user-123",
227
+ });
228
+
229
+ // ... perform AI operation ...
230
+
231
+ const endedSpan = SpanSerializer.endSpan(span);
232
+
233
+ // Process span before export
234
+ const processedSpan = processor.process(endedSpan);
235
+
236
+ if (processedSpan) {
237
+ // Export with retry
238
+ await retryExecutor.execute(
239
+ () => registry.exportToAll(processedSpan),
240
+ "export-span",
241
+ );
242
+ }
243
+ ```
244
+
245
+ ## Migration from 91% to 100%
246
+
247
+ ### New Components Added (January 31, 2026)
248
+
249
+ 1. **SpanProcessor** (`spanProcessor.ts`)
250
+ - Fills the SpanProcessor gap identified in pattern compliance
251
+ - 7 processor types for different use cases
252
+ - Factory for production/development pipelines
253
+
254
+ 2. **RetryPolicy** (`retryPolicy.ts`)
255
+ - Addresses "more sophisticated retry policies" gap
256
+ - 5 policy types with full configuration
257
+ - Circuit breaker integration
258
+ - RetryExecutor for easy usage
259
+
260
+ ### Breaking Changes
261
+
262
+ None - all new components are additive.
263
+
264
+ ### Recommended Upgrades
265
+
266
+ For production deployments, consider upgrading to use:
267
+
268
+ 1. `SpanProcessorFactory.createProductionPipeline()` for automatic redaction and enrichment
269
+ 2. `RetryPolicyFactory.createWithCircuitBreaker()` for resilient exports
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Exporter Registry
3
+ * Manages multiple observability exporters with circuit breaker protection
4
+ */
5
+ import type { BaseExporter } from "./exporters/baseExporter.js";
6
+ import type { Sampler } from "./sampling/samplers.js";
7
+ import type { ExporterHealthStatus, ExportResult, SpanData } from "./types/index.js";
8
+ /**
9
+ * Circuit breaker state for an exporter
10
+ */
11
+ type CircuitBreakerState = {
12
+ failures: number;
13
+ lastFailure: number;
14
+ state: "closed" | "open" | "half-open";
15
+ };
16
+ /**
17
+ * Circuit breaker configuration
18
+ */
19
+ type CircuitBreakerConfig = {
20
+ /** Number of failures before opening the circuit */
21
+ failureThreshold: number;
22
+ /** Time in ms to wait before trying half-open state */
23
+ resetTimeout: number;
24
+ };
25
+ /**
26
+ * Registry for managing multiple observability exporters
27
+ * Includes circuit breaker protection to prevent cascading failures
28
+ */
29
+ export declare class ExporterRegistry {
30
+ private exporters;
31
+ private defaultExporter;
32
+ private sampler;
33
+ private circuitBreakers;
34
+ private readonly circuitBreakerConfig;
35
+ /**
36
+ * Register an exporter
37
+ */
38
+ register(exporter: BaseExporter): void;
39
+ /**
40
+ * Unregister an exporter
41
+ */
42
+ unregister(name: string): boolean;
43
+ /**
44
+ * Get an exporter by name
45
+ */
46
+ get(name: string): BaseExporter | undefined;
47
+ /**
48
+ * Get all registered exporter names
49
+ */
50
+ getNames(): string[];
51
+ /**
52
+ * Get total exporter count
53
+ */
54
+ getCount(): number;
55
+ /**
56
+ * Set the default exporter
57
+ */
58
+ setDefault(name: string): void;
59
+ /**
60
+ * Get the default exporter
61
+ */
62
+ getDefault(): BaseExporter | undefined;
63
+ /**
64
+ * Set the sampler for the registry
65
+ */
66
+ setSampler(sampler: Sampler): void;
67
+ /**
68
+ * Get the current sampler
69
+ */
70
+ getSampler(): Sampler;
71
+ /**
72
+ * Configure the circuit breaker settings
73
+ * @param config - Partial circuit breaker configuration
74
+ */
75
+ configureCircuitBreaker(config: Partial<CircuitBreakerConfig>): void;
76
+ /**
77
+ * Check if circuit is open for an exporter
78
+ * @param exporterName - Name of the exporter
79
+ * @returns true if circuit is open (exporter should be skipped)
80
+ */
81
+ private isCircuitOpen;
82
+ /**
83
+ * Record a failure for an exporter's circuit breaker
84
+ * @param exporterName - Name of the exporter
85
+ */
86
+ private recordFailure;
87
+ /**
88
+ * Record a success for an exporter's circuit breaker
89
+ * Resets the circuit to closed state
90
+ * @param exporterName - Name of the exporter
91
+ */
92
+ private recordSuccess;
93
+ /**
94
+ * Get circuit breaker status for an exporter
95
+ * @param exporterName - Name of the exporter
96
+ * @returns Circuit breaker state or undefined if not tracked
97
+ */
98
+ getCircuitBreakerStatus(exporterName: string): CircuitBreakerState | undefined;
99
+ /**
100
+ * Reset circuit breaker for an exporter
101
+ * @param exporterName - Name of the exporter
102
+ */
103
+ resetCircuitBreaker(exporterName: string): void;
104
+ /**
105
+ * Export span to all registered exporters
106
+ * Applies sampling and circuit breaker protection before export
107
+ */
108
+ exportToAll(span: SpanData): Promise<Map<string, ExportResult>>;
109
+ /**
110
+ * Export span to a specific exporter
111
+ * Applies sampling and circuit breaker protection
112
+ */
113
+ exportTo(name: string, span: SpanData): Promise<ExportResult | null>;
114
+ /**
115
+ * Initialize all exporters
116
+ */
117
+ initializeAll(): Promise<void>;
118
+ /**
119
+ * Shutdown all exporters
120
+ */
121
+ shutdownAll(): Promise<void>;
122
+ /**
123
+ * Flush all exporters
124
+ */
125
+ flushAll(): Promise<void>;
126
+ /**
127
+ * Get health status of all exporters
128
+ */
129
+ healthCheckAll(): Promise<Map<string, ExporterHealthStatus>>;
130
+ /**
131
+ * Check if all exporters are healthy
132
+ */
133
+ isHealthy(): Promise<boolean>;
134
+ /**
135
+ * Get total pending spans across all exporters
136
+ */
137
+ getTotalPendingSpans(): number;
138
+ /**
139
+ * Clear all registered exporters and reset state
140
+ * (For testing and cleanup)
141
+ */
142
+ clear(): void;
143
+ }
144
+ /**
145
+ * Get the global exporter registry instance
146
+ */
147
+ export declare function getExporterRegistry(): ExporterRegistry;
148
+ /**
149
+ * Reset the global exporter registry (for testing)
150
+ */
151
+ export declare function resetExporterRegistry(): void;
152
+ export {};