autotel 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1946 -0
- package/dist/chunk-2LNRY4QK.js +273 -0
- package/dist/chunk-2LNRY4QK.js.map +1 -0
- package/dist/chunk-3HENGDW2.js +587 -0
- package/dist/chunk-3HENGDW2.js.map +1 -0
- package/dist/chunk-4OAT42CA.cjs +73 -0
- package/dist/chunk-4OAT42CA.cjs.map +1 -0
- package/dist/chunk-5GWX5LFW.js +70 -0
- package/dist/chunk-5GWX5LFW.js.map +1 -0
- package/dist/chunk-5R2M36QB.js +195 -0
- package/dist/chunk-5R2M36QB.js.map +1 -0
- package/dist/chunk-5ZN622AO.js +73 -0
- package/dist/chunk-5ZN622AO.js.map +1 -0
- package/dist/chunk-77MSMAUQ.cjs +498 -0
- package/dist/chunk-77MSMAUQ.cjs.map +1 -0
- package/dist/chunk-ABPEQ6RK.cjs +596 -0
- package/dist/chunk-ABPEQ6RK.cjs.map +1 -0
- package/dist/chunk-BWYGJKRB.js +95 -0
- package/dist/chunk-BWYGJKRB.js.map +1 -0
- package/dist/chunk-BZHG5IZ4.js +73 -0
- package/dist/chunk-BZHG5IZ4.js.map +1 -0
- package/dist/chunk-G7VZBCD6.cjs +35 -0
- package/dist/chunk-G7VZBCD6.cjs.map +1 -0
- package/dist/chunk-GVLK7YUU.cjs +30 -0
- package/dist/chunk-GVLK7YUU.cjs.map +1 -0
- package/dist/chunk-HCCXC7XG.js +205 -0
- package/dist/chunk-HCCXC7XG.js.map +1 -0
- package/dist/chunk-HE6T6FIX.cjs +203 -0
- package/dist/chunk-HE6T6FIX.cjs.map +1 -0
- package/dist/chunk-KIXWPOCO.cjs +100 -0
- package/dist/chunk-KIXWPOCO.cjs.map +1 -0
- package/dist/chunk-KVGNW3FC.js +87 -0
- package/dist/chunk-KVGNW3FC.js.map +1 -0
- package/dist/chunk-LITNXTTT.js +3 -0
- package/dist/chunk-LITNXTTT.js.map +1 -0
- package/dist/chunk-M4ANN7RL.js +114 -0
- package/dist/chunk-M4ANN7RL.js.map +1 -0
- package/dist/chunk-NC52UBR2.cjs +32 -0
- package/dist/chunk-NC52UBR2.cjs.map +1 -0
- package/dist/chunk-NHCNRQD3.cjs +212 -0
- package/dist/chunk-NHCNRQD3.cjs.map +1 -0
- package/dist/chunk-NZ72VDNY.cjs +4 -0
- package/dist/chunk-NZ72VDNY.cjs.map +1 -0
- package/dist/chunk-P6JUDYNO.js +57 -0
- package/dist/chunk-P6JUDYNO.js.map +1 -0
- package/dist/chunk-RJYY7BWX.js +1349 -0
- package/dist/chunk-RJYY7BWX.js.map +1 -0
- package/dist/chunk-TRI4V5BF.cjs +126 -0
- package/dist/chunk-TRI4V5BF.cjs.map +1 -0
- package/dist/chunk-UL33I6IS.js +139 -0
- package/dist/chunk-UL33I6IS.js.map +1 -0
- package/dist/chunk-URRW6M2C.cjs +61 -0
- package/dist/chunk-URRW6M2C.cjs.map +1 -0
- package/dist/chunk-UY3UYPBZ.cjs +77 -0
- package/dist/chunk-UY3UYPBZ.cjs.map +1 -0
- package/dist/chunk-W3253FGB.cjs +277 -0
- package/dist/chunk-W3253FGB.cjs.map +1 -0
- package/dist/chunk-W7LHZVQF.js +26 -0
- package/dist/chunk-W7LHZVQF.js.map +1 -0
- package/dist/chunk-WBWNM6LB.cjs +1360 -0
- package/dist/chunk-WBWNM6LB.cjs.map +1 -0
- package/dist/chunk-WFJ7L2RV.js +494 -0
- package/dist/chunk-WFJ7L2RV.js.map +1 -0
- package/dist/chunk-X4RMFFMR.js +28 -0
- package/dist/chunk-X4RMFFMR.js.map +1 -0
- package/dist/chunk-Y4Y2S7BM.cjs +92 -0
- package/dist/chunk-Y4Y2S7BM.cjs.map +1 -0
- package/dist/chunk-YLPNXZFI.cjs +143 -0
- package/dist/chunk-YLPNXZFI.cjs.map +1 -0
- package/dist/chunk-YTXEZ4SD.cjs +77 -0
- package/dist/chunk-YTXEZ4SD.cjs.map +1 -0
- package/dist/chunk-Z6ZWNWWR.js +30 -0
- package/dist/chunk-Z6ZWNWWR.js.map +1 -0
- package/dist/config.cjs +26 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +75 -0
- package/dist/config.d.ts +75 -0
- package/dist/config.js +5 -0
- package/dist/config.js.map +1 -0
- package/dist/db.cjs +233 -0
- package/dist/db.cjs.map +1 -0
- package/dist/db.d.cts +123 -0
- package/dist/db.d.ts +123 -0
- package/dist/db.js +228 -0
- package/dist/db.js.map +1 -0
- package/dist/decorators.cjs +67 -0
- package/dist/decorators.cjs.map +1 -0
- package/dist/decorators.d.cts +91 -0
- package/dist/decorators.d.ts +91 -0
- package/dist/decorators.js +65 -0
- package/dist/decorators.js.map +1 -0
- package/dist/event-subscriber.cjs +6 -0
- package/dist/event-subscriber.cjs.map +1 -0
- package/dist/event-subscriber.d.cts +116 -0
- package/dist/event-subscriber.d.ts +116 -0
- package/dist/event-subscriber.js +3 -0
- package/dist/event-subscriber.js.map +1 -0
- package/dist/event-testing.cjs +21 -0
- package/dist/event-testing.cjs.map +1 -0
- package/dist/event-testing.d.cts +110 -0
- package/dist/event-testing.d.ts +110 -0
- package/dist/event-testing.js +4 -0
- package/dist/event-testing.js.map +1 -0
- package/dist/event.cjs +30 -0
- package/dist/event.cjs.map +1 -0
- package/dist/event.d.cts +282 -0
- package/dist/event.d.ts +282 -0
- package/dist/event.js +13 -0
- package/dist/event.js.map +1 -0
- package/dist/exporters.cjs +17 -0
- package/dist/exporters.cjs.map +1 -0
- package/dist/exporters.d.cts +1 -0
- package/dist/exporters.d.ts +1 -0
- package/dist/exporters.js +4 -0
- package/dist/exporters.js.map +1 -0
- package/dist/functional.cjs +46 -0
- package/dist/functional.cjs.map +1 -0
- package/dist/functional.d.cts +478 -0
- package/dist/functional.d.ts +478 -0
- package/dist/functional.js +13 -0
- package/dist/functional.js.map +1 -0
- package/dist/http.cjs +189 -0
- package/dist/http.cjs.map +1 -0
- package/dist/http.d.cts +169 -0
- package/dist/http.d.ts +169 -0
- package/dist/http.js +184 -0
- package/dist/http.js.map +1 -0
- package/dist/index.cjs +333 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +758 -0
- package/dist/index.d.ts +758 -0
- package/dist/index.js +143 -0
- package/dist/index.js.map +1 -0
- package/dist/instrumentation.cjs +182 -0
- package/dist/instrumentation.cjs.map +1 -0
- package/dist/instrumentation.d.cts +49 -0
- package/dist/instrumentation.d.ts +49 -0
- package/dist/instrumentation.js +179 -0
- package/dist/instrumentation.js.map +1 -0
- package/dist/logger.cjs +19 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +146 -0
- package/dist/logger.d.ts +146 -0
- package/dist/logger.js +6 -0
- package/dist/logger.js.map +1 -0
- package/dist/metric-helpers.cjs +31 -0
- package/dist/metric-helpers.cjs.map +1 -0
- package/dist/metric-helpers.d.cts +13 -0
- package/dist/metric-helpers.d.ts +13 -0
- package/dist/metric-helpers.js +6 -0
- package/dist/metric-helpers.js.map +1 -0
- package/dist/metric-testing.cjs +21 -0
- package/dist/metric-testing.cjs.map +1 -0
- package/dist/metric-testing.d.cts +110 -0
- package/dist/metric-testing.d.ts +110 -0
- package/dist/metric-testing.js +4 -0
- package/dist/metric-testing.js.map +1 -0
- package/dist/metric.cjs +26 -0
- package/dist/metric.cjs.map +1 -0
- package/dist/metric.d.cts +240 -0
- package/dist/metric.d.ts +240 -0
- package/dist/metric.js +9 -0
- package/dist/metric.js.map +1 -0
- package/dist/processors.cjs +17 -0
- package/dist/processors.cjs.map +1 -0
- package/dist/processors.d.cts +1 -0
- package/dist/processors.d.ts +1 -0
- package/dist/processors.js +4 -0
- package/dist/processors.js.map +1 -0
- package/dist/sampling.cjs +40 -0
- package/dist/sampling.cjs.map +1 -0
- package/dist/sampling.d.cts +260 -0
- package/dist/sampling.d.ts +260 -0
- package/dist/sampling.js +7 -0
- package/dist/sampling.js.map +1 -0
- package/dist/semantic-helpers.cjs +35 -0
- package/dist/semantic-helpers.cjs.map +1 -0
- package/dist/semantic-helpers.d.cts +442 -0
- package/dist/semantic-helpers.d.ts +442 -0
- package/dist/semantic-helpers.js +14 -0
- package/dist/semantic-helpers.js.map +1 -0
- package/dist/tail-sampling-processor.cjs +13 -0
- package/dist/tail-sampling-processor.cjs.map +1 -0
- package/dist/tail-sampling-processor.d.cts +27 -0
- package/dist/tail-sampling-processor.d.ts +27 -0
- package/dist/tail-sampling-processor.js +4 -0
- package/dist/tail-sampling-processor.js.map +1 -0
- package/dist/testing.cjs +286 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +291 -0
- package/dist/testing.d.ts +291 -0
- package/dist/testing.js +263 -0
- package/dist/testing.js.map +1 -0
- package/dist/trace-context-DRZdUvVY.d.cts +181 -0
- package/dist/trace-context-DRZdUvVY.d.ts +181 -0
- package/dist/trace-helpers.cjs +54 -0
- package/dist/trace-helpers.cjs.map +1 -0
- package/dist/trace-helpers.d.cts +524 -0
- package/dist/trace-helpers.d.ts +524 -0
- package/dist/trace-helpers.js +5 -0
- package/dist/trace-helpers.js.map +1 -0
- package/dist/tracer-provider.cjs +21 -0
- package/dist/tracer-provider.cjs.map +1 -0
- package/dist/tracer-provider.d.cts +169 -0
- package/dist/tracer-provider.d.ts +169 -0
- package/dist/tracer-provider.js +4 -0
- package/dist/tracer-provider.js.map +1 -0
- package/package.json +280 -0
- package/src/baggage-span-processor.test.ts +202 -0
- package/src/baggage-span-processor.ts +98 -0
- package/src/circuit-breaker.test.ts +341 -0
- package/src/circuit-breaker.ts +184 -0
- package/src/config.test.ts +94 -0
- package/src/config.ts +169 -0
- package/src/db.test.ts +252 -0
- package/src/db.ts +447 -0
- package/src/decorators.test.ts +203 -0
- package/src/decorators.ts +188 -0
- package/src/env-config.test.ts +246 -0
- package/src/env-config.ts +158 -0
- package/src/event-queue.test.ts +222 -0
- package/src/event-queue.ts +203 -0
- package/src/event-subscriber.ts +136 -0
- package/src/event-testing.ts +197 -0
- package/src/event.test.ts +718 -0
- package/src/event.ts +556 -0
- package/src/exporters.ts +96 -0
- package/src/functional.test.ts +1059 -0
- package/src/functional.ts +2295 -0
- package/src/http.test.ts +487 -0
- package/src/http.ts +424 -0
- package/src/index.ts +158 -0
- package/src/init.customization.test.ts +210 -0
- package/src/init.integrations.test.ts +366 -0
- package/src/init.openllmetry.test.ts +282 -0
- package/src/init.protocol.test.ts +215 -0
- package/src/init.ts +1426 -0
- package/src/instrumentation.test.ts +108 -0
- package/src/instrumentation.ts +308 -0
- package/src/logger.test.ts +117 -0
- package/src/logger.ts +246 -0
- package/src/metric-helpers.ts +47 -0
- package/src/metric-testing.ts +197 -0
- package/src/metric.ts +434 -0
- package/src/metrics.test.ts +205 -0
- package/src/operation-context.ts +93 -0
- package/src/processors.ts +106 -0
- package/src/rate-limiter.test.ts +199 -0
- package/src/rate-limiter.ts +98 -0
- package/src/sampling.test.ts +513 -0
- package/src/sampling.ts +428 -0
- package/src/semantic-helpers.test.ts +311 -0
- package/src/semantic-helpers.ts +584 -0
- package/src/shutdown.test.ts +311 -0
- package/src/shutdown.ts +222 -0
- package/src/stub.integration.test.ts +361 -0
- package/src/tail-sampling-processor.test.ts +226 -0
- package/src/tail-sampling-processor.ts +51 -0
- package/src/testing.ts +670 -0
- package/src/trace-context.ts +470 -0
- package/src/trace-helpers.new.test.ts +278 -0
- package/src/trace-helpers.test.ts +242 -0
- package/src/trace-helpers.ts +690 -0
- package/src/tracer-provider.test.ts +183 -0
- package/src/tracer-provider.ts +266 -0
- package/src/track.test.ts +153 -0
- package/src/track.ts +120 -0
- package/src/validation.test.ts +306 -0
- package/src/validation.ts +239 -0
- package/src/variable-name-inference.test.ts +178 -0
- package/src/variable-name-inference.ts +242 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkHE6T6FIX_cjs = require('./chunk-HE6T6FIX.cjs');
|
|
4
|
+
require('./chunk-4OAT42CA.cjs');
|
|
5
|
+
require('./chunk-Y4Y2S7BM.cjs');
|
|
6
|
+
require('./chunk-URRW6M2C.cjs');
|
|
7
|
+
require('./chunk-G7VZBCD6.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Object.defineProperty(exports, "AdaptiveSampler", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return chunkHE6T6FIX_cjs.AdaptiveSampler; }
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "AlwaysSampler", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return chunkHE6T6FIX_cjs.AlwaysSampler; }
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "CompositeSampler", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return chunkHE6T6FIX_cjs.CompositeSampler; }
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports, "FeatureFlagSampler", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return chunkHE6T6FIX_cjs.FeatureFlagSampler; }
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(exports, "NeverSampler", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return chunkHE6T6FIX_cjs.NeverSampler; }
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "RandomSampler", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () { return chunkHE6T6FIX_cjs.RandomSampler; }
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, "UserIdSampler", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () { return chunkHE6T6FIX_cjs.UserIdSampler; }
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=sampling.cjs.map
|
|
40
|
+
//# sourceMappingURL=sampling.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"sampling.cjs"}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { Logger } from './logger.cjs';
|
|
2
|
+
import 'pino';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sampling Strategies
|
|
6
|
+
*
|
|
7
|
+
* Provides intelligent sampling beyond simple random rates.
|
|
8
|
+
* Helps reduce telemetry costs while capturing critical data.
|
|
9
|
+
*
|
|
10
|
+
* Key strategies:
|
|
11
|
+
* - Always trace errors and slow requests (critical for debugging)
|
|
12
|
+
* - Sample by user ID for consistent request tracing
|
|
13
|
+
* - Adaptive sampling based on load
|
|
14
|
+
* - Sample by feature flags for A/B testing correlation
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { AlwaysOnErrorSampler, UserIdSampler } from './sampling'
|
|
19
|
+
*
|
|
20
|
+
* @Instrumented({
|
|
21
|
+
* serviceName: 'user',
|
|
22
|
+
* sampler: new AlwaysOnErrorSampler(0.1) // 10% baseline, 100% on errors
|
|
23
|
+
* })
|
|
24
|
+
* class UserService { }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Sampler interface - return true to trace, false to skip
|
|
30
|
+
*/
|
|
31
|
+
interface Sampler {
|
|
32
|
+
/**
|
|
33
|
+
* Decide whether to trace this operation
|
|
34
|
+
*
|
|
35
|
+
* @param context - Sampling context
|
|
36
|
+
* @returns true to trace, false to skip
|
|
37
|
+
*/
|
|
38
|
+
shouldSample(context: SamplingContext): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Whether this sampler needs tail sampling (post-execution decision)
|
|
41
|
+
* If true, spans are always created and shouldKeepTrace() is called after execution
|
|
42
|
+
*
|
|
43
|
+
* @returns true if this sampler needs to evaluate after operation completes
|
|
44
|
+
*/
|
|
45
|
+
needsTailSampling?(): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Re-evaluate sampling decision after operation completes (tail sampling)
|
|
48
|
+
* Only called if needsTailSampling() returns true
|
|
49
|
+
*
|
|
50
|
+
* @param context - Sampling context
|
|
51
|
+
* @param result - Operation result
|
|
52
|
+
* @returns true if this trace should be kept, false to drop it
|
|
53
|
+
*/
|
|
54
|
+
shouldKeepTrace?(context: SamplingContext, result: OperationResult): boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Context information for sampling decisions
|
|
58
|
+
*/
|
|
59
|
+
interface SamplingContext {
|
|
60
|
+
/** Operation name */
|
|
61
|
+
operationName: string;
|
|
62
|
+
/** Method arguments (for extracting user IDs, etc.) */
|
|
63
|
+
args: unknown[];
|
|
64
|
+
/** Optional metadata (e.g., feature flags, request headers) */
|
|
65
|
+
metadata?: Record<string, unknown>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Result of a trace operation (for post-execution sampling)
|
|
69
|
+
*/
|
|
70
|
+
interface OperationResult {
|
|
71
|
+
/** Whether the operation succeeded */
|
|
72
|
+
success: boolean;
|
|
73
|
+
/** Duration in milliseconds */
|
|
74
|
+
duration: number;
|
|
75
|
+
/** Error if operation failed */
|
|
76
|
+
error?: Error;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Simple random sampler
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* new RandomSampler(0.1) // Sample 10% of requests
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
declare class RandomSampler implements Sampler {
|
|
87
|
+
private readonly sampleRate;
|
|
88
|
+
constructor(sampleRate: number);
|
|
89
|
+
shouldSample(_context: SamplingContext): boolean;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Always sample (100% tracing)
|
|
93
|
+
*/
|
|
94
|
+
declare class AlwaysSampler implements Sampler {
|
|
95
|
+
shouldSample(_context: SamplingContext): boolean;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Never sample (0% tracing)
|
|
99
|
+
*/
|
|
100
|
+
declare class NeverSampler implements Sampler {
|
|
101
|
+
shouldSample(_context: SamplingContext): boolean;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Adaptive sampler that always traces errors and slow requests
|
|
105
|
+
*
|
|
106
|
+
* This is the recommended sampler for production use.
|
|
107
|
+
* It ensures you never miss critical issues while keeping costs down.
|
|
108
|
+
*
|
|
109
|
+
* Strategy:
|
|
110
|
+
* - Always trace errors (critical for debugging)
|
|
111
|
+
* - Always trace slow requests (performance issues)
|
|
112
|
+
* - Use baseline sample rate for successful fast requests
|
|
113
|
+
*
|
|
114
|
+
* **IMPORTANT - Tail Sampling Requirement:**
|
|
115
|
+
* This sampler uses tail sampling (makes decisions AFTER execution).
|
|
116
|
+
* You MUST use TailSamplingSpanProcessor for it to work correctly:
|
|
117
|
+
*
|
|
118
|
+
* - If using initInstrumentation(): TailSamplingSpanProcessor is auto-configured
|
|
119
|
+
* - If using custom TracerProvider: You MUST manually register TailSamplingSpanProcessor
|
|
120
|
+
*
|
|
121
|
+
* Without TailSamplingSpanProcessor, ALL spans are exported (defeating the cost savings).
|
|
122
|
+
*
|
|
123
|
+
* @see TailSamplingSpanProcessor
|
|
124
|
+
* @see README.md "Tail Sampling with Custom Providers" section
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* new AdaptiveSampler({
|
|
129
|
+
* baselineSampleRate: 0.1, // 10% of normal requests
|
|
130
|
+
* slowThresholdMs: 1000, // Requests > 1s are "slow"
|
|
131
|
+
* alwaysSampleErrors: true, // Always trace errors
|
|
132
|
+
* alwaysSampleSlow: true // Always trace slow requests
|
|
133
|
+
* })
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
declare class AdaptiveSampler implements Sampler {
|
|
137
|
+
private baselineSampleRate;
|
|
138
|
+
private slowThresholdMs;
|
|
139
|
+
private alwaysSampleErrors;
|
|
140
|
+
private alwaysSampleSlow;
|
|
141
|
+
private logger?;
|
|
142
|
+
private readonly samplingDecisions;
|
|
143
|
+
private readonly operationResults;
|
|
144
|
+
constructor(options?: {
|
|
145
|
+
baselineSampleRate?: number;
|
|
146
|
+
slowThresholdMs?: number;
|
|
147
|
+
alwaysSampleErrors?: boolean;
|
|
148
|
+
alwaysSampleSlow?: boolean;
|
|
149
|
+
logger?: Logger;
|
|
150
|
+
});
|
|
151
|
+
needsTailSampling(): boolean;
|
|
152
|
+
shouldSample(context: SamplingContext): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Re-evaluate sampling decision after operation completes
|
|
155
|
+
*
|
|
156
|
+
* This allows us to always capture errors and slow requests,
|
|
157
|
+
* even if they weren't initially sampled.
|
|
158
|
+
*
|
|
159
|
+
* @param context - Sampling context
|
|
160
|
+
* @param result - Operation result
|
|
161
|
+
* @returns true if this operation should be kept (not discarded)
|
|
162
|
+
*/
|
|
163
|
+
shouldKeepTrace(context: SamplingContext, result: OperationResult): boolean;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* User-based sampler for consistent tracing
|
|
167
|
+
*
|
|
168
|
+
* Always samples requests from specific user IDs.
|
|
169
|
+
* Useful for debugging specific user issues or monitoring VIP users.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* new UserIdSampler({
|
|
174
|
+
* baselineSampleRate: 0.01, // 1% of normal users
|
|
175
|
+
* alwaysSampleUsers: ['vip_123'], // Always trace VIP users
|
|
176
|
+
* extractUserId: (args) => args[0]?.userId // Extract user ID from first arg
|
|
177
|
+
* })
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
declare class UserIdSampler implements Sampler {
|
|
181
|
+
private baselineSampleRate;
|
|
182
|
+
private alwaysSampleUsers;
|
|
183
|
+
private extractUserId;
|
|
184
|
+
private logger?;
|
|
185
|
+
constructor(options: {
|
|
186
|
+
baselineSampleRate?: number;
|
|
187
|
+
alwaysSampleUsers?: string[];
|
|
188
|
+
extractUserId: (args: unknown[]) => string | undefined;
|
|
189
|
+
logger?: Logger;
|
|
190
|
+
});
|
|
191
|
+
shouldSample(context: SamplingContext): boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Add user IDs to always-sample list
|
|
194
|
+
*/
|
|
195
|
+
addAlwaysSampleUsers(...userIds: string[]): void;
|
|
196
|
+
/**
|
|
197
|
+
* Remove user IDs from always-sample list
|
|
198
|
+
*/
|
|
199
|
+
removeAlwaysSampleUsers(...userIds: string[]): void;
|
|
200
|
+
/**
|
|
201
|
+
* Simple hash function for consistent user sampling
|
|
202
|
+
*/
|
|
203
|
+
private hashString;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Composite sampler that combines multiple samplers
|
|
207
|
+
*
|
|
208
|
+
* Samples if ANY of the child samplers returns true.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* new CompositeSampler([
|
|
213
|
+
* new UserIdSampler({ extractUserId: (args) => args[0]?.userId }),
|
|
214
|
+
* new AdaptiveSampler({ baselineSampleRate: 0.1 })
|
|
215
|
+
* ])
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
declare class CompositeSampler implements Sampler {
|
|
219
|
+
private readonly samplers;
|
|
220
|
+
constructor(samplers: Sampler[]);
|
|
221
|
+
shouldSample(context: SamplingContext): boolean;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Feature flag sampler
|
|
225
|
+
*
|
|
226
|
+
* Always samples requests with specific feature flags enabled.
|
|
227
|
+
* Perfect for correlating A/B test experiments with metrics.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* new FeatureFlagSampler({
|
|
232
|
+
* baselineSampleRate: 0.01,
|
|
233
|
+
* alwaysSampleFlags: ['new_checkout', 'experimental_ui'],
|
|
234
|
+
* extractFlags: (args, metadata) => metadata?.featureFlags
|
|
235
|
+
* })
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
declare class FeatureFlagSampler implements Sampler {
|
|
239
|
+
private baselineSampleRate;
|
|
240
|
+
private alwaysSampleFlags;
|
|
241
|
+
private extractFlags;
|
|
242
|
+
private logger?;
|
|
243
|
+
constructor(options: {
|
|
244
|
+
baselineSampleRate?: number;
|
|
245
|
+
alwaysSampleFlags?: string[];
|
|
246
|
+
extractFlags: (args: unknown[], metadata?: Record<string, unknown>) => string[] | undefined;
|
|
247
|
+
logger?: Logger;
|
|
248
|
+
});
|
|
249
|
+
shouldSample(context: SamplingContext): boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Add feature flags to always-sample list
|
|
252
|
+
*/
|
|
253
|
+
addAlwaysSampleFlags(...flags: string[]): void;
|
|
254
|
+
/**
|
|
255
|
+
* Remove feature flags from always-sample list
|
|
256
|
+
*/
|
|
257
|
+
removeAlwaysSampleFlags(...flags: string[]): void;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export { AdaptiveSampler, AlwaysSampler, CompositeSampler, FeatureFlagSampler, NeverSampler, type OperationResult, RandomSampler, type Sampler, type SamplingContext, UserIdSampler };
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { Logger } from './logger.js';
|
|
2
|
+
import 'pino';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sampling Strategies
|
|
6
|
+
*
|
|
7
|
+
* Provides intelligent sampling beyond simple random rates.
|
|
8
|
+
* Helps reduce telemetry costs while capturing critical data.
|
|
9
|
+
*
|
|
10
|
+
* Key strategies:
|
|
11
|
+
* - Always trace errors and slow requests (critical for debugging)
|
|
12
|
+
* - Sample by user ID for consistent request tracing
|
|
13
|
+
* - Adaptive sampling based on load
|
|
14
|
+
* - Sample by feature flags for A/B testing correlation
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { AlwaysOnErrorSampler, UserIdSampler } from './sampling'
|
|
19
|
+
*
|
|
20
|
+
* @Instrumented({
|
|
21
|
+
* serviceName: 'user',
|
|
22
|
+
* sampler: new AlwaysOnErrorSampler(0.1) // 10% baseline, 100% on errors
|
|
23
|
+
* })
|
|
24
|
+
* class UserService { }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Sampler interface - return true to trace, false to skip
|
|
30
|
+
*/
|
|
31
|
+
interface Sampler {
|
|
32
|
+
/**
|
|
33
|
+
* Decide whether to trace this operation
|
|
34
|
+
*
|
|
35
|
+
* @param context - Sampling context
|
|
36
|
+
* @returns true to trace, false to skip
|
|
37
|
+
*/
|
|
38
|
+
shouldSample(context: SamplingContext): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Whether this sampler needs tail sampling (post-execution decision)
|
|
41
|
+
* If true, spans are always created and shouldKeepTrace() is called after execution
|
|
42
|
+
*
|
|
43
|
+
* @returns true if this sampler needs to evaluate after operation completes
|
|
44
|
+
*/
|
|
45
|
+
needsTailSampling?(): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Re-evaluate sampling decision after operation completes (tail sampling)
|
|
48
|
+
* Only called if needsTailSampling() returns true
|
|
49
|
+
*
|
|
50
|
+
* @param context - Sampling context
|
|
51
|
+
* @param result - Operation result
|
|
52
|
+
* @returns true if this trace should be kept, false to drop it
|
|
53
|
+
*/
|
|
54
|
+
shouldKeepTrace?(context: SamplingContext, result: OperationResult): boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Context information for sampling decisions
|
|
58
|
+
*/
|
|
59
|
+
interface SamplingContext {
|
|
60
|
+
/** Operation name */
|
|
61
|
+
operationName: string;
|
|
62
|
+
/** Method arguments (for extracting user IDs, etc.) */
|
|
63
|
+
args: unknown[];
|
|
64
|
+
/** Optional metadata (e.g., feature flags, request headers) */
|
|
65
|
+
metadata?: Record<string, unknown>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Result of a trace operation (for post-execution sampling)
|
|
69
|
+
*/
|
|
70
|
+
interface OperationResult {
|
|
71
|
+
/** Whether the operation succeeded */
|
|
72
|
+
success: boolean;
|
|
73
|
+
/** Duration in milliseconds */
|
|
74
|
+
duration: number;
|
|
75
|
+
/** Error if operation failed */
|
|
76
|
+
error?: Error;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Simple random sampler
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* new RandomSampler(0.1) // Sample 10% of requests
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
declare class RandomSampler implements Sampler {
|
|
87
|
+
private readonly sampleRate;
|
|
88
|
+
constructor(sampleRate: number);
|
|
89
|
+
shouldSample(_context: SamplingContext): boolean;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Always sample (100% tracing)
|
|
93
|
+
*/
|
|
94
|
+
declare class AlwaysSampler implements Sampler {
|
|
95
|
+
shouldSample(_context: SamplingContext): boolean;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Never sample (0% tracing)
|
|
99
|
+
*/
|
|
100
|
+
declare class NeverSampler implements Sampler {
|
|
101
|
+
shouldSample(_context: SamplingContext): boolean;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Adaptive sampler that always traces errors and slow requests
|
|
105
|
+
*
|
|
106
|
+
* This is the recommended sampler for production use.
|
|
107
|
+
* It ensures you never miss critical issues while keeping costs down.
|
|
108
|
+
*
|
|
109
|
+
* Strategy:
|
|
110
|
+
* - Always trace errors (critical for debugging)
|
|
111
|
+
* - Always trace slow requests (performance issues)
|
|
112
|
+
* - Use baseline sample rate for successful fast requests
|
|
113
|
+
*
|
|
114
|
+
* **IMPORTANT - Tail Sampling Requirement:**
|
|
115
|
+
* This sampler uses tail sampling (makes decisions AFTER execution).
|
|
116
|
+
* You MUST use TailSamplingSpanProcessor for it to work correctly:
|
|
117
|
+
*
|
|
118
|
+
* - If using initInstrumentation(): TailSamplingSpanProcessor is auto-configured
|
|
119
|
+
* - If using custom TracerProvider: You MUST manually register TailSamplingSpanProcessor
|
|
120
|
+
*
|
|
121
|
+
* Without TailSamplingSpanProcessor, ALL spans are exported (defeating the cost savings).
|
|
122
|
+
*
|
|
123
|
+
* @see TailSamplingSpanProcessor
|
|
124
|
+
* @see README.md "Tail Sampling with Custom Providers" section
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* new AdaptiveSampler({
|
|
129
|
+
* baselineSampleRate: 0.1, // 10% of normal requests
|
|
130
|
+
* slowThresholdMs: 1000, // Requests > 1s are "slow"
|
|
131
|
+
* alwaysSampleErrors: true, // Always trace errors
|
|
132
|
+
* alwaysSampleSlow: true // Always trace slow requests
|
|
133
|
+
* })
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
declare class AdaptiveSampler implements Sampler {
|
|
137
|
+
private baselineSampleRate;
|
|
138
|
+
private slowThresholdMs;
|
|
139
|
+
private alwaysSampleErrors;
|
|
140
|
+
private alwaysSampleSlow;
|
|
141
|
+
private logger?;
|
|
142
|
+
private readonly samplingDecisions;
|
|
143
|
+
private readonly operationResults;
|
|
144
|
+
constructor(options?: {
|
|
145
|
+
baselineSampleRate?: number;
|
|
146
|
+
slowThresholdMs?: number;
|
|
147
|
+
alwaysSampleErrors?: boolean;
|
|
148
|
+
alwaysSampleSlow?: boolean;
|
|
149
|
+
logger?: Logger;
|
|
150
|
+
});
|
|
151
|
+
needsTailSampling(): boolean;
|
|
152
|
+
shouldSample(context: SamplingContext): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Re-evaluate sampling decision after operation completes
|
|
155
|
+
*
|
|
156
|
+
* This allows us to always capture errors and slow requests,
|
|
157
|
+
* even if they weren't initially sampled.
|
|
158
|
+
*
|
|
159
|
+
* @param context - Sampling context
|
|
160
|
+
* @param result - Operation result
|
|
161
|
+
* @returns true if this operation should be kept (not discarded)
|
|
162
|
+
*/
|
|
163
|
+
shouldKeepTrace(context: SamplingContext, result: OperationResult): boolean;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* User-based sampler for consistent tracing
|
|
167
|
+
*
|
|
168
|
+
* Always samples requests from specific user IDs.
|
|
169
|
+
* Useful for debugging specific user issues or monitoring VIP users.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* new UserIdSampler({
|
|
174
|
+
* baselineSampleRate: 0.01, // 1% of normal users
|
|
175
|
+
* alwaysSampleUsers: ['vip_123'], // Always trace VIP users
|
|
176
|
+
* extractUserId: (args) => args[0]?.userId // Extract user ID from first arg
|
|
177
|
+
* })
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
declare class UserIdSampler implements Sampler {
|
|
181
|
+
private baselineSampleRate;
|
|
182
|
+
private alwaysSampleUsers;
|
|
183
|
+
private extractUserId;
|
|
184
|
+
private logger?;
|
|
185
|
+
constructor(options: {
|
|
186
|
+
baselineSampleRate?: number;
|
|
187
|
+
alwaysSampleUsers?: string[];
|
|
188
|
+
extractUserId: (args: unknown[]) => string | undefined;
|
|
189
|
+
logger?: Logger;
|
|
190
|
+
});
|
|
191
|
+
shouldSample(context: SamplingContext): boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Add user IDs to always-sample list
|
|
194
|
+
*/
|
|
195
|
+
addAlwaysSampleUsers(...userIds: string[]): void;
|
|
196
|
+
/**
|
|
197
|
+
* Remove user IDs from always-sample list
|
|
198
|
+
*/
|
|
199
|
+
removeAlwaysSampleUsers(...userIds: string[]): void;
|
|
200
|
+
/**
|
|
201
|
+
* Simple hash function for consistent user sampling
|
|
202
|
+
*/
|
|
203
|
+
private hashString;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Composite sampler that combines multiple samplers
|
|
207
|
+
*
|
|
208
|
+
* Samples if ANY of the child samplers returns true.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* new CompositeSampler([
|
|
213
|
+
* new UserIdSampler({ extractUserId: (args) => args[0]?.userId }),
|
|
214
|
+
* new AdaptiveSampler({ baselineSampleRate: 0.1 })
|
|
215
|
+
* ])
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
declare class CompositeSampler implements Sampler {
|
|
219
|
+
private readonly samplers;
|
|
220
|
+
constructor(samplers: Sampler[]);
|
|
221
|
+
shouldSample(context: SamplingContext): boolean;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Feature flag sampler
|
|
225
|
+
*
|
|
226
|
+
* Always samples requests with specific feature flags enabled.
|
|
227
|
+
* Perfect for correlating A/B test experiments with metrics.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* new FeatureFlagSampler({
|
|
232
|
+
* baselineSampleRate: 0.01,
|
|
233
|
+
* alwaysSampleFlags: ['new_checkout', 'experimental_ui'],
|
|
234
|
+
* extractFlags: (args, metadata) => metadata?.featureFlags
|
|
235
|
+
* })
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
declare class FeatureFlagSampler implements Sampler {
|
|
239
|
+
private baselineSampleRate;
|
|
240
|
+
private alwaysSampleFlags;
|
|
241
|
+
private extractFlags;
|
|
242
|
+
private logger?;
|
|
243
|
+
constructor(options: {
|
|
244
|
+
baselineSampleRate?: number;
|
|
245
|
+
alwaysSampleFlags?: string[];
|
|
246
|
+
extractFlags: (args: unknown[], metadata?: Record<string, unknown>) => string[] | undefined;
|
|
247
|
+
logger?: Logger;
|
|
248
|
+
});
|
|
249
|
+
shouldSample(context: SamplingContext): boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Add feature flags to always-sample list
|
|
252
|
+
*/
|
|
253
|
+
addAlwaysSampleFlags(...flags: string[]): void;
|
|
254
|
+
/**
|
|
255
|
+
* Remove feature flags from always-sample list
|
|
256
|
+
*/
|
|
257
|
+
removeAlwaysSampleFlags(...flags: string[]): void;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export { AdaptiveSampler, AlwaysSampler, CompositeSampler, FeatureFlagSampler, NeverSampler, type OperationResult, RandomSampler, type Sampler, type SamplingContext, UserIdSampler };
|
package/dist/sampling.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { AdaptiveSampler, AlwaysSampler, CompositeSampler, FeatureFlagSampler, NeverSampler, RandomSampler, UserIdSampler } from './chunk-5R2M36QB.js';
|
|
2
|
+
import './chunk-5GWX5LFW.js';
|
|
3
|
+
import './chunk-KVGNW3FC.js';
|
|
4
|
+
import './chunk-P6JUDYNO.js';
|
|
5
|
+
import './chunk-Z6ZWNWWR.js';
|
|
6
|
+
//# sourceMappingURL=sampling.js.map
|
|
7
|
+
//# sourceMappingURL=sampling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"sampling.js"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkKIXWPOCO_cjs = require('./chunk-KIXWPOCO.cjs');
|
|
4
|
+
require('./chunk-WBWNM6LB.cjs');
|
|
5
|
+
require('./chunk-TRI4V5BF.cjs');
|
|
6
|
+
require('./chunk-NHCNRQD3.cjs');
|
|
7
|
+
require('./chunk-YLPNXZFI.cjs');
|
|
8
|
+
require('./chunk-ABPEQ6RK.cjs');
|
|
9
|
+
require('./chunk-GVLK7YUU.cjs');
|
|
10
|
+
require('./chunk-HE6T6FIX.cjs');
|
|
11
|
+
require('./chunk-4OAT42CA.cjs');
|
|
12
|
+
require('./chunk-Y4Y2S7BM.cjs');
|
|
13
|
+
require('./chunk-URRW6M2C.cjs');
|
|
14
|
+
require('./chunk-G7VZBCD6.cjs');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
Object.defineProperty(exports, "traceDB", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return chunkKIXWPOCO_cjs.traceDB; }
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports, "traceHTTP", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () { return chunkKIXWPOCO_cjs.traceHTTP; }
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(exports, "traceLLM", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () { return chunkKIXWPOCO_cjs.traceLLM; }
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "traceMessaging", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () { return chunkKIXWPOCO_cjs.traceMessaging; }
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=semantic-helpers.cjs.map
|
|
35
|
+
//# sourceMappingURL=semantic-helpers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"semantic-helpers.cjs"}
|