@juspay/neurolink 9.24.0 → 9.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/adapters/tts/googleTTSHandler.js +26 -1
- package/dist/adapters/video/vertexVideoHandler.js +23 -17
- package/dist/cli/commands/config.d.ts +3 -3
- package/dist/cli/commands/observability.d.ts +53 -0
- package/dist/cli/commands/observability.js +453 -0
- package/dist/cli/commands/telemetry.d.ts +63 -0
- package/dist/cli/commands/telemetry.js +689 -0
- package/dist/cli/factories/commandFactory.js +29 -15
- package/dist/cli/parser.js +6 -9
- package/dist/cli/utils/formatters.d.ts +13 -0
- package/dist/cli/utils/formatters.js +23 -0
- package/dist/constants/contextWindows.js +6 -0
- package/dist/constants/enums.d.ts +6 -0
- package/dist/constants/enums.js +8 -2
- package/dist/context/budgetChecker.js +75 -48
- package/dist/context/contextCompactor.js +135 -127
- package/dist/core/baseProvider.d.ts +5 -0
- package/dist/core/baseProvider.js +117 -110
- package/dist/core/conversationMemoryInitializer.js +7 -4
- package/dist/core/conversationMemoryManager.d.ts +2 -0
- package/dist/core/conversationMemoryManager.js +6 -2
- package/dist/core/modules/GenerationHandler.d.ts +2 -2
- package/dist/core/modules/GenerationHandler.js +12 -12
- package/dist/evaluation/ragasEvaluator.js +39 -19
- package/dist/evaluation/scoring.js +46 -20
- package/dist/features/ppt/presentationOrchestrator.js +23 -0
- package/dist/features/ppt/slideGenerator.js +13 -0
- package/dist/features/ppt/slideRenderers.d.ts +1 -1
- package/dist/features/ppt/slideRenderers.js +6 -4
- package/dist/features/ppt/slideTypeInference.d.ts +1 -1
- package/dist/features/ppt/slideTypeInference.js +75 -73
- package/dist/files/fileTools.d.ts +6 -6
- package/dist/index.d.ts +46 -12
- package/dist/index.js +79 -17
- package/dist/lib/adapters/tts/googleTTSHandler.js +26 -1
- package/dist/lib/adapters/video/vertexVideoHandler.js +23 -17
- package/dist/lib/constants/contextWindows.js +6 -0
- package/dist/lib/constants/enums.d.ts +6 -0
- package/dist/lib/constants/enums.js +8 -2
- package/dist/lib/context/budgetChecker.js +75 -48
- package/dist/lib/context/contextCompactor.js +135 -127
- package/dist/lib/core/baseProvider.d.ts +5 -0
- package/dist/lib/core/baseProvider.js +117 -110
- package/dist/lib/core/conversationMemoryInitializer.js +7 -4
- package/dist/lib/core/conversationMemoryManager.d.ts +2 -0
- package/dist/lib/core/conversationMemoryManager.js +6 -2
- package/dist/lib/core/modules/GenerationHandler.d.ts +2 -2
- package/dist/lib/core/modules/GenerationHandler.js +12 -12
- package/dist/lib/evaluation/ragasEvaluator.js +39 -19
- package/dist/lib/evaluation/scoring.js +46 -20
- package/dist/lib/features/ppt/presentationOrchestrator.js +23 -0
- package/dist/lib/features/ppt/slideGenerator.js +13 -0
- package/dist/lib/features/ppt/slideRenderers.d.ts +1 -1
- package/dist/lib/features/ppt/slideRenderers.js +6 -4
- package/dist/lib/features/ppt/slideTypeInference.d.ts +1 -1
- package/dist/lib/features/ppt/slideTypeInference.js +75 -73
- package/dist/lib/files/fileTools.d.ts +6 -6
- package/dist/lib/index.d.ts +46 -12
- package/dist/lib/index.js +79 -17
- package/dist/lib/mcp/httpRateLimiter.js +39 -12
- package/dist/lib/mcp/httpRetryHandler.js +22 -1
- package/dist/lib/mcp/mcpClientFactory.js +13 -15
- package/dist/lib/memory/memoryRetrievalTools.js +22 -0
- package/dist/lib/neurolink.d.ts +64 -72
- package/dist/lib/neurolink.js +1007 -564
- package/dist/lib/observability/exporterRegistry.d.ts +152 -0
- package/dist/lib/observability/exporterRegistry.js +414 -0
- package/dist/lib/observability/exporters/arizeExporter.d.ts +32 -0
- package/dist/lib/observability/exporters/arizeExporter.js +139 -0
- package/dist/lib/observability/exporters/baseExporter.d.ts +117 -0
- package/dist/lib/observability/exporters/baseExporter.js +191 -0
- package/dist/lib/observability/exporters/braintrustExporter.d.ts +30 -0
- package/dist/lib/observability/exporters/braintrustExporter.js +155 -0
- package/dist/lib/observability/exporters/datadogExporter.d.ts +37 -0
- package/dist/lib/observability/exporters/datadogExporter.js +197 -0
- package/dist/lib/observability/exporters/index.d.ts +13 -0
- package/dist/lib/observability/exporters/index.js +14 -0
- package/dist/lib/observability/exporters/laminarExporter.d.ts +48 -0
- package/dist/lib/observability/exporters/laminarExporter.js +303 -0
- package/dist/lib/observability/exporters/langfuseExporter.d.ts +47 -0
- package/dist/lib/observability/exporters/langfuseExporter.js +204 -0
- package/dist/lib/observability/exporters/langsmithExporter.d.ts +26 -0
- package/dist/lib/observability/exporters/langsmithExporter.js +124 -0
- package/dist/lib/observability/exporters/otelExporter.d.ts +39 -0
- package/dist/lib/observability/exporters/otelExporter.js +165 -0
- package/dist/lib/observability/exporters/posthogExporter.d.ts +48 -0
- package/dist/lib/observability/exporters/posthogExporter.js +288 -0
- package/dist/lib/observability/exporters/sentryExporter.d.ts +32 -0
- package/dist/lib/observability/exporters/sentryExporter.js +166 -0
- package/dist/lib/observability/index.d.ts +25 -0
- package/dist/lib/observability/index.js +32 -0
- package/dist/lib/observability/metricsAggregator.d.ts +260 -0
- package/dist/lib/observability/metricsAggregator.js +557 -0
- package/dist/lib/observability/otelBridge.d.ts +49 -0
- package/dist/lib/observability/otelBridge.js +132 -0
- package/dist/lib/observability/retryPolicy.d.ts +192 -0
- package/dist/lib/observability/retryPolicy.js +384 -0
- package/dist/lib/observability/sampling/index.d.ts +4 -0
- package/dist/lib/observability/sampling/index.js +5 -0
- package/dist/lib/observability/sampling/samplers.d.ts +116 -0
- package/dist/lib/observability/sampling/samplers.js +217 -0
- package/dist/lib/observability/spanProcessor.d.ts +129 -0
- package/dist/lib/observability/spanProcessor.js +304 -0
- package/dist/lib/observability/tokenTracker.d.ts +156 -0
- package/dist/lib/observability/tokenTracker.js +414 -0
- package/dist/lib/observability/types/exporterTypes.d.ts +250 -0
- package/dist/lib/observability/types/exporterTypes.js +6 -0
- package/dist/lib/observability/types/index.d.ts +6 -0
- package/dist/lib/observability/types/index.js +5 -0
- package/dist/lib/observability/types/spanTypes.d.ts +244 -0
- package/dist/lib/observability/types/spanTypes.js +93 -0
- package/dist/lib/observability/utils/index.d.ts +4 -0
- package/dist/lib/observability/utils/index.js +5 -0
- package/dist/lib/observability/utils/safeMetadata.d.ts +10 -0
- package/dist/lib/observability/utils/safeMetadata.js +26 -0
- package/dist/lib/observability/utils/spanSerializer.d.ts +115 -0
- package/dist/lib/observability/utils/spanSerializer.js +291 -0
- package/dist/lib/providers/amazonSagemaker.d.ts +5 -4
- package/dist/lib/providers/amazonSagemaker.js +3 -4
- package/dist/lib/providers/googleVertex.d.ts +7 -0
- package/dist/lib/providers/googleVertex.js +76 -2
- package/dist/lib/rag/pipeline/RAGPipeline.d.ts +0 -5
- package/dist/lib/rag/pipeline/RAGPipeline.js +122 -87
- package/dist/lib/rag/ragIntegration.js +30 -0
- package/dist/lib/rag/retrieval/hybridSearch.js +22 -0
- package/dist/lib/server/abstract/baseServerAdapter.js +51 -19
- package/dist/lib/server/middleware/common.js +44 -12
- package/dist/lib/services/server/ai/observability/instrumentation.d.ts +2 -2
- package/dist/lib/services/server/ai/observability/instrumentation.js +10 -5
- package/dist/lib/types/conversationMemoryInterface.d.ts +2 -0
- package/dist/lib/types/modelTypes.d.ts +18 -18
- package/dist/lib/types/providers.d.ts +5 -0
- package/dist/lib/utils/pricing.js +25 -1
- package/dist/lib/utils/ttsProcessor.js +74 -59
- package/dist/lib/workflow/config.d.ts +36 -36
- package/dist/lib/workflow/core/ensembleExecutor.js +10 -0
- package/dist/lib/workflow/core/judgeScorer.js +20 -2
- package/dist/lib/workflow/core/workflowRunner.js +34 -1
- package/dist/mcp/httpRateLimiter.js +39 -12
- package/dist/mcp/httpRetryHandler.js +22 -1
- package/dist/mcp/mcpClientFactory.js +13 -15
- package/dist/memory/memoryRetrievalTools.js +22 -0
- package/dist/neurolink.d.ts +64 -72
- package/dist/neurolink.js +1007 -564
- package/dist/observability/FEATURE-STATUS.md +269 -0
- package/dist/observability/exporterRegistry.d.ts +152 -0
- package/dist/observability/exporterRegistry.js +413 -0
- package/dist/observability/exporters/arizeExporter.d.ts +32 -0
- package/dist/observability/exporters/arizeExporter.js +138 -0
- package/dist/observability/exporters/baseExporter.d.ts +117 -0
- package/dist/observability/exporters/baseExporter.js +190 -0
- package/dist/observability/exporters/braintrustExporter.d.ts +30 -0
- package/dist/observability/exporters/braintrustExporter.js +154 -0
- package/dist/observability/exporters/datadogExporter.d.ts +37 -0
- package/dist/observability/exporters/datadogExporter.js +196 -0
- package/dist/observability/exporters/index.d.ts +13 -0
- package/dist/observability/exporters/index.js +13 -0
- package/dist/observability/exporters/laminarExporter.d.ts +48 -0
- package/dist/observability/exporters/laminarExporter.js +302 -0
- package/dist/observability/exporters/langfuseExporter.d.ts +47 -0
- package/dist/observability/exporters/langfuseExporter.js +203 -0
- package/dist/observability/exporters/langsmithExporter.d.ts +26 -0
- package/dist/observability/exporters/langsmithExporter.js +123 -0
- package/dist/observability/exporters/otelExporter.d.ts +39 -0
- package/dist/observability/exporters/otelExporter.js +164 -0
- package/dist/observability/exporters/posthogExporter.d.ts +48 -0
- package/dist/observability/exporters/posthogExporter.js +287 -0
- package/dist/observability/exporters/sentryExporter.d.ts +32 -0
- package/dist/observability/exporters/sentryExporter.js +165 -0
- package/dist/observability/index.d.ts +25 -0
- package/dist/observability/index.js +31 -0
- package/dist/observability/metricsAggregator.d.ts +260 -0
- package/dist/observability/metricsAggregator.js +556 -0
- package/dist/observability/otelBridge.d.ts +49 -0
- package/dist/observability/otelBridge.js +131 -0
- package/dist/observability/retryPolicy.d.ts +192 -0
- package/dist/observability/retryPolicy.js +383 -0
- package/dist/observability/sampling/index.d.ts +4 -0
- package/dist/observability/sampling/index.js +4 -0
- package/dist/observability/sampling/samplers.d.ts +116 -0
- package/dist/observability/sampling/samplers.js +216 -0
- package/dist/observability/spanProcessor.d.ts +129 -0
- package/dist/observability/spanProcessor.js +303 -0
- package/dist/observability/tokenTracker.d.ts +156 -0
- package/dist/observability/tokenTracker.js +413 -0
- package/dist/observability/types/exporterTypes.d.ts +250 -0
- package/dist/observability/types/exporterTypes.js +5 -0
- package/dist/observability/types/index.d.ts +6 -0
- package/dist/observability/types/index.js +4 -0
- package/dist/observability/types/spanTypes.d.ts +244 -0
- package/dist/observability/types/spanTypes.js +92 -0
- package/dist/observability/utils/index.d.ts +4 -0
- package/dist/observability/utils/index.js +4 -0
- package/dist/observability/utils/safeMetadata.d.ts +10 -0
- package/dist/observability/utils/safeMetadata.js +25 -0
- package/dist/observability/utils/spanSerializer.d.ts +115 -0
- package/dist/observability/utils/spanSerializer.js +290 -0
- package/dist/providers/amazonSagemaker.d.ts +5 -4
- package/dist/providers/amazonSagemaker.js +3 -4
- package/dist/providers/googleVertex.d.ts +7 -0
- package/dist/providers/googleVertex.js +76 -2
- package/dist/rag/pipeline/RAGPipeline.d.ts +0 -5
- package/dist/rag/pipeline/RAGPipeline.js +122 -87
- package/dist/rag/ragIntegration.js +30 -0
- package/dist/rag/retrieval/hybridSearch.js +22 -0
- package/dist/server/abstract/baseServerAdapter.js +51 -19
- package/dist/server/middleware/common.js +44 -12
- package/dist/services/server/ai/observability/instrumentation.d.ts +2 -2
- package/dist/services/server/ai/observability/instrumentation.js +10 -5
- package/dist/types/conversationMemoryInterface.d.ts +2 -0
- package/dist/types/providers.d.ts +5 -0
- package/dist/utils/pricing.js +25 -1
- package/dist/utils/ttsProcessor.js +74 -59
- package/dist/workflow/config.d.ts +52 -52
- package/dist/workflow/core/ensembleExecutor.js +10 -0
- package/dist/workflow/core/judgeScorer.js +20 -2
- package/dist/workflow/core/workflowRunner.js +34 -1
- package/package.json +1 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sampling strategies exports
|
|
3
|
+
*/
|
|
4
|
+
export { AlwaysSampler, AttributeBasedSampler, CompositeSampler, CustomSampler, ErrorOnlySampler, NeverSampler, PrioritySampler, RatioSampler, SamplerFactory, TraceIdRatioSampler, } from "./samplers.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sampling Strategies
|
|
3
|
+
* Control which spans are exported for production optimization
|
|
4
|
+
*/
|
|
5
|
+
import type { SamplerConfig, SamplingRule } from "../types/exporterTypes.js";
|
|
6
|
+
import type { SpanData } from "../types/spanTypes.js";
|
|
7
|
+
/**
|
|
8
|
+
* Sampler interface for controlling which spans are exported
|
|
9
|
+
*/
|
|
10
|
+
export interface Sampler {
|
|
11
|
+
/** Sampler name for identification */
|
|
12
|
+
readonly name: string;
|
|
13
|
+
/** Determine if a span should be sampled */
|
|
14
|
+
shouldSample(span: SpanData): boolean;
|
|
15
|
+
/** Get sampling decision description */
|
|
16
|
+
getDescription(): string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Always sample all spans
|
|
20
|
+
*/
|
|
21
|
+
export declare class AlwaysSampler implements Sampler {
|
|
22
|
+
readonly name = "always";
|
|
23
|
+
shouldSample(_span: SpanData): boolean;
|
|
24
|
+
getDescription(): string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Never sample any spans
|
|
28
|
+
*/
|
|
29
|
+
export declare class NeverSampler implements Sampler {
|
|
30
|
+
readonly name = "never";
|
|
31
|
+
shouldSample(_span: SpanData): boolean;
|
|
32
|
+
getDescription(): string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Sample spans based on a probability ratio
|
|
36
|
+
*/
|
|
37
|
+
export declare class RatioSampler implements Sampler {
|
|
38
|
+
readonly name = "ratio";
|
|
39
|
+
private readonly ratio;
|
|
40
|
+
constructor(ratio: number);
|
|
41
|
+
shouldSample(_span: SpanData): boolean;
|
|
42
|
+
getDescription(): string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Sample based on trace ID for consistent sampling across a trace
|
|
46
|
+
*/
|
|
47
|
+
export declare class TraceIdRatioSampler implements Sampler {
|
|
48
|
+
readonly name = "trace-id-ratio";
|
|
49
|
+
private readonly ratio;
|
|
50
|
+
private readonly upperBound;
|
|
51
|
+
constructor(ratio: number);
|
|
52
|
+
shouldSample(span: SpanData): boolean;
|
|
53
|
+
getDescription(): string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Sample based on span attributes (e.g., errors, specific providers)
|
|
57
|
+
*/
|
|
58
|
+
export declare class AttributeBasedSampler implements Sampler {
|
|
59
|
+
readonly name = "attribute-based";
|
|
60
|
+
private readonly rules;
|
|
61
|
+
private readonly defaultSampler;
|
|
62
|
+
constructor(rules: SamplingRule[], defaultSampler?: Sampler);
|
|
63
|
+
shouldSample(span: SpanData): boolean;
|
|
64
|
+
private matchesRule;
|
|
65
|
+
getDescription(): string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Priority-based sampler - always sample high-priority spans
|
|
69
|
+
*/
|
|
70
|
+
export declare class PrioritySampler implements Sampler {
|
|
71
|
+
readonly name = "priority";
|
|
72
|
+
private readonly highPriorityTypes;
|
|
73
|
+
private readonly fallbackSampler;
|
|
74
|
+
constructor(highPriorityTypes?: string[], fallbackSampler?: Sampler);
|
|
75
|
+
shouldSample(span: SpanData): boolean;
|
|
76
|
+
getDescription(): string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Error-only sampler - only sample error spans
|
|
80
|
+
*/
|
|
81
|
+
export declare class ErrorOnlySampler implements Sampler {
|
|
82
|
+
readonly name = "error-only";
|
|
83
|
+
shouldSample(span: SpanData): boolean;
|
|
84
|
+
getDescription(): string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Composite sampler that combines multiple samplers
|
|
88
|
+
*/
|
|
89
|
+
export declare class CompositeSampler implements Sampler {
|
|
90
|
+
readonly name = "composite";
|
|
91
|
+
private readonly samplers;
|
|
92
|
+
private readonly totalWeight;
|
|
93
|
+
constructor(samplers: Array<{
|
|
94
|
+
sampler: Sampler;
|
|
95
|
+
weight: number;
|
|
96
|
+
}>);
|
|
97
|
+
shouldSample(span: SpanData): boolean;
|
|
98
|
+
getDescription(): string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Custom sampler that uses a user-provided function
|
|
102
|
+
*/
|
|
103
|
+
export declare class CustomSampler implements Sampler {
|
|
104
|
+
readonly name = "custom";
|
|
105
|
+
private readonly sampleFn;
|
|
106
|
+
private readonly description;
|
|
107
|
+
constructor(sampleFn: (span: SpanData) => boolean, description?: string);
|
|
108
|
+
shouldSample(span: SpanData): boolean;
|
|
109
|
+
getDescription(): string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Factory for creating samplers from configuration
|
|
113
|
+
*/
|
|
114
|
+
export declare class SamplerFactory {
|
|
115
|
+
static create(config: SamplerConfig): Sampler;
|
|
116
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sampling Strategies
|
|
3
|
+
* Control which spans are exported for production optimization
|
|
4
|
+
*/
|
|
5
|
+
import { SpanStatus } from "../types/spanTypes.js";
|
|
6
|
+
/**
|
|
7
|
+
* Always sample all spans
|
|
8
|
+
*/
|
|
9
|
+
export class AlwaysSampler {
|
|
10
|
+
name = "always";
|
|
11
|
+
shouldSample(_span) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
getDescription() {
|
|
15
|
+
return "Samples 100% of spans";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Never sample any spans
|
|
20
|
+
*/
|
|
21
|
+
export class NeverSampler {
|
|
22
|
+
name = "never";
|
|
23
|
+
shouldSample(_span) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
getDescription() {
|
|
27
|
+
return "Samples 0% of spans";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Sample spans based on a probability ratio
|
|
32
|
+
*/
|
|
33
|
+
export class RatioSampler {
|
|
34
|
+
name = "ratio";
|
|
35
|
+
ratio;
|
|
36
|
+
constructor(ratio) {
|
|
37
|
+
if (ratio < 0 || ratio > 1) {
|
|
38
|
+
throw new Error("Ratio must be between 0 and 1");
|
|
39
|
+
}
|
|
40
|
+
this.ratio = ratio;
|
|
41
|
+
}
|
|
42
|
+
shouldSample(_span) {
|
|
43
|
+
return Math.random() < this.ratio;
|
|
44
|
+
}
|
|
45
|
+
getDescription() {
|
|
46
|
+
return `Samples ${this.ratio * 100}% of spans`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Sample based on trace ID for consistent sampling across a trace
|
|
51
|
+
*/
|
|
52
|
+
export class TraceIdRatioSampler {
|
|
53
|
+
name = "trace-id-ratio";
|
|
54
|
+
ratio;
|
|
55
|
+
upperBound;
|
|
56
|
+
constructor(ratio) {
|
|
57
|
+
if (ratio < 0 || ratio > 1) {
|
|
58
|
+
throw new Error("Ratio must be between 0 and 1");
|
|
59
|
+
}
|
|
60
|
+
this.ratio = ratio;
|
|
61
|
+
this.upperBound = Math.floor(ratio * 0xffffffff);
|
|
62
|
+
}
|
|
63
|
+
shouldSample(span) {
|
|
64
|
+
// Use first 8 chars of trace ID as hash
|
|
65
|
+
const hash = parseInt(span.traceId.substring(0, 8), 16);
|
|
66
|
+
return !isNaN(hash) && hash < this.upperBound;
|
|
67
|
+
}
|
|
68
|
+
getDescription() {
|
|
69
|
+
return `Samples ${this.ratio * 100}% of traces (consistent per trace)`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Sample based on span attributes (e.g., errors, specific providers)
|
|
74
|
+
*/
|
|
75
|
+
export class AttributeBasedSampler {
|
|
76
|
+
name = "attribute-based";
|
|
77
|
+
rules;
|
|
78
|
+
defaultSampler;
|
|
79
|
+
constructor(rules, defaultSampler = new RatioSampler(0.1)) {
|
|
80
|
+
// Sort rules by priority (higher first)
|
|
81
|
+
this.rules = [...rules].sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
82
|
+
this.defaultSampler = defaultSampler;
|
|
83
|
+
}
|
|
84
|
+
shouldSample(span) {
|
|
85
|
+
for (const rule of this.rules) {
|
|
86
|
+
if (this.matchesRule(span, rule)) {
|
|
87
|
+
return rule.sample;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return this.defaultSampler.shouldSample(span);
|
|
91
|
+
}
|
|
92
|
+
matchesRule(span, rule) {
|
|
93
|
+
for (const [key, value] of Object.entries(rule.conditions)) {
|
|
94
|
+
const spanValue = span.attributes[key];
|
|
95
|
+
// Support wildcard matching
|
|
96
|
+
if (value === "*" && spanValue !== undefined) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (spanValue !== value) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
getDescription() {
|
|
106
|
+
return `Attribute-based sampling with ${this.rules.length} rules`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Priority-based sampler - always sample high-priority spans
|
|
111
|
+
*/
|
|
112
|
+
export class PrioritySampler {
|
|
113
|
+
name = "priority";
|
|
114
|
+
highPriorityTypes;
|
|
115
|
+
fallbackSampler;
|
|
116
|
+
constructor(highPriorityTypes = ["model.generation", "tool.call"], fallbackSampler = new RatioSampler(0.1)) {
|
|
117
|
+
this.highPriorityTypes = highPriorityTypes;
|
|
118
|
+
this.fallbackSampler = fallbackSampler;
|
|
119
|
+
}
|
|
120
|
+
shouldSample(span) {
|
|
121
|
+
// Always sample errors
|
|
122
|
+
if (span.status === SpanStatus.ERROR) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
// Always sample high-priority span types
|
|
126
|
+
if (this.highPriorityTypes.includes(span.type)) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
return this.fallbackSampler.shouldSample(span);
|
|
130
|
+
}
|
|
131
|
+
getDescription() {
|
|
132
|
+
return `Priority sampling for ${this.highPriorityTypes.join(", ")} spans`;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Error-only sampler - only sample error spans
|
|
137
|
+
*/
|
|
138
|
+
export class ErrorOnlySampler {
|
|
139
|
+
name = "error-only";
|
|
140
|
+
shouldSample(span) {
|
|
141
|
+
return span.status === SpanStatus.ERROR;
|
|
142
|
+
}
|
|
143
|
+
getDescription() {
|
|
144
|
+
return "Samples only error spans";
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Composite sampler that combines multiple samplers
|
|
149
|
+
*/
|
|
150
|
+
export class CompositeSampler {
|
|
151
|
+
name = "composite";
|
|
152
|
+
samplers;
|
|
153
|
+
totalWeight;
|
|
154
|
+
constructor(samplers) {
|
|
155
|
+
this.samplers = samplers;
|
|
156
|
+
this.totalWeight = samplers.reduce((sum, s) => sum + s.weight, 0);
|
|
157
|
+
}
|
|
158
|
+
shouldSample(span) {
|
|
159
|
+
let random = Math.random() * this.totalWeight;
|
|
160
|
+
for (const { sampler, weight } of this.samplers) {
|
|
161
|
+
random -= weight;
|
|
162
|
+
if (random <= 0) {
|
|
163
|
+
return sampler.shouldSample(span);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return this.samplers[this.samplers.length - 1].sampler.shouldSample(span);
|
|
167
|
+
}
|
|
168
|
+
getDescription() {
|
|
169
|
+
return `Composite of ${this.samplers.length} samplers`;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Custom sampler that uses a user-provided function
|
|
174
|
+
*/
|
|
175
|
+
export class CustomSampler {
|
|
176
|
+
name = "custom";
|
|
177
|
+
sampleFn;
|
|
178
|
+
description;
|
|
179
|
+
constructor(sampleFn, description = "Custom sampling function") {
|
|
180
|
+
this.sampleFn = sampleFn;
|
|
181
|
+
this.description = description;
|
|
182
|
+
}
|
|
183
|
+
shouldSample(span) {
|
|
184
|
+
return this.sampleFn(span);
|
|
185
|
+
}
|
|
186
|
+
getDescription() {
|
|
187
|
+
return this.description;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Factory for creating samplers from configuration
|
|
192
|
+
*/
|
|
193
|
+
export class SamplerFactory {
|
|
194
|
+
static create(config) {
|
|
195
|
+
switch (config.type) {
|
|
196
|
+
case "always":
|
|
197
|
+
return new AlwaysSampler();
|
|
198
|
+
case "never":
|
|
199
|
+
return new NeverSampler();
|
|
200
|
+
case "ratio":
|
|
201
|
+
return new RatioSampler(config.ratio ?? 0.1);
|
|
202
|
+
case "trace-id-ratio":
|
|
203
|
+
return new TraceIdRatioSampler(config.ratio ?? 0.1);
|
|
204
|
+
case "attribute-based":
|
|
205
|
+
return new AttributeBasedSampler(config.rules ?? [], config.defaultRatio !== undefined
|
|
206
|
+
? new RatioSampler(config.defaultRatio)
|
|
207
|
+
: undefined);
|
|
208
|
+
case "priority":
|
|
209
|
+
return new PrioritySampler();
|
|
210
|
+
case "error-only":
|
|
211
|
+
return new ErrorOnlySampler();
|
|
212
|
+
default:
|
|
213
|
+
return new RatioSampler(0.1);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=samplers.js.map
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Span Processor
|
|
3
|
+
* Handles span processing before export - enrichment, filtering, and transformation
|
|
4
|
+
* Fills the 9% gap in pattern compliance
|
|
5
|
+
*/
|
|
6
|
+
import type { SpanAttributes, SpanData } from "./types/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* Span processor interface
|
|
9
|
+
* Allows for composable span processing pipelines
|
|
10
|
+
*/
|
|
11
|
+
export interface SpanProcessor {
|
|
12
|
+
/** Processor name for identification */
|
|
13
|
+
readonly name: string;
|
|
14
|
+
/** Process a span before export, returns null to drop the span */
|
|
15
|
+
process(span: SpanData): SpanData | null;
|
|
16
|
+
/** Optional async processing (for external lookups, etc.) */
|
|
17
|
+
processAsync?(span: SpanData): Promise<SpanData | null>;
|
|
18
|
+
/** Shutdown the processor (cleanup resources) */
|
|
19
|
+
shutdown?(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* No-op processor that passes spans through unchanged
|
|
23
|
+
*/
|
|
24
|
+
export declare class PassThroughProcessor implements SpanProcessor {
|
|
25
|
+
readonly name = "pass-through";
|
|
26
|
+
process(span: SpanData): SpanData;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Attribute enrichment processor
|
|
30
|
+
* Adds additional attributes to spans based on configuration
|
|
31
|
+
*/
|
|
32
|
+
export declare class AttributeEnrichmentProcessor implements SpanProcessor {
|
|
33
|
+
readonly name = "attribute-enrichment";
|
|
34
|
+
private readonly staticAttributes;
|
|
35
|
+
private readonly dynamicAttributes;
|
|
36
|
+
constructor(config: {
|
|
37
|
+
staticAttributes?: SpanAttributes;
|
|
38
|
+
dynamicAttributes?: (span: SpanData) => Partial<SpanAttributes>;
|
|
39
|
+
});
|
|
40
|
+
process(span: SpanData): SpanData;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Filter processor - drops spans based on conditions
|
|
44
|
+
*/
|
|
45
|
+
export declare class FilterProcessor implements SpanProcessor {
|
|
46
|
+
readonly name = "filter";
|
|
47
|
+
private readonly predicate;
|
|
48
|
+
constructor(predicate: (span: SpanData) => boolean);
|
|
49
|
+
process(span: SpanData): SpanData | null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Redaction processor - removes sensitive data from spans
|
|
53
|
+
*/
|
|
54
|
+
export declare class RedactionProcessor implements SpanProcessor {
|
|
55
|
+
readonly name = "redaction";
|
|
56
|
+
private readonly sensitiveKeys;
|
|
57
|
+
private readonly redactedValue;
|
|
58
|
+
constructor(config?: {
|
|
59
|
+
sensitiveKeys?: string[];
|
|
60
|
+
redactedValue?: string;
|
|
61
|
+
});
|
|
62
|
+
process(span: SpanData): SpanData;
|
|
63
|
+
private redactObject;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Truncation processor - truncates large attribute values
|
|
67
|
+
*/
|
|
68
|
+
export declare class TruncationProcessor implements SpanProcessor {
|
|
69
|
+
readonly name = "truncation";
|
|
70
|
+
private readonly maxStringLength;
|
|
71
|
+
private readonly maxArrayLength;
|
|
72
|
+
constructor(config?: {
|
|
73
|
+
maxStringLength?: number;
|
|
74
|
+
maxArrayLength?: number;
|
|
75
|
+
});
|
|
76
|
+
process(span: SpanData): SpanData;
|
|
77
|
+
private truncateAttributes;
|
|
78
|
+
private truncateValue;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Composite processor - chains multiple processors together
|
|
82
|
+
*/
|
|
83
|
+
export declare class CompositeProcessor implements SpanProcessor {
|
|
84
|
+
readonly name = "composite";
|
|
85
|
+
private readonly processors;
|
|
86
|
+
constructor(processors: SpanProcessor[]);
|
|
87
|
+
process(span: SpanData): SpanData | null;
|
|
88
|
+
processAsync(span: SpanData): Promise<SpanData | null>;
|
|
89
|
+
shutdown(): Promise<void>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Batch processor - collects spans and processes them in batches
|
|
93
|
+
*/
|
|
94
|
+
export declare class BatchProcessor implements SpanProcessor {
|
|
95
|
+
readonly name = "batch";
|
|
96
|
+
private readonly innerProcessor;
|
|
97
|
+
private readonly batchSize;
|
|
98
|
+
private readonly flushIntervalMs;
|
|
99
|
+
private batch;
|
|
100
|
+
private flushTimer;
|
|
101
|
+
private onBatchReady?;
|
|
102
|
+
constructor(config: {
|
|
103
|
+
processor?: SpanProcessor;
|
|
104
|
+
batchSize?: number;
|
|
105
|
+
flushIntervalMs?: number;
|
|
106
|
+
onBatchReady?: (spans: SpanData[]) => void;
|
|
107
|
+
});
|
|
108
|
+
process(span: SpanData): SpanData | null;
|
|
109
|
+
private startFlushTimer;
|
|
110
|
+
private flush;
|
|
111
|
+
shutdown(): Promise<void>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Factory for creating span processors
|
|
115
|
+
*/
|
|
116
|
+
export declare class SpanProcessorFactory {
|
|
117
|
+
/**
|
|
118
|
+
* Create a standard processor pipeline for production use
|
|
119
|
+
*/
|
|
120
|
+
static createProductionPipeline(config?: {
|
|
121
|
+
serviceName?: string;
|
|
122
|
+
environment?: string;
|
|
123
|
+
additionalProcessors?: SpanProcessor[];
|
|
124
|
+
}): CompositeProcessor;
|
|
125
|
+
/**
|
|
126
|
+
* Create a minimal processor pipeline for development
|
|
127
|
+
*/
|
|
128
|
+
static createDevelopmentPipeline(): CompositeProcessor;
|
|
129
|
+
}
|