netra-sdk 1.5.0 → 1.7.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/dist/index.cjs +1093 -514
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +258 -95
- package/dist/index.d.ts +258 -95
- package/dist/index.js +1085 -508
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.d.cts
CHANGED
|
@@ -18,6 +18,26 @@ interface NetraConfig {
|
|
|
18
18
|
blockedSpans?: string[];
|
|
19
19
|
instruments?: Set<NetraInstruments>;
|
|
20
20
|
blockInstruments?: Set<NetraInstruments>;
|
|
21
|
+
/**
|
|
22
|
+
* Set of instruments allowed to produce root-level spans. Independent of
|
|
23
|
+
* `instruments`. Defaults to `DEFAULT_INSTRUMENTS_FOR_ROOT` when omitted.
|
|
24
|
+
*
|
|
25
|
+
* When a root span comes from an instrumentation outside this set, only that
|
|
26
|
+
* span is dropped — its children are reparented onto its parent (a true
|
|
27
|
+
* root's children become the new roots). The peel then repeats: if a promoted
|
|
28
|
+
* child is itself from a non-root instrumentation it is dropped too,
|
|
29
|
+
* recursively, until a surviving span is reached (an allowed instrument, a
|
|
30
|
+
* Netra decorator / manual span, or any non-instrumentation span). This keeps
|
|
31
|
+
* LLM/vector spans that originate under an unwanted server root (e.g.
|
|
32
|
+
* Express/HTTP) without emitting the server span itself. A span whose parent
|
|
33
|
+
* link is remote (cross-process) is kept as a root so an upstream distributed
|
|
34
|
+
* trace is not severed.
|
|
35
|
+
*
|
|
36
|
+
* Note: when `enableRootSpan` is true, Netra attaches its own root span and
|
|
37
|
+
* every auto-instrumentation span becomes its child, so no reparenting
|
|
38
|
+
* occurs. Pass a set containing `NetraInstruments.ALL` to allow all
|
|
39
|
+
* instrumentations to produce root spans (legacy behaviour).
|
|
40
|
+
*/
|
|
21
41
|
rootInstruments?: Set<NetraInstruments>;
|
|
22
42
|
}
|
|
23
43
|
declare enum NetraInstruments {
|
|
@@ -60,11 +80,15 @@ declare const DEFAULT_INSTRUMENTS: Set<NetraInstruments>;
|
|
|
60
80
|
declare class Config {
|
|
61
81
|
static readonly SDK_NAME = "netra";
|
|
62
82
|
static readonly LIBRARY_NAME = "netra";
|
|
63
|
-
static readonly LIBRARY_VERSION = "1.
|
|
83
|
+
static readonly LIBRARY_VERSION = "1.6.0";
|
|
64
84
|
static readonly TRIAL_BLOCK_DURATION_SECONDS = 900;
|
|
65
|
-
static
|
|
66
|
-
|
|
67
|
-
|
|
85
|
+
private static _spanAttributeMaxSize;
|
|
86
|
+
/**
|
|
87
|
+
* Lazily reads NETRA_SPAN_ATTRIBUTE_MAX_SIZE from process.env on first
|
|
88
|
+
* access so that env vars set before Netra.init() (via dotenv, shell
|
|
89
|
+
* export, Docker, etc.) are always respected regardless of import order.
|
|
90
|
+
*/
|
|
91
|
+
static get SPAN_ATTRIBUTE_MAX_SIZE(): number;
|
|
68
92
|
appName: string;
|
|
69
93
|
otlpEndpoint?: string;
|
|
70
94
|
apiKey?: string;
|
|
@@ -851,109 +875,76 @@ declare class Prompts {
|
|
|
851
875
|
}
|
|
852
876
|
|
|
853
877
|
/**
|
|
854
|
-
*
|
|
878
|
+
* Instrumentation Span Processor
|
|
855
879
|
*
|
|
856
|
-
*
|
|
857
|
-
*
|
|
880
|
+
* OpenTelemetry span processor that records the raw instrumentation scope
|
|
881
|
+
* name for each span. This enables downstream processors and the dashboard
|
|
882
|
+
* to identify which provider/framework produced a given span.
|
|
858
883
|
*/
|
|
859
884
|
|
|
860
|
-
declare class
|
|
861
|
-
private
|
|
862
|
-
constructor(maxAttributeSize?: number);
|
|
885
|
+
declare class InstrumentationSpanProcessor implements SpanProcessor {
|
|
886
|
+
private detectRawInstrumentationName;
|
|
863
887
|
onStart(span: Span, _parentContext: Context): void;
|
|
864
888
|
onEnd(_span: ReadableSpan): void;
|
|
865
889
|
shutdown(): Promise<void>;
|
|
866
890
|
forceFlush(): Promise<void>;
|
|
867
|
-
private _wrapSetAttribute;
|
|
868
891
|
}
|
|
869
892
|
|
|
893
|
+
declare function withBlockedSpansLocal<T>(patterns: readonly string[], fn: () => Promise<T>): Promise<T>;
|
|
894
|
+
declare function withBlockedSpansLocal<T>(patterns: readonly string[], fn: () => T): T;
|
|
895
|
+
|
|
870
896
|
/**
|
|
871
|
-
*
|
|
897
|
+
* Scrubbing Span Processor
|
|
898
|
+
*
|
|
899
|
+
* OpenTelemetry span processor that scrubs sensitive data from span attributes
|
|
900
|
+
* at write time via setAttribute wrapping. This includes API keys, emails,
|
|
901
|
+
* phone numbers, SSNs, credit cards, passwords, bearer tokens, and other
|
|
902
|
+
* sensitive information.
|
|
872
903
|
*
|
|
873
|
-
*
|
|
874
|
-
*
|
|
875
|
-
*
|
|
904
|
+
* Handles both pre-serialized string values (the normal path when
|
|
905
|
+
* SerializationSpanProcessor is active) and raw objects/arrays (defensive
|
|
906
|
+
* fallback for custom pipelines that skip serialization).
|
|
907
|
+
*
|
|
908
|
+
* Wraps in onStart to avoid unreliable _attributes mutation in onEnd.
|
|
909
|
+
* MUST be registered BEFORE SerializationSpanProcessor so it forms the
|
|
910
|
+
* innermost layer (closest to OTel storage). Because serialization wraps
|
|
911
|
+
* outside this layer, values are serialized to strings first, then this
|
|
912
|
+
* processor scrubs sensitive patterns from the resulting string values.
|
|
876
913
|
*/
|
|
877
914
|
|
|
878
|
-
declare class
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
/**
|
|
882
|
-
* Detect the raw instrumentation name from the span's instrumentation scope.
|
|
883
|
-
*/
|
|
884
|
-
private detectRawInstrumentationName;
|
|
885
|
-
/**
|
|
886
|
-
* Truncate a value to the maximum allowed length.
|
|
887
|
-
* Handles strings, bytes, and recursively handles lists and objects.
|
|
888
|
-
*/
|
|
889
|
-
private truncateValue;
|
|
890
|
-
/**
|
|
891
|
-
* Called when a span starts. Wraps setAttribute to truncate values
|
|
892
|
-
* and records the instrumentation name.
|
|
893
|
-
*/
|
|
894
|
-
onStart(span: Span, parentContext: Context): void;
|
|
895
|
-
/**
|
|
896
|
-
* Called when a span ends. No-op for this processor.
|
|
897
|
-
*/
|
|
898
|
-
onEnd(span: ReadableSpan): void;
|
|
899
|
-
/**
|
|
900
|
-
* Shuts down the processor.
|
|
901
|
-
*/
|
|
915
|
+
declare class ScrubbingSpanProcessor implements SpanProcessor {
|
|
916
|
+
onStart(span: Span, _parentContext: Context): void;
|
|
917
|
+
onEnd(_span: ReadableSpan): void;
|
|
902
918
|
shutdown(): Promise<void>;
|
|
903
|
-
/**
|
|
904
|
-
* Forces a flush of any pending spans.
|
|
905
|
-
*/
|
|
906
919
|
forceFlush(): Promise<void>;
|
|
920
|
+
private wrapSetAttribute;
|
|
907
921
|
}
|
|
908
922
|
|
|
909
|
-
declare function withBlockedSpansLocal<T>(patterns: readonly string[], fn: () => Promise<T>): Promise<T>;
|
|
910
|
-
declare function withBlockedSpansLocal<T>(patterns: readonly string[], fn: () => T): T;
|
|
911
|
-
|
|
912
923
|
/**
|
|
913
|
-
*
|
|
924
|
+
* Serialization Span Processor
|
|
925
|
+
*
|
|
926
|
+
* Single enforcement point for attribute serialization and truncation.
|
|
927
|
+
* Wraps span.setAttribute in onStart so every value is serialized and
|
|
928
|
+
* truncated at write time. Uses jsonrepair-based truncation for JSON
|
|
929
|
+
* values and `...[TRUNCATED]` suffix for plain strings, aligned with
|
|
930
|
+
* backend behavior.
|
|
914
931
|
*
|
|
915
|
-
*
|
|
916
|
-
*
|
|
917
|
-
*
|
|
932
|
+
* MUST be registered AFTER ScrubbingSpanProcessor so it wraps outside
|
|
933
|
+
* the scrubbing layer. In the resulting call chain, serialization runs
|
|
934
|
+
* before scrubbing — converting objects to JSON strings so the
|
|
935
|
+
* regex-based scrubber can detect sensitive patterns in string form.
|
|
936
|
+
* All values, including those assembled by SpanIOProcessor, pass
|
|
937
|
+
* through serialization → scrubbing before reaching OTel storage.
|
|
918
938
|
*/
|
|
919
939
|
|
|
920
|
-
declare class
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
/**
|
|
926
|
-
* Scrub sensitive patterns from a string value.
|
|
927
|
-
*/
|
|
928
|
-
private scrubStringValue;
|
|
929
|
-
/**
|
|
930
|
-
* Recursively scrub sensitive data from a dictionary value.
|
|
931
|
-
*/
|
|
932
|
-
private scrubDictValue;
|
|
933
|
-
/**
|
|
934
|
-
* Recursively scrub sensitive data from a list value.
|
|
935
|
-
*/
|
|
936
|
-
private scrubListValue;
|
|
937
|
-
/**
|
|
938
|
-
* Scrub sensitive data from a key-value pair.
|
|
939
|
-
*/
|
|
940
|
-
private scrubKeyValue;
|
|
941
|
-
/**
|
|
942
|
-
* Called when a span starts. No-op for this processor.
|
|
943
|
-
*/
|
|
944
|
-
onStart(span: Span, parentContext: Context): void;
|
|
945
|
-
/**
|
|
946
|
-
* Called when a span ends. Scrubs sensitive data from span attributes.
|
|
947
|
-
*/
|
|
948
|
-
onEnd(span: ReadableSpan): void;
|
|
949
|
-
/**
|
|
950
|
-
* Shuts down the processor.
|
|
951
|
-
*/
|
|
940
|
+
declare class SerializationSpanProcessor implements SpanProcessor {
|
|
941
|
+
private readonly maxAttributeSize;
|
|
942
|
+
constructor(maxAttributeSize?: number);
|
|
943
|
+
onStart(span: Span, _parentContext: Context): void;
|
|
944
|
+
onEnd(_span: ReadableSpan): void;
|
|
952
945
|
shutdown(): Promise<void>;
|
|
953
|
-
/**
|
|
954
|
-
* Forces a flush of any pending spans.
|
|
955
|
-
*/
|
|
956
946
|
forceFlush(): Promise<void>;
|
|
947
|
+
private wrapSetAttribute;
|
|
957
948
|
}
|
|
958
949
|
|
|
959
950
|
/**
|
|
@@ -1083,6 +1074,68 @@ interface DecoratorOptions {
|
|
|
1083
1074
|
}
|
|
1084
1075
|
type SpanCallback<T> = (span: SpanWrapper) => T;
|
|
1085
1076
|
|
|
1077
|
+
/**
|
|
1078
|
+
* Pre/post script hooks for multi-turn simulation runs.
|
|
1079
|
+
*
|
|
1080
|
+
* Hooks let you run setup and teardown logic around scenario execution
|
|
1081
|
+
* without merging all scenarios into one or relying on sequential ordering.
|
|
1082
|
+
*
|
|
1083
|
+
* Hook levels:
|
|
1084
|
+
* beforeAll -- runs once before any scenario starts (dataset-level setup)
|
|
1085
|
+
* beforeEach -- runs before every scenario (common per-item setup)
|
|
1086
|
+
* before -- runs before specific scenarios only (item-specific setup, keyed by datasetItemId)
|
|
1087
|
+
* after -- runs after specific scenarios only (item-specific teardown, keyed by datasetItemId)
|
|
1088
|
+
* afterEach -- runs after every scenario (common per-item teardown)
|
|
1089
|
+
* afterAll -- runs once after all scenarios complete (dataset-level teardown)
|
|
1090
|
+
*
|
|
1091
|
+
* Execution order per item:
|
|
1092
|
+
* beforeAll() -> returns sharedContext (Record | null)
|
|
1093
|
+
* beforeEach(sharedContext) -> returns eachContext (Record | null)
|
|
1094
|
+
* before[datasetItemId](mergedContext) -> returns itemContext (Record | null), if registered
|
|
1095
|
+
* BaseTask.run(..., setupContext) <- receives merged context
|
|
1096
|
+
* after[datasetItemId](result, setupContext), if registered
|
|
1097
|
+
* afterEach(result, setupContext)
|
|
1098
|
+
* afterAll(results, sharedContext)
|
|
1099
|
+
*
|
|
1100
|
+
* Failure semantics:
|
|
1101
|
+
* - beforeAll failure -> entire run is marked failed (prescript_failed), no scenarios run
|
|
1102
|
+
* - beforeEach failure -> that scenario is marked failed (prescript_failed), others continue
|
|
1103
|
+
* - before failure -> that scenario is marked failed (prescript_failed), others continue
|
|
1104
|
+
* - after / afterEach / afterAll failures are logged as warnings and do not affect run/scenario status
|
|
1105
|
+
*/
|
|
1106
|
+
/** Hook that runs once before any scenario starts. May return shared context. */
|
|
1107
|
+
type BeforeAllFn = () => Record<string, any> | null | void | Promise<Record<string, any> | null | void>;
|
|
1108
|
+
/** Hook that runs before every scenario. Receives shared context, may return per-item context. */
|
|
1109
|
+
type BeforeEachFn = (sharedContext: Record<string, any> | null) => Record<string, any> | null | void | Promise<Record<string, any> | null | void>;
|
|
1110
|
+
/** Hook that runs before a specific scenario. Receives merged context, may return item context. */
|
|
1111
|
+
type BeforeFn = (sharedContext: Record<string, any> | null) => Record<string, any> | null | void | Promise<Record<string, any> | null | void>;
|
|
1112
|
+
/** Hook that runs after a specific scenario. Receives result and setup context. */
|
|
1113
|
+
type AfterFn = (itemResult: Record<string, any>, setupContext: Record<string, any> | null) => void | Promise<void>;
|
|
1114
|
+
/** Hook that runs after every scenario. Receives result and setup context. */
|
|
1115
|
+
type AfterEachFn = (itemResult: Record<string, any>, setupContext: Record<string, any> | null) => void | Promise<void>;
|
|
1116
|
+
/** Hook that runs once after all scenarios complete. Receives aggregated results and shared context. */
|
|
1117
|
+
type AfterAllFn = (results: Record<string, any>, sharedContext: Record<string, any> | null) => void | Promise<void>;
|
|
1118
|
+
/**
|
|
1119
|
+
* Container for lifecycle hook functions attached to a simulation run.
|
|
1120
|
+
*
|
|
1121
|
+
* All hooks are optional. When a hook is not provided the corresponding
|
|
1122
|
+
* lifecycle phase is silently skipped.
|
|
1123
|
+
*/
|
|
1124
|
+
interface SimulationHooks {
|
|
1125
|
+
/** Called once before any scenario starts. May return a dict forwarded as sharedContext. */
|
|
1126
|
+
beforeAll?: BeforeAllFn;
|
|
1127
|
+
/** Called before every scenario. Receives sharedContext, may return per-item context merged into setupContext. */
|
|
1128
|
+
beforeEach?: BeforeEachFn;
|
|
1129
|
+
/** Dict mapping datasetItemId to hook functions. Called before specific scenarios only. */
|
|
1130
|
+
before?: Record<string, BeforeFn>;
|
|
1131
|
+
/** Dict mapping datasetItemId to hook functions. Called after specific scenarios only. */
|
|
1132
|
+
after?: Record<string, AfterFn>;
|
|
1133
|
+
/** Called after every scenario. Receives the item result and setupContext. */
|
|
1134
|
+
afterEach?: AfterEachFn;
|
|
1135
|
+
/** Called once after all scenarios finish. Receives aggregated results and sharedContext. */
|
|
1136
|
+
afterAll?: AfterAllFn;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1086
1139
|
/**
|
|
1087
1140
|
* Raw file metadata received from the backend.
|
|
1088
1141
|
*
|
|
@@ -1114,6 +1167,7 @@ interface ProcessedFile {
|
|
|
1114
1167
|
*/
|
|
1115
1168
|
interface SimulationItem {
|
|
1116
1169
|
runItemId: string;
|
|
1170
|
+
datasetItemId: string;
|
|
1117
1171
|
message: string;
|
|
1118
1172
|
turnId: string;
|
|
1119
1173
|
files?: FileData[];
|
|
@@ -1164,11 +1218,15 @@ declare abstract class BaseTask {
|
|
|
1164
1218
|
* @param sessionId - The session identifier.
|
|
1165
1219
|
* @param files - Optional list of base64-encoded file attachments from the
|
|
1166
1220
|
* dataset item. Will be `null` when no files are attached.
|
|
1221
|
+
* @param setupContext - Optional dict populated by `beforeAll` and `before`
|
|
1222
|
+
* hooks. Will be `null` when no hooks are configured.
|
|
1223
|
+
* Use this to access shared resources (e.g. a pre-created
|
|
1224
|
+
* employee ID) set up before the scenario started.
|
|
1167
1225
|
* @returns The task result containing:
|
|
1168
1226
|
* - message (string): The response message from the task.
|
|
1169
1227
|
* - sessionId (string): The session identifier.
|
|
1170
1228
|
*/
|
|
1171
|
-
abstract run(message: string, sessionId?: string | null, files?: ProcessedFile[] | null): Promise<TaskResult> | TaskResult;
|
|
1229
|
+
abstract run(message: string, sessionId?: string | null, files?: ProcessedFile[] | null, setupContext?: Record<string, any> | null): Promise<TaskResult> | TaskResult;
|
|
1172
1230
|
}
|
|
1173
1231
|
|
|
1174
1232
|
/**
|
|
@@ -1181,6 +1239,7 @@ interface SimulationOptions {
|
|
|
1181
1239
|
task: BaseTask;
|
|
1182
1240
|
context?: Record<string, any>;
|
|
1183
1241
|
maxConcurrency?: number;
|
|
1242
|
+
hooks?: SimulationHooks;
|
|
1184
1243
|
}
|
|
1185
1244
|
/**
|
|
1186
1245
|
* Public API for running multi-turn conversation simulations.
|
|
@@ -1192,26 +1251,39 @@ declare class Simulation {
|
|
|
1192
1251
|
/**
|
|
1193
1252
|
* Run a multi-turn conversation simulation.
|
|
1194
1253
|
*
|
|
1254
|
+
* Uses the two-phase API flow:
|
|
1255
|
+
* 1. initializeRun (no LLM cost) — with optional lifecycle hooks metadata
|
|
1256
|
+
* 2. beforeAll hook (if configured)
|
|
1257
|
+
* 3. Per-item: before hook -> generateFirstTurn -> conversation loop -> after hook
|
|
1258
|
+
* 4. afterAll hook (if configured)
|
|
1259
|
+
*
|
|
1195
1260
|
* @param options - Simulation configuration options
|
|
1196
1261
|
* @returns Dictionary with simulation results, or null on failure
|
|
1197
1262
|
*/
|
|
1198
1263
|
runSimulation(options: SimulationOptions): Promise<SimulationResult | null>;
|
|
1199
1264
|
/**
|
|
1200
|
-
*
|
|
1265
|
+
* Orchestrate concurrent simulation execution with hooks support.
|
|
1201
1266
|
*/
|
|
1202
1267
|
private _runSimulationAsync;
|
|
1203
1268
|
/**
|
|
1204
1269
|
* Execute a multi-turn conversation for a single simulation item.
|
|
1270
|
+
*
|
|
1271
|
+
* The per-item before hook has already been executed by the caller;
|
|
1272
|
+
* the merged setupContext is passed directly to executeTask.
|
|
1273
|
+
* The after hook runs when the conversation ends (success or failure).
|
|
1205
1274
|
*/
|
|
1206
1275
|
private _executeConversation;
|
|
1207
1276
|
}
|
|
1208
1277
|
|
|
1209
1278
|
/**
|
|
1210
|
-
* Result from
|
|
1279
|
+
* Result from initializing a simulation run (two-phase flow).
|
|
1211
1280
|
*/
|
|
1212
|
-
interface
|
|
1281
|
+
interface InitializeRunResult {
|
|
1213
1282
|
runId: string;
|
|
1214
|
-
|
|
1283
|
+
items: Array<{
|
|
1284
|
+
runItemId: string;
|
|
1285
|
+
datasetItemId: string;
|
|
1286
|
+
}>;
|
|
1215
1287
|
}
|
|
1216
1288
|
|
|
1217
1289
|
/**
|
|
@@ -1236,6 +1308,30 @@ declare function span(target: AnyClass): void;
|
|
|
1236
1308
|
declare function span<T extends AnyFunction>(target: T): T;
|
|
1237
1309
|
declare function span(options?: DecoratorOptions): UnifiedDecorator;
|
|
1238
1310
|
|
|
1311
|
+
interface SafeStringifyOptions {
|
|
1312
|
+
maxLength?: number;
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Circular-reference-safe JSON serialization.
|
|
1316
|
+
*
|
|
1317
|
+
* Handles circular references, functions, symbols, bigints, and
|
|
1318
|
+
* large class instances gracefully. Never throws.
|
|
1319
|
+
*
|
|
1320
|
+
* When called without options, performs pure serialization with no truncation.
|
|
1321
|
+
* Pass `{ maxLength }` to enable hard truncation of the final result.
|
|
1322
|
+
*/
|
|
1323
|
+
declare function safeStringify(value: unknown, options?: SafeStringifyOptions): string;
|
|
1324
|
+
|
|
1325
|
+
interface TruncatingSerializerConfig {
|
|
1326
|
+
maxAttributeSize: number;
|
|
1327
|
+
}
|
|
1328
|
+
type SerializedAttributeValue = string | number | boolean | Array<null | undefined | string> | Array<null | undefined | number> | Array<null | undefined | boolean>;
|
|
1329
|
+
declare class TruncatingSerializer {
|
|
1330
|
+
private readonly maxAttributeSize;
|
|
1331
|
+
constructor(config?: Partial<TruncatingSerializerConfig>);
|
|
1332
|
+
serializeAttribute(value: unknown, budget?: number): SerializedAttributeValue;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1239
1335
|
/**
|
|
1240
1336
|
* Shared utility functions for instrumentation.
|
|
1241
1337
|
* Handles setting OTel span attributes for LLM request/response tracing.
|
|
@@ -1437,6 +1533,20 @@ declare class NetraOpenAIAgentsInstrumentor {
|
|
|
1437
1533
|
}
|
|
1438
1534
|
declare const openaiAgentsInstrumentor: NetraOpenAIAgentsInstrumentor;
|
|
1439
1535
|
|
|
1536
|
+
/**
|
|
1537
|
+
* SpanExporter wrapper that drops spans by name and by root-instrument policy.
|
|
1538
|
+
*
|
|
1539
|
+
* A span is dropped when any of the following holds:
|
|
1540
|
+
* - its trace id was blocked while a trial/quota block was active;
|
|
1541
|
+
* - its name matches a globally configured block pattern;
|
|
1542
|
+
* - its name matches a per-span local block pattern set by
|
|
1543
|
+
* `LocalFilteringSpanProcessor`;
|
|
1544
|
+
* - it is a root-connected span from an instrumentation not allowed to emit
|
|
1545
|
+
* root spans (resolved by `findRootSpansBlocked`).
|
|
1546
|
+
*
|
|
1547
|
+
* Children of a dropped span are reparented onto the dropped span's parent so
|
|
1548
|
+
* subtrees are never silently discarded.
|
|
1549
|
+
*/
|
|
1440
1550
|
declare class FilteringSpanExporter implements SpanExporter {
|
|
1441
1551
|
private readonly exporter;
|
|
1442
1552
|
private readonly localBlockedMap?;
|
|
@@ -1452,22 +1562,75 @@ declare class FilteringSpanExporter implements SpanExporter {
|
|
|
1452
1562
|
private readonly localPatternCache;
|
|
1453
1563
|
private static readonly MAX_LOCAL_PATTERN_CACHE;
|
|
1454
1564
|
constructor(exporter: SpanExporter, globalPatterns: string[], localBlockedMap?: ReadonlyMap<string, SpanContext | undefined> | undefined);
|
|
1565
|
+
/**
|
|
1566
|
+
* Filter `spans`, reparent survivors, and forward them to the wrapped exporter.
|
|
1567
|
+
*
|
|
1568
|
+
* While a trial/quota block is active the whole batch is dropped and its trace
|
|
1569
|
+
* ids are remembered so their later spans are dropped too. Otherwise the batch
|
|
1570
|
+
* is classified into name/local drops and root-instrument drops, the survivors
|
|
1571
|
+
* are reparented past any dropped ancestor, and only they are forwarded.
|
|
1572
|
+
*/
|
|
1455
1573
|
export(spans: ReadableSpan[], resultCallback: (result: {
|
|
1456
1574
|
code: ExportResultCode;
|
|
1457
1575
|
}) => void): void;
|
|
1458
1576
|
shutdown(): Promise<void>;
|
|
1459
1577
|
forceFlush(): Promise<void>;
|
|
1578
|
+
/**
|
|
1579
|
+
* Remember the trace ids seen during a block so their later spans are dropped
|
|
1580
|
+
* too, even after the block expires.
|
|
1581
|
+
*/
|
|
1582
|
+
private recordBlockedTraceIds;
|
|
1583
|
+
/**
|
|
1584
|
+
* Find the spans dropped unconditionally by a global or local name rule.
|
|
1585
|
+
*
|
|
1586
|
+
* Trace-blocked spans are skipped entirely (dropped without reparenting). Each
|
|
1587
|
+
* dropped span is also recorded in the cross-batch remembered map so a child
|
|
1588
|
+
* arriving in a later batch can still be reparented past it. The returned map
|
|
1589
|
+
* feeds both the root-connected candidate walk — as transparent dropped
|
|
1590
|
+
* ancestors — and the reparent map.
|
|
1591
|
+
*
|
|
1592
|
+
* @returns A `{droppedSpanId -> normalizedParent}` map for the name/locally
|
|
1593
|
+
* blocked spans in this batch.
|
|
1594
|
+
*/
|
|
1595
|
+
private findSpansBlockedByName;
|
|
1596
|
+
/**
|
|
1597
|
+
* Check whether `span` is blocked by its per-span local rules — either its
|
|
1598
|
+
* name matches a local pattern or it carries the local-block flag.
|
|
1599
|
+
*/
|
|
1600
|
+
private isLocallyBlocked;
|
|
1601
|
+
/**
|
|
1602
|
+
* Return the spans that survive filtering: not trace-blocked and not in
|
|
1603
|
+
* `allBlockedSpanIds` (name/local drops or the root-instrument policy).
|
|
1604
|
+
*/
|
|
1605
|
+
private collectSurvivors;
|
|
1606
|
+
/**
|
|
1607
|
+
* Merge the cross-batch remembered map with this batch's dropped-parent maps.
|
|
1608
|
+
*
|
|
1609
|
+
* Ordering matters — later wins on conflict: the remembered map and the
|
|
1610
|
+
* injected local-block snapshot are the base, overlaid by root-blocked
|
|
1611
|
+
* parents, then this batch's name/local blocks, so in-batch drops win.
|
|
1612
|
+
*
|
|
1613
|
+
* @returns The merged `{droppedSpanId -> parent}` map used for reparenting.
|
|
1614
|
+
*/
|
|
1615
|
+
private buildReparentMap;
|
|
1460
1616
|
private getCompiledLocalPatterns;
|
|
1461
1617
|
private evictRememberedIfNeeded;
|
|
1462
|
-
|
|
1618
|
+
/**
|
|
1619
|
+
* Read the per-span local-block patterns set by `LocalFilteringSpanProcessor`,
|
|
1620
|
+
* or an empty list when none are set.
|
|
1621
|
+
*/
|
|
1622
|
+
private readLocalBlockPatterns;
|
|
1623
|
+
/** Check whether the processor explicitly flagged `span` as locally blocked. */
|
|
1463
1624
|
private hasLocalBlockFlag;
|
|
1464
1625
|
/**
|
|
1465
|
-
*
|
|
1466
|
-
* with a ReparentedSpan pointing to the nearest non-blocked ancestor.
|
|
1626
|
+
* Reparent each span past any dropped ancestor onto its first surviving one.
|
|
1467
1627
|
*
|
|
1468
|
-
*
|
|
1628
|
+
* Walks the chain of dropped parents (following `blockedMap`) until a surviving
|
|
1629
|
+
* parent — or `undefined` (promote to root) — is reached, then wraps the span
|
|
1630
|
+
* in a `ReparentedSpan` pointing there. A cycle guard (visited set) prevents
|
|
1631
|
+
* infinite loops in malformed traces.
|
|
1469
1632
|
*/
|
|
1470
|
-
private
|
|
1633
|
+
private reparentSpans;
|
|
1471
1634
|
}
|
|
1472
1635
|
|
|
1473
1636
|
interface ExporterConfig {
|
|
@@ -1624,4 +1787,4 @@ declare class Netra {
|
|
|
1624
1787
|
static withBlockedSpansLocal: typeof withBlockedSpansLocal;
|
|
1625
1788
|
}
|
|
1626
1789
|
|
|
1627
|
-
export { type ActionModel,
|
|
1790
|
+
export { type ActionModel, type AfterAllFn, type AfterFn, Aggregation, BaseTask, type BeforeAllFn, type BeforeFn, type CategoricalDataPoint, ChartType, Config, type ConversationResponse, type ConversationResult, ConversationType, type CreateDatasetParams, DEFAULT_INSTRUMENTS, DEFAULT_INSTRUMENTS_FOR_ROOT, Dashboard, type DashboardData, type Dataset, type DatasetEntry, type DatasetItem, type Dimension, DimensionField, type DimensionValue, EntryStatus, Evaluation, type EvaluationScore, type EvaluatorFunction, type Filter, type FilterConfig, FilterField, FilterType, FilteringSpanExporter, type GetPromptParams, GroupBy, type InitializeRunResult, InstrumentationSpanProcessor, type ListSpansParams, type ListTracesParams, Measure, type Metrics, Netra, NetraAgentsTracingProcessor, NetraInstruments, NetraOpenAIAgentsInstrumentor, type NumberResponse, Operator, type ProcessedFile, type PromptResponse, Prompts, type QueryDataParams, type QueryResponse, type Run, RunEntryContext, RunStatus, type SafeStringifyOptions, Scope, ScrubbingSpanProcessor, SerializationSpanProcessor, SessionSpanProcessor, type SessionUsageData, Simulation, type SimulationHooks, type SimulationItem, type SimulationOptions, type SimulationResult, SpanIOProcessor, type SpanOptions, SpanType, type SpansPage, type TaskFunction, type TaskResult, type TenantUsageData, type TestSuiteResult, type TimeRange, type TimeSeriesDataPoint, type TimeSeriesResponse, type TimeSeriesWithDimension, type TraceSpan, type TraceSummary, type TracesPage, TrialAwareOTLPExporter, TruncatingSerializer, Usage, type UsageModel, agent, Netra as default, metadataField, mistralAIInstrumentor, netraExpressMiddleware, openaiAgentsInstrumentor, runWithExtractedContext, safeStringify, span, task, workflow };
|