@juspay/neurolink 13.5.0 → 13.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -3
- package/dist/adapters/video/videoAnalyzer.d.ts +1 -0
- package/dist/adapters/video/videoAnalyzer.js +4 -0
- package/dist/autoresearch/index.d.ts +1 -0
- package/dist/autoresearch/index.js +4 -0
- package/dist/autoresearch/worker.js +4 -0
- package/dist/browser/neurolink.min.js +467 -467
- package/dist/cli/commands/observability.js +11 -4
- package/dist/cli/commands/telemetry.js +36 -6
- package/dist/cli/utils/formatters.d.ts +17 -0
- package/dist/cli/utils/formatters.js +39 -0
- package/dist/constants/langfuse.d.ts +17 -1
- package/dist/constants/langfuse.js +23 -1
- package/dist/constants/telemetry.d.ts +6 -0
- package/dist/constants/telemetry.js +6 -0
- package/dist/core/baseProvider.js +2 -0
- package/dist/core/geminiLoopAdapter.js +19 -0
- package/dist/core/loopEngine.js +10 -7
- package/dist/core/modules/StreamHandler.js +5 -4
- package/dist/core/modules/TelemetryHandler.d.ts +5 -1
- package/dist/core/modules/TelemetryHandler.js +16 -0
- package/dist/core/modules/ToolsManager.js +3 -0
- package/dist/core/nativeGenerateLoop.js +1 -1
- package/dist/evaluation/index.d.ts +1 -0
- package/dist/evaluation/index.js +4 -0
- package/dist/evaluation/ragasEvaluator.js +1 -0
- package/dist/mcp/externalServerManager.js +6 -2
- package/dist/mcp/toolRegistry.js +3 -0
- package/dist/neurolink.d.ts +16 -8
- package/dist/neurolink.js +115 -61
- package/dist/observability/FEATURE-STATUS.md +0 -4
- package/dist/observability/exporterRegistry.d.ts +6 -1
- package/dist/observability/exporterRegistry.js +18 -0
- package/dist/observability/exporterSpanProcessor.d.ts +20 -6
- package/dist/observability/exporterSpanProcessor.js +166 -34
- package/dist/observability/exporters/baseExporter.d.ts +22 -3
- package/dist/observability/exporters/baseExporter.js +87 -5
- package/dist/observability/exporters/langfuseExporter.d.ts +29 -3
- package/dist/observability/exporters/langfuseExporter.js +251 -41
- package/dist/observability/langfuseMasking.d.ts +1 -1
- package/dist/observability/langfuseMasking.js +1 -1
- package/dist/observability/otlpEncoding.d.ts +18 -5
- package/dist/observability/otlpEncoding.js +69 -12
- package/dist/observability/utils/spanSerializer.d.ts +3 -2
- package/dist/observability/utils/spanSerializer.js +5 -3
- package/dist/processors/base/BaseFileProcessor.d.ts +1 -0
- package/dist/processors/base/BaseFileProcessor.js +4 -0
- package/dist/processors/index.d.ts +1 -0
- package/dist/processors/index.js +4 -0
- package/dist/processors/registry/ProcessorRegistry.d.ts +1 -0
- package/dist/processors/registry/ProcessorRegistry.js +5 -0
- package/dist/providers/amazonBedrock/client.js +7 -5
- package/dist/providers/amazonSagemaker.js +32 -12
- package/dist/providers/anthropic/client.js +1 -0
- package/dist/providers/anthropic/loopAdapter.js +7 -3
- package/dist/providers/googleAiStudio/client.js +2 -0
- package/dist/providers/googleVertex/client.d.ts +6 -5
- package/dist/providers/googleVertex/client.js +46 -19
- package/dist/providers/openaiChatCompletionsBase.js +4 -4
- package/dist/proxy/codexUsage.js +59 -2
- package/dist/proxy/proxyTracer.d.ts +25 -1
- package/dist/proxy/proxyTracer.js +146 -22
- package/dist/proxy/proxyTranslationEngine.js +4 -2
- package/dist/proxy/sseInterceptor.js +6 -4
- package/dist/rag/chunkers/BaseChunker.js +1 -0
- package/dist/rag/index.d.ts +1 -0
- package/dist/rag/index.js +4 -0
- package/dist/rag/ragIntegration.js +1 -0
- package/dist/rag/reranker/reranker.js +2 -0
- package/dist/rag/retrieval/vectorQueryTool.js +1 -0
- package/dist/server/routes/codexProxyRoutes.js +3 -1
- package/dist/server/utils/validation.d.ts +3 -3
- package/dist/services/server/ai/observability/instrumentation.d.ts +8 -7
- package/dist/services/server/ai/observability/instrumentation.js +217 -47
- package/dist/services/server/ai/observability/langfuseSetup.d.ts +19 -1
- package/dist/services/server/ai/observability/langfuseSetup.js +62 -4
- package/dist/services/server/ai/observability/otlpSetup.d.ts +12 -2
- package/dist/services/server/ai/observability/otlpSetup.js +55 -4
- package/dist/telemetry/aiMetrics.d.ts +56 -0
- package/dist/telemetry/aiMetrics.js +229 -0
- package/dist/telemetry/attributes.d.ts +24 -1
- package/dist/telemetry/attributes.js +94 -9
- package/dist/telemetry/chatMessages.d.ts +6 -0
- package/dist/telemetry/chatMessages.js +37 -0
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/telemetry/index.js +1 -1
- package/dist/telemetry/observation.d.ts +5 -5
- package/dist/telemetry/observation.js +128 -39
- package/dist/telemetry/spanSanitizer.d.ts +2 -2
- package/dist/telemetry/spanSanitizer.js +76 -8
- package/dist/telemetry/telemetryStarter.d.ts +16 -0
- package/dist/telemetry/telemetryStarter.js +28 -0
- package/dist/telemetry/traceContext.d.ts +3 -3
- package/dist/telemetry/traceContext.js +3 -3
- package/dist/telemetry/tracers.d.ts +13 -1
- package/dist/telemetry/tracers.js +49 -10
- package/dist/telemetry/withSpan.d.ts +19 -3
- package/dist/telemetry/withSpan.js +149 -20
- package/dist/types/exporter.d.ts +98 -3
- package/dist/types/livekit.d.ts +16 -1
- package/dist/types/loopEngine.d.ts +16 -1
- package/dist/types/observability.d.ts +38 -5
- package/dist/types/proxy.d.ts +2 -0
- package/dist/types/span.d.ts +26 -0
- package/dist/utils/timeout.js +4 -2
- package/dist/voice/livekit/realtimeMcpTools.js +11 -2
- package/dist/voice/livekit/realtimeMemory.d.ts +20 -2
- package/dist/voice/livekit/realtimeMemory.js +139 -46
- package/dist/voice/livekit/realtimeVoiceAgent.js +20 -8
- package/dist/voice/livekit/turnRecorder.js +22 -9
- package/dist/workflow/core/ensembleExecutor.js +2 -0
- package/dist/workflow/core/judgeScorer.js +1 -0
- package/dist/workflow/core/responseConditioner.js +1 -0
- package/dist/workflow/core/workflowRunner.js +6 -1
- package/dist/workflow/index.d.ts +1 -0
- package/dist/workflow/index.js +4 -0
- package/docs-site/static/search-index.json +32 -27
- package/package.json +21 -2
package/dist/neurolink.js
CHANGED
|
@@ -71,8 +71,9 @@ import { getMetricsAggregator, MetricsAggregator, } from "./observability/metric
|
|
|
71
71
|
import { AnalyticsService, calculateAdvancedCost, parseAnalyticsQualityScore, } from "./analytics/index.js";
|
|
72
72
|
import { SpanStatus, SpanType, CircuitBreakerOpenError, ConversationMemoryError, DEFAULT_DECISION_HOOK_TIMEOUT_MS, MAX_DECISION_HOOK_TIMEOUT_MS, ModelAccessDeniedError, } from "./types/index.js";
|
|
73
73
|
import { resolveTerminalAgentMode } from "./agent/prompts/terminalAgentPrompt.js";
|
|
74
|
+
import { getExporterRegistry } from "./observability/exporterRegistry.js";
|
|
74
75
|
import { SpanSerializer } from "./observability/utils/spanSerializer.js";
|
|
75
|
-
import { withSpan } from "./telemetry/withSpan.js";
|
|
76
|
+
import { endSpanWhenDropped, withSpan } from "./telemetry/withSpan.js";
|
|
76
77
|
import { getActiveTraceContext } from "./telemetry/traceContext.js";
|
|
77
78
|
import { calculateCost } from "./utils/pricing.js";
|
|
78
79
|
import { acquireTelemetry, ensureTelemetry, flushOpenTelemetry, getLangfuseHealthStatus, isOpenTelemetryInitialized, releaseTelemetry, setLangfuseContext, traceMetadataFromContext, } from "./services/server/ai/observability/instrumentation.js";
|
|
@@ -410,6 +411,9 @@ function observeTurn(span, attrs) {
|
|
|
410
411
|
}
|
|
411
412
|
}
|
|
412
413
|
function startTurn(span, optionsOrPrompt) {
|
|
414
|
+
if (!span.isRecording()) {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
413
417
|
observeTurn(span, { input: turnInput(optionsOrPrompt) });
|
|
414
418
|
if (typeof optionsOrPrompt !== "string") {
|
|
415
419
|
const name = optionsOrPrompt.context?.observationName;
|
|
@@ -474,65 +478,87 @@ function traceTurnStream(result, span, turnContext) {
|
|
|
474
478
|
: "stream closed before first chunk");
|
|
475
479
|
}
|
|
476
480
|
};
|
|
481
|
+
const advance = async (pull, afterThrow = false) => {
|
|
482
|
+
started = true;
|
|
483
|
+
try {
|
|
484
|
+
const step = await context.with(turnContext, pull);
|
|
485
|
+
if (step.done) {
|
|
486
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
487
|
+
end(observationLevel(result.finishReason));
|
|
488
|
+
return { done: true, value: undefined };
|
|
489
|
+
}
|
|
490
|
+
const content = typeof step.value === "object" && step.value !== null
|
|
491
|
+
? step.value.content
|
|
492
|
+
: undefined;
|
|
493
|
+
if (typeof content === "string") {
|
|
494
|
+
output += content;
|
|
495
|
+
}
|
|
496
|
+
return step;
|
|
497
|
+
}
|
|
498
|
+
catch (error) {
|
|
499
|
+
failTurnSpan(span, error instanceof Error ? error : new Error(String(error)));
|
|
500
|
+
// A consumer that throws into the stream ends it early, as return()
|
|
501
|
+
// does, and the root has always kept the model in that case.
|
|
502
|
+
if (afterThrow) {
|
|
503
|
+
observeTurn(span, { metadata: { model: result.model } });
|
|
504
|
+
}
|
|
505
|
+
finish();
|
|
506
|
+
throw error;
|
|
507
|
+
}
|
|
508
|
+
};
|
|
477
509
|
const traced = {
|
|
478
510
|
async next() {
|
|
479
511
|
if (ended) {
|
|
480
512
|
return { done: true, value: undefined };
|
|
481
513
|
}
|
|
482
|
-
|
|
483
|
-
try {
|
|
484
|
-
const step = await context.with(turnContext, () => iterator.next());
|
|
485
|
-
if (step.done) {
|
|
486
|
-
span.setStatus({ code: SpanStatusCode.OK });
|
|
487
|
-
end(observationLevel(result.finishReason));
|
|
488
|
-
return { done: true, value: undefined };
|
|
489
|
-
}
|
|
490
|
-
const content = typeof step.value === "object" && step.value !== null
|
|
491
|
-
? step.value.content
|
|
492
|
-
: undefined;
|
|
493
|
-
if (typeof content === "string") {
|
|
494
|
-
output += content;
|
|
495
|
-
}
|
|
496
|
-
return step;
|
|
497
|
-
}
|
|
498
|
-
catch (error) {
|
|
499
|
-
failTurnSpan(span, error instanceof Error ? error : new Error(String(error)));
|
|
500
|
-
finish();
|
|
501
|
-
throw error;
|
|
502
|
-
}
|
|
514
|
+
return advance(() => iterator.next());
|
|
503
515
|
},
|
|
504
516
|
async return() {
|
|
505
517
|
await close();
|
|
506
518
|
return { done: true, value: undefined };
|
|
507
519
|
},
|
|
508
520
|
async throw(error) {
|
|
509
|
-
|
|
510
|
-
|
|
521
|
+
const forward = iterator.throw;
|
|
522
|
+
if (ended || forward === undefined) {
|
|
523
|
+
await close();
|
|
524
|
+
throw error;
|
|
525
|
+
}
|
|
526
|
+
return advance(() => forward.call(iterator, error), true);
|
|
511
527
|
},
|
|
512
528
|
[Symbol.asyncIterator]() {
|
|
513
529
|
return traced;
|
|
514
530
|
},
|
|
515
531
|
};
|
|
532
|
+
endSpanWhenDropped(traced, span);
|
|
516
533
|
return traced;
|
|
517
534
|
}
|
|
535
|
+
/**
|
|
536
|
+
* Runs every pull of `stream` inside `drainContext`, and forwards `return()`
|
|
537
|
+
* and `throw()` to it even before the first `next()`. A generator that has not
|
|
538
|
+
* started never enters its body, so wrapping the drain in one would swallow a
|
|
539
|
+
* pre-start close and leave the drain's own settle step unreached.
|
|
540
|
+
*/
|
|
518
541
|
function drainInContext(stream, drainContext) {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
542
|
+
const iterator = stream[Symbol.asyncIterator]();
|
|
543
|
+
const drained = {
|
|
544
|
+
next: () => context.with(drainContext, () => iterator.next()),
|
|
545
|
+
async return() {
|
|
546
|
+
await context.with(drainContext, async () => iterator.return?.());
|
|
547
|
+
return { done: true, value: undefined };
|
|
548
|
+
},
|
|
549
|
+
async throw(error) {
|
|
550
|
+
const forward = iterator.throw;
|
|
551
|
+
if (forward === undefined) {
|
|
552
|
+
await context.with(drainContext, async () => iterator.return?.());
|
|
553
|
+
throw error;
|
|
528
554
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
555
|
+
return context.with(drainContext, () => forward.call(iterator, error));
|
|
556
|
+
},
|
|
557
|
+
[Symbol.asyncIterator]() {
|
|
558
|
+
return drained;
|
|
559
|
+
},
|
|
560
|
+
};
|
|
561
|
+
return drained;
|
|
536
562
|
}
|
|
537
563
|
/** Monotonic source for {@link NeuroLink.logInstanceId}. Process-local by design. */
|
|
538
564
|
let neuroLinkInstanceCounter = 0;
|
|
@@ -834,8 +860,8 @@ export class NeuroLink {
|
|
|
834
860
|
}, callback);
|
|
835
861
|
}
|
|
836
862
|
createMetricsTraceContext() {
|
|
837
|
-
//
|
|
838
|
-
//
|
|
863
|
+
// Reuse the active OTel trace context so the in-process span records
|
|
864
|
+
// carry the traceId of the exported OTEL trace of the same request.
|
|
839
865
|
const activeSpan = trace.getSpan(context.active());
|
|
840
866
|
if (activeSpan) {
|
|
841
867
|
const spanCtx = activeSpan.spanContext();
|
|
@@ -3168,11 +3194,15 @@ Current user's request: ${currentInput}`;
|
|
|
3168
3194
|
}
|
|
3169
3195
|
/**
|
|
3170
3196
|
* Get comprehensive telemetry status including Langfuse and OpenTelemetry state
|
|
3197
|
+
* and every registered exporter with its queued, delivered and dropped spans.
|
|
3198
|
+
* `openTelemetry.enabled` is whether tracing is initialized, as it always
|
|
3199
|
+
* was. Beside a host TracerProvider, `openTelemetry.usingExternalProvider`
|
|
3200
|
+
* is `true`: NeuroLink exports nothing to the endpoint.
|
|
3171
3201
|
*/
|
|
3172
3202
|
getTelemetryStatus() {
|
|
3173
3203
|
const langfuseConfig = this.observabilityConfig?.langfuse;
|
|
3174
3204
|
const langfuseOptions = typeof langfuseConfig === "object" ? langfuseConfig : undefined;
|
|
3175
|
-
const { hasProcessor } = getLangfuseHealthStatus();
|
|
3205
|
+
const { hasProcessor, usingExternalProvider } = getLangfuseHealthStatus();
|
|
3176
3206
|
return {
|
|
3177
3207
|
enabled: isOpenTelemetryInitialized(),
|
|
3178
3208
|
langfuse: langfuseConfig !== undefined || hasProcessor
|
|
@@ -3188,8 +3218,10 @@ Current user's request: ${currentInput}`;
|
|
|
3188
3218
|
enabled: isOpenTelemetryInitialized(),
|
|
3189
3219
|
endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
|
|
3190
3220
|
serviceName: process.env.OTEL_SERVICE_NAME,
|
|
3221
|
+
...(usingExternalProvider && { usingExternalProvider }),
|
|
3191
3222
|
}
|
|
3192
3223
|
: undefined,
|
|
3224
|
+
exporters: getExporterRegistry().getStatuses(),
|
|
3193
3225
|
};
|
|
3194
3226
|
}
|
|
3195
3227
|
/**
|
|
@@ -7435,8 +7467,12 @@ Current user's request: ${currentInput}`;
|
|
|
7435
7467
|
return { done: true, value: undefined };
|
|
7436
7468
|
},
|
|
7437
7469
|
async throw(error) {
|
|
7438
|
-
|
|
7439
|
-
|
|
7470
|
+
const forward = iterator.throw;
|
|
7471
|
+
if (forward === undefined) {
|
|
7472
|
+
await scope.run(eventScope, async () => iterator.return?.());
|
|
7473
|
+
throw error;
|
|
7474
|
+
}
|
|
7475
|
+
return scope.run(eventScope, () => forward.call(iterator, error));
|
|
7440
7476
|
},
|
|
7441
7477
|
[Symbol.asyncIterator]() {
|
|
7442
7478
|
return bound;
|
|
@@ -7805,6 +7841,7 @@ Current user's request: ${currentInput}`;
|
|
|
7805
7841
|
},
|
|
7806
7842
|
});
|
|
7807
7843
|
attempt.stream = drainInContext(attempt.stream, context.active());
|
|
7844
|
+
endSpanWhenDropped(attempt.stream, streamSpan);
|
|
7808
7845
|
return attempt;
|
|
7809
7846
|
}));
|
|
7810
7847
|
if (streamSttTranscription) {
|
|
@@ -8615,7 +8652,18 @@ Current user's request: ${currentInput}`;
|
|
|
8615
8652
|
}
|
|
8616
8653
|
return stream.return(value);
|
|
8617
8654
|
},
|
|
8618
|
-
throw: (error) =>
|
|
8655
|
+
throw: async (error) => {
|
|
8656
|
+
if (!started) {
|
|
8657
|
+
started = true;
|
|
8658
|
+
await this.settleStandardStreamDrain(drain, {
|
|
8659
|
+
accumulatedContent: "",
|
|
8660
|
+
chunkCount: 0,
|
|
8661
|
+
streamError: error instanceof Error ? error : new Error(String(error)),
|
|
8662
|
+
resolvedUsage: undefined,
|
|
8663
|
+
});
|
|
8664
|
+
}
|
|
8665
|
+
return stream.throw(error);
|
|
8666
|
+
},
|
|
8619
8667
|
[Symbol.asyncIterator]: () => guarded,
|
|
8620
8668
|
};
|
|
8621
8669
|
return guarded;
|
|
@@ -14066,13 +14114,15 @@ Current user's request: ${currentInput}`;
|
|
|
14066
14114
|
* on the wire can differ from the instance's.
|
|
14067
14115
|
*
|
|
14068
14116
|
* Fail-open by construction, in three layers. Without a decision provider
|
|
14069
|
-
*
|
|
14070
|
-
*
|
|
14071
|
-
*
|
|
14072
|
-
*
|
|
14073
|
-
*
|
|
14074
|
-
*
|
|
14075
|
-
*
|
|
14117
|
+
* no hook runs and no event is emitted: the call goes to `tryRunDecide`
|
|
14118
|
+
* alone, which records the WARNING `decide` observation it always did, and
|
|
14119
|
+
* the consumer gets the null it always got. Everything a host can reach
|
|
14120
|
+
* (its hook's return value, the event payloads, the answer split,
|
|
14121
|
+
* `onAnswers`) runs inside one `try`; whatever a host throws, the consumer
|
|
14122
|
+
* gets what `tryRunDecide` alone would have given it. And every
|
|
14123
|
+
* host-facing value is a `structuredClone`, so a hook or listener that
|
|
14124
|
+
* edits what it is handed edits neither the wire request nor the
|
|
14125
|
+
* consumer's own question objects.
|
|
14076
14126
|
*
|
|
14077
14127
|
* `outer` is what the surrounding `generate()` / `stream()` supplies —
|
|
14078
14128
|
* per-call credentials, abort signal, ids — and wins over the same fields
|
|
@@ -14094,9 +14144,10 @@ Current user's request: ${currentInput}`;
|
|
|
14094
14144
|
if (!site) {
|
|
14095
14145
|
return this.tryRunDecide(merged);
|
|
14096
14146
|
}
|
|
14097
|
-
//
|
|
14098
|
-
// request path of a tenant that has no decision model to reach, and
|
|
14099
|
-
// event for a call that could never be made would only mislead.
|
|
14147
|
+
// No host hook or event without a decision provider: a hook must not sit
|
|
14148
|
+
// on the request path of a tenant that has no decision model to reach, and
|
|
14149
|
+
// an event for a call that could never be made would only mislead. The
|
|
14150
|
+
// plain call still runs, so the WARNING observation it records is kept.
|
|
14100
14151
|
if (!this.resolveDecisionProviderName(merged.provider, merged.credentials)) {
|
|
14101
14152
|
return this.tryRunDecide(merged);
|
|
14102
14153
|
}
|
|
@@ -14419,11 +14470,14 @@ Current user's request: ${currentInput}`;
|
|
|
14419
14470
|
? { "decision.upstream_ms": result.upstreamMs }
|
|
14420
14471
|
: {}),
|
|
14421
14472
|
});
|
|
14422
|
-
// BOTH aggregators, exactly as the generate path does.
|
|
14423
|
-
//
|
|
14424
|
-
//
|
|
14425
|
-
//
|
|
14426
|
-
//
|
|
14473
|
+
// BOTH aggregators, exactly as the generate path does. They are
|
|
14474
|
+
// in-process stores that are never exported: what Langfuse and the
|
|
14475
|
+
// OTLP exporters receive for this decision is the `decide`
|
|
14476
|
+
// generation span. The instance one is what
|
|
14477
|
+
// `neurolink.getMetrics()` / `getSpans()` read; the global one is
|
|
14478
|
+
// what `getMetricsAggregator()` readers see. Recording to only the
|
|
14479
|
+
// global one would make a decision invisible to the very API a
|
|
14480
|
+
// caller would use to check whether it ran.
|
|
14427
14481
|
const ended = SpanSerializer.endSpan(span, SpanStatus.OK);
|
|
14428
14482
|
this.metricsAggregator.recordSpan(ended);
|
|
14429
14483
|
getMetricsAggregator().recordSpan(ended);
|
|
@@ -160,10 +160,6 @@ neurolink observability status
|
|
|
160
160
|
neurolink observability metrics
|
|
161
161
|
neurolink obs metrics --detailed
|
|
162
162
|
|
|
163
|
-
# List exporters
|
|
164
|
-
neurolink observability exporters
|
|
165
|
-
neurolink obs exp --format json
|
|
166
|
-
|
|
167
163
|
# Cost breakdown
|
|
168
164
|
neurolink observability costs
|
|
169
165
|
neurolink obs costs --by-model --by-provider
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Manages multiple observability exporters with circuit breaker protection
|
|
4
4
|
*/
|
|
5
5
|
import type { BaseExporter } from "./exporters/baseExporter.js";
|
|
6
|
-
import type { ExportResult, ExporterHealthStatus, ObservabilityCircuitBreakerConfig, ObservabilityCircuitBreakerState, Sampler, SpanData } from "../types/index.js";
|
|
6
|
+
import type { ExportResult, ExporterHealthStatus, ExporterStatus, ObservabilityCircuitBreakerConfig, ObservabilityCircuitBreakerState, Sampler, SpanData } from "../types/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Registry for managing multiple observability exporters
|
|
9
9
|
* Includes circuit breaker protection to prevent cascading failures
|
|
@@ -117,6 +117,11 @@ export declare class ExporterRegistry {
|
|
|
117
117
|
* Get total pending spans across all exporters
|
|
118
118
|
*/
|
|
119
119
|
getTotalPendingSpans(): number;
|
|
120
|
+
/**
|
|
121
|
+
* Snapshot of every registered exporter without a network call: whether it
|
|
122
|
+
* runs, what is queued, delivered and dropped, and an open circuit breaker
|
|
123
|
+
*/
|
|
124
|
+
getStatuses(): ExporterStatus[];
|
|
120
125
|
/**
|
|
121
126
|
* Clear all registered exporters and reset state
|
|
122
127
|
* (For testing and cleanup)
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Manages multiple observability exporters with circuit breaker protection
|
|
4
4
|
*/
|
|
5
5
|
import { logger } from "../utils/logger.js";
|
|
6
|
+
import { exporterStatusOf } from "./exporters/baseExporter.js";
|
|
6
7
|
import { AlwaysSampler } from "./sampling/samplers.js";
|
|
7
8
|
/** Default timeout for exporter API calls (30 seconds) */
|
|
8
9
|
const DEFAULT_EXPORT_TIMEOUT_MS = 30_000;
|
|
@@ -378,6 +379,23 @@ export class ExporterRegistry {
|
|
|
378
379
|
}
|
|
379
380
|
return total;
|
|
380
381
|
}
|
|
382
|
+
/**
|
|
383
|
+
* Snapshot of every registered exporter without a network call: whether it
|
|
384
|
+
* runs, what is queued, delivered and dropped, and an open circuit breaker
|
|
385
|
+
*/
|
|
386
|
+
getStatuses() {
|
|
387
|
+
return Array.from(this.exporters.entries()).map(([name, exporter]) => {
|
|
388
|
+
const status = exporterStatusOf(exporter);
|
|
389
|
+
if (this.circuitBreakers.get(name)?.state !== "open") {
|
|
390
|
+
return status;
|
|
391
|
+
}
|
|
392
|
+
return {
|
|
393
|
+
...status,
|
|
394
|
+
healthy: false,
|
|
395
|
+
errors: [...(status.errors ?? []), "Circuit breaker open"],
|
|
396
|
+
};
|
|
397
|
+
});
|
|
398
|
+
}
|
|
381
399
|
/**
|
|
382
400
|
* Clear all registered exporters and reset state
|
|
383
401
|
* (For testing and cleanup)
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { type Context } from "@opentelemetry/api";
|
|
2
2
|
import type { ReadableSpan, Span, SpanProcessor as OtelSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
3
|
+
import type { ExporterSpanProcessorOptions } from "../types/index.js";
|
|
3
4
|
import type { ExporterRegistry } from "./exporterRegistry.js";
|
|
4
5
|
/**
|
|
5
|
-
* @description OpenTelemetry span processor that turns every observation span into `SpanData` and hands it to an `ExporterRegistry`, so one instrumentation feeds Langfuse, Datadog, Sentry and every other registered exporter. Spans that are not observations are skipped and their children are re-parented onto the nearest exported ancestor. Delivery never blocks the span's thread.
|
|
6
|
+
* @description OpenTelemetry span processor that turns every observation span into `SpanData` and hands it to an `ExporterRegistry`, so one instrumentation feeds Langfuse, Datadog, Sentry and every other registered exporter. Spans that are not observations (health checks, auth, middleware, NeuroLink's helper spans), wrapper spans marked `langfuse.internal` and spans from other libraries are skipped and their children are re-parented onto the nearest exported ancestor. `shutdown()` shuts the registry's exporters down, as it always did, unless the processor was created to leave them running. Parent ids are read from OpenTelemetry SDK 2.x (`parentSpanContext`) and 1.x (`parentSpanId`) spans alike. At most `MAX_REMEMBERED_SPANS` open and ended spans are remembered for re-parenting; an ancestor of a span that is still open is kept past that limit. Delivery never blocks the span's thread, and a span that cannot be converted is skipped without throwing into the code that ended it.
|
|
6
7
|
*/
|
|
7
8
|
export declare class ExporterSpanProcessor implements OtelSpanProcessor {
|
|
8
9
|
private readonly registry;
|
|
10
|
+
private readonly shutsDownExporters;
|
|
9
11
|
private readonly open;
|
|
10
12
|
private readonly ended;
|
|
13
|
+
private readonly pins;
|
|
14
|
+
private evictionLogged;
|
|
11
15
|
/**
|
|
12
16
|
* @description Creates a processor bound to a registry.
|
|
13
17
|
* @param registry {ExporterRegistry} - Registry that receives every exported span.
|
|
18
|
+
* @param shutsDownExporters {boolean} - Whether `shutdown()` also shuts down the registry's exporters; defaults to `true`. Pass `false` for a host provider that is shut down and rebuilt while the exporters stay shared.
|
|
14
19
|
*/
|
|
15
|
-
constructor(registry: ExporterRegistry);
|
|
20
|
+
constructor(registry: ExporterRegistry, shutsDownExporters?: boolean);
|
|
16
21
|
/**
|
|
17
22
|
* @description Copies the propagated Langfuse trace attributes (user, session, trace name, tags, metadata) from the parent context onto the new span and remembers it until it ends.
|
|
18
23
|
* @param span {Span} - Span that just started.
|
|
@@ -32,19 +37,28 @@ export declare class ExporterSpanProcessor implements OtelSpanProcessor {
|
|
|
32
37
|
*/
|
|
33
38
|
forceFlush(): Promise<void>;
|
|
34
39
|
/**
|
|
35
|
-
* @description Shuts down every exporter in the registry.
|
|
36
|
-
* @returns {Promise<void>} Resolves when
|
|
40
|
+
* @description Shuts down every exporter in the registry, or only flushes them when the processor was created to leave them running.
|
|
41
|
+
* @returns {Promise<void>} Resolves when the exporters have shut down or flushed.
|
|
37
42
|
*/
|
|
38
43
|
shutdown(): Promise<void>;
|
|
44
|
+
private contain;
|
|
39
45
|
private exportQuietly;
|
|
46
|
+
private hold;
|
|
47
|
+
private release;
|
|
48
|
+
private evictOldestOpen;
|
|
40
49
|
private remember;
|
|
50
|
+
private trimEnded;
|
|
41
51
|
private nearestExportedAncestor;
|
|
42
52
|
}
|
|
43
53
|
/**
|
|
44
|
-
* @description Creates a span processor that feeds NeuroLink's observation spans to an exporter registry. Add it to a host `TracerProvider` to deliver spans through the registered exporters (such as `LangfuseExporter`) instead of `LangfuseSpanProcessor`.
|
|
54
|
+
* @description Creates a span processor that feeds NeuroLink's observation spans to an exporter registry. Add it to a host `TracerProvider` to deliver spans through the registered exporters (such as `LangfuseExporter`) instead of `LangfuseSpanProcessor`. Shutting that provider down shuts the registry's exporters down; pass `{ shutdownExporters: false }` to flush them and leave them running, so a provider the host rebuilds keeps exporting.
|
|
45
55
|
* @param registry {ExporterRegistry} - Registry to export to; defaults to the process-wide registry.
|
|
56
|
+
* @param options {ExporterSpanProcessorOptions} - `shutdownExporters` (default `true`) says whether the processor's `shutdown()` also shuts down the registry's exporters.
|
|
46
57
|
* @returns {ExporterSpanProcessor} A processor ready to be added to a TracerProvider.
|
|
47
58
|
* @example
|
|
48
59
|
* const provider = new NodeTracerProvider({ spanProcessors: [createExporterSpanProcessor()] });
|
|
60
|
+
* @example
|
|
61
|
+
* // A host provider that is shut down and rebuilt over the same exporters
|
|
62
|
+
* const processor = createExporterSpanProcessor(getExporterRegistry(), { shutdownExporters: false });
|
|
49
63
|
*/
|
|
50
|
-
export declare function createExporterSpanProcessor(registry?: ExporterRegistry): ExporterSpanProcessor;
|
|
64
|
+
export declare function createExporterSpanProcessor(registry?: ExporterRegistry, options?: ExporterSpanProcessorOptions): ExporterSpanProcessor;
|