netra-sdk 1.5.0 → 1.6.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 +731 -448
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +172 -90
- package/dist/index.d.ts +172 -90
- package/dist/index.js +721 -440
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -7,6 +7,7 @@ var api = require('@opentelemetry/api');
|
|
|
7
7
|
var instrumentation = require('@opentelemetry/instrumentation');
|
|
8
8
|
var module$1 = require('module');
|
|
9
9
|
var async_hooks = require('async_hooks');
|
|
10
|
+
var jsonrepair = require('jsonrepair');
|
|
10
11
|
var sdkTraceBase = require('@opentelemetry/sdk-trace-base');
|
|
11
12
|
var nodeServerSdk = require('@traceloop/node-server-sdk');
|
|
12
13
|
var shimmer = require('shimmer');
|
|
@@ -1338,7 +1339,7 @@ var require_validation = __commonJS({
|
|
|
1338
1339
|
exports$1.needsEscaping = needsEscaping3;
|
|
1339
1340
|
exports$1.escapeObject = escapeObject3;
|
|
1340
1341
|
exports$1.isEscapedObject = isEscapedObject;
|
|
1341
|
-
exports$1.serializeValue =
|
|
1342
|
+
exports$1.serializeValue = serializeValue;
|
|
1342
1343
|
exports$1.serializeLcObject = serializeLcObject;
|
|
1343
1344
|
exports$1.escapeIfNeeded = escapeIfNeeded3;
|
|
1344
1345
|
exports$1.unescapeValue = unescapeValue;
|
|
@@ -1372,7 +1373,7 @@ var require_validation = __commonJS({
|
|
|
1372
1373
|
id
|
|
1373
1374
|
};
|
|
1374
1375
|
}
|
|
1375
|
-
function
|
|
1376
|
+
function serializeValue(obj) {
|
|
1376
1377
|
if (isSerializableLike3(obj)) {
|
|
1377
1378
|
return serializeLcObject(obj);
|
|
1378
1379
|
}
|
|
@@ -1383,12 +1384,12 @@ var require_validation = __commonJS({
|
|
|
1383
1384
|
}
|
|
1384
1385
|
const result = {};
|
|
1385
1386
|
for (const [key, value] of Object.entries(record)) {
|
|
1386
|
-
result[key] =
|
|
1387
|
+
result[key] = serializeValue(value);
|
|
1387
1388
|
}
|
|
1388
1389
|
return result;
|
|
1389
1390
|
}
|
|
1390
1391
|
if (Array.isArray(obj)) {
|
|
1391
|
-
return obj.map((item) =>
|
|
1392
|
+
return obj.map((item) => serializeValue(item));
|
|
1392
1393
|
}
|
|
1393
1394
|
if (typeof obj === "string" || typeof obj === "number" || typeof obj === "boolean" || obj === null) {
|
|
1394
1395
|
return obj;
|
|
@@ -1404,7 +1405,7 @@ var require_validation = __commonJS({
|
|
|
1404
1405
|
if (secretFields.has(key)) {
|
|
1405
1406
|
newKwargs[key] = value;
|
|
1406
1407
|
} else {
|
|
1407
|
-
newKwargs[key] =
|
|
1408
|
+
newKwargs[key] = serializeValue(value);
|
|
1408
1409
|
}
|
|
1409
1410
|
}
|
|
1410
1411
|
serialized.kwargs = newKwargs;
|
|
@@ -7606,7 +7607,7 @@ Context: ${context18}`);
|
|
|
7606
7607
|
}
|
|
7607
7608
|
}
|
|
7608
7609
|
}
|
|
7609
|
-
async getRunStats({ id, trace:
|
|
7610
|
+
async getRunStats({ id, trace: trace24, parentRun, runType, projectNames, projectIds, referenceExampleIds, startTime, endTime, error, query, filter, traceFilter, treeFilter, isRoot, dataSourceType }) {
|
|
7610
7611
|
let projectIds_ = projectIds || [];
|
|
7611
7612
|
if (projectNames) {
|
|
7612
7613
|
projectIds_ = [
|
|
@@ -7616,7 +7617,7 @@ Context: ${context18}`);
|
|
|
7616
7617
|
}
|
|
7617
7618
|
const payload = {
|
|
7618
7619
|
id,
|
|
7619
|
-
trace:
|
|
7620
|
+
trace: trace24,
|
|
7620
7621
|
parent_run: parentRun,
|
|
7621
7622
|
run_type: runType,
|
|
7622
7623
|
session: projectIds_,
|
|
@@ -14934,8 +14935,8 @@ var Usage = class {
|
|
|
14934
14935
|
if (!page) {
|
|
14935
14936
|
break;
|
|
14936
14937
|
}
|
|
14937
|
-
for (const
|
|
14938
|
-
yield
|
|
14938
|
+
for (const trace24 of page.traces) {
|
|
14939
|
+
yield trace24;
|
|
14939
14940
|
}
|
|
14940
14941
|
if (!page.hasNextPage || !page.nextCursor) {
|
|
14941
14942
|
break;
|
|
@@ -15048,7 +15049,7 @@ var Usage = class {
|
|
|
15048
15049
|
};
|
|
15049
15050
|
|
|
15050
15051
|
// src/version.ts
|
|
15051
|
-
var SDK_VERSION = "1.
|
|
15052
|
+
var SDK_VERSION = "1.6.0";
|
|
15052
15053
|
|
|
15053
15054
|
// src/config.ts
|
|
15054
15055
|
var NetraInstruments = /* @__PURE__ */ ((NetraInstruments2) => {
|
|
@@ -15104,7 +15105,20 @@ var DEFAULT_INSTRUMENTS = /* @__PURE__ */ new Set([
|
|
|
15104
15105
|
// Web Frameworks
|
|
15105
15106
|
"express" /* EXPRESS */
|
|
15106
15107
|
]);
|
|
15107
|
-
var
|
|
15108
|
+
var _Config = class _Config {
|
|
15109
|
+
/**
|
|
15110
|
+
* Lazily reads NETRA_SPAN_ATTRIBUTE_MAX_SIZE from process.env on first
|
|
15111
|
+
* access so that env vars set before Netra.init() (via dotenv, shell
|
|
15112
|
+
* export, Docker, etc.) are always respected regardless of import order.
|
|
15113
|
+
*/
|
|
15114
|
+
static get SPAN_ATTRIBUTE_MAX_SIZE() {
|
|
15115
|
+
if (_Config._spanAttributeMaxSize === void 0) {
|
|
15116
|
+
_Config._spanAttributeMaxSize = parseInt(
|
|
15117
|
+
process.env.NETRA_SPAN_ATTRIBUTE_MAX_SIZE || "30000"
|
|
15118
|
+
);
|
|
15119
|
+
}
|
|
15120
|
+
return _Config._spanAttributeMaxSize;
|
|
15121
|
+
}
|
|
15108
15122
|
constructor(config = {}) {
|
|
15109
15123
|
this.appName = this._getAppName(config.appName);
|
|
15110
15124
|
this.otlpEndpoint = this._getOtlpEndpoint();
|
|
@@ -15275,20 +15289,11 @@ var Config = class {
|
|
|
15275
15289
|
process.env.OTEL_RESOURCE_ATTRIBUTES = Object.entries(attrs).map(([k, v]) => `${encodeAttrValue(k)}=${encodeAttrValue(v)}`).join(",");
|
|
15276
15290
|
}
|
|
15277
15291
|
};
|
|
15278
|
-
|
|
15279
|
-
|
|
15280
|
-
|
|
15281
|
-
|
|
15282
|
-
|
|
15283
|
-
Config.ATTRIBUTE_MAX_LEN = parseInt(
|
|
15284
|
-
process.env.NETRA_ATTRIBUTE_MAX_LEN || "50000"
|
|
15285
|
-
);
|
|
15286
|
-
Config.CONVERSATION_MAX_LEN = parseInt(
|
|
15287
|
-
process.env.NETRA_CONVERSATION_CONTENT_MAX_LEN || "50000"
|
|
15288
|
-
);
|
|
15289
|
-
Config.SPAN_ATTRIBUTE_MAX_SIZE = parseInt(
|
|
15290
|
-
process.env.NETRA_SPAN_ATTRIBUTE_MAX_SIZE || "30000"
|
|
15291
|
-
);
|
|
15292
|
+
_Config.SDK_NAME = "netra";
|
|
15293
|
+
_Config.LIBRARY_NAME = "netra";
|
|
15294
|
+
_Config.LIBRARY_VERSION = SDK_VERSION;
|
|
15295
|
+
_Config.TRIAL_BLOCK_DURATION_SECONDS = 900;
|
|
15296
|
+
var Config = _Config;
|
|
15292
15297
|
|
|
15293
15298
|
// src/utils/pattern-matching.ts
|
|
15294
15299
|
function compilePatterns(patterns) {
|
|
@@ -15550,27 +15555,26 @@ var ConversationType = /* @__PURE__ */ ((ConversationType3) => {
|
|
|
15550
15555
|
return ConversationType3;
|
|
15551
15556
|
})(ConversationType || {});
|
|
15552
15557
|
|
|
15553
|
-
// src/utils/serialization.ts
|
|
15554
|
-
|
|
15555
|
-
|
|
15556
|
-
if (s.length <= maxLength) return s;
|
|
15557
|
-
if (maxLength <= ELLIPSIS.length) return s.slice(0, maxLength);
|
|
15558
|
-
return s.slice(0, maxLength - ELLIPSIS.length) + ELLIPSIS;
|
|
15559
|
-
}
|
|
15560
|
-
function safeStringify(value, maxLength) {
|
|
15558
|
+
// src/utils/serialization/safe-stringify.ts
|
|
15559
|
+
function safeStringify(value, options) {
|
|
15560
|
+
const maxLength = options?.maxLength;
|
|
15561
15561
|
if (typeof value === "string") {
|
|
15562
15562
|
if (maxLength && value.length > maxLength) {
|
|
15563
|
-
return
|
|
15563
|
+
return value.slice(0, maxLength);
|
|
15564
15564
|
}
|
|
15565
15565
|
return value;
|
|
15566
15566
|
}
|
|
15567
|
+
if (value === null) return "null";
|
|
15568
|
+
if (value === void 0) return "undefined";
|
|
15569
|
+
const t = typeof value;
|
|
15570
|
+
if (t === "number" || t === "boolean") return String(value);
|
|
15571
|
+
if (t === "bigint") return value.toString();
|
|
15572
|
+
if (t === "symbol") return value.toString();
|
|
15573
|
+
if (t === "function") return `[Function: ${value.name || "anonymous"}]`;
|
|
15567
15574
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
15568
15575
|
let result;
|
|
15569
15576
|
try {
|
|
15570
15577
|
result = JSON.stringify(value, (_key, val) => {
|
|
15571
|
-
if (typeof val === "string" && maxLength && val.length > maxLength) {
|
|
15572
|
-
return truncate(val, maxLength);
|
|
15573
|
-
}
|
|
15574
15578
|
if (typeof val === "function")
|
|
15575
15579
|
return `[Function: ${val.name || "anonymous"}]`;
|
|
15576
15580
|
if (typeof val === "symbol") return val.toString();
|
|
@@ -15584,25 +15588,148 @@ function safeStringify(value, maxLength) {
|
|
|
15584
15588
|
}
|
|
15585
15589
|
}
|
|
15586
15590
|
return val;
|
|
15587
|
-
}) ??
|
|
15591
|
+
}) ?? "null";
|
|
15588
15592
|
} catch {
|
|
15589
|
-
|
|
15593
|
+
const name = value?.constructor?.name;
|
|
15594
|
+
result = name ? `[Unserializable: ${name}]` : "[Unserializable]";
|
|
15590
15595
|
}
|
|
15591
15596
|
if (maxLength && result.length > maxLength) {
|
|
15592
|
-
return
|
|
15597
|
+
return result.slice(0, maxLength);
|
|
15593
15598
|
}
|
|
15594
15599
|
return result;
|
|
15595
15600
|
}
|
|
15596
|
-
|
|
15597
|
-
|
|
15598
|
-
|
|
15599
|
-
|
|
15600
|
-
|
|
15601
|
-
|
|
15602
|
-
|
|
15601
|
+
var TRUNCATION_SUFFIX = "...[TRUNCATED]";
|
|
15602
|
+
var MINIMAL_TRUNCATED_OBJECT = '{"__truncated__":true}';
|
|
15603
|
+
var MINIMAL_TRUNCATED_ARRAY = '[{"__truncated__":true}]';
|
|
15604
|
+
var MIN_JSON_TRUNCATION_LENGTH = MINIMAL_TRUNCATED_ARRAY.length;
|
|
15605
|
+
var RETRY_RATIOS = [0.7, 0.5, 0.3];
|
|
15606
|
+
var DEFAULT_CONFIG = {
|
|
15607
|
+
maxAttributeSize: 3e4
|
|
15608
|
+
};
|
|
15609
|
+
function isJsonLike(str) {
|
|
15610
|
+
const trimmed = str.trimStart();
|
|
15611
|
+
return trimmed.startsWith("{") || trimmed.startsWith("[");
|
|
15612
|
+
}
|
|
15613
|
+
function minimalTruncatedJson(json) {
|
|
15614
|
+
return json.trimStart().startsWith("[") ? MINIMAL_TRUNCATED_ARRAY : MINIMAL_TRUNCATED_OBJECT;
|
|
15615
|
+
}
|
|
15616
|
+
function injectTruncationMarker(parsed) {
|
|
15617
|
+
if (Array.isArray(parsed)) {
|
|
15618
|
+
parsed.push({ __truncated__: true });
|
|
15619
|
+
} else if (typeof parsed === "object" && parsed !== null) {
|
|
15620
|
+
parsed.__truncated__ = true;
|
|
15621
|
+
}
|
|
15622
|
+
}
|
|
15623
|
+
function tryRepairAndFit(json, cutLen, budget) {
|
|
15624
|
+
if (cutLen <= 0) return null;
|
|
15625
|
+
try {
|
|
15626
|
+
const repaired = jsonrepair.jsonrepair(json.slice(0, cutLen));
|
|
15627
|
+
const parsed = JSON.parse(repaired);
|
|
15628
|
+
injectTruncationMarker(parsed);
|
|
15629
|
+
const result = JSON.stringify(parsed);
|
|
15630
|
+
if (result.length <= budget) return result;
|
|
15631
|
+
} catch {
|
|
15632
|
+
Logger.debug("Failed to repair and fit JSON at cut length", {
|
|
15633
|
+
length: json.length,
|
|
15634
|
+
cutLength: cutLen
|
|
15635
|
+
});
|
|
15636
|
+
}
|
|
15637
|
+
return null;
|
|
15638
|
+
}
|
|
15639
|
+
function truncateJsonValue(json, budget) {
|
|
15640
|
+
const minimal = minimalTruncatedJson(json);
|
|
15641
|
+
if (budget < minimal.length) {
|
|
15642
|
+
return truncatePlainString(json, budget);
|
|
15643
|
+
}
|
|
15644
|
+
const overhead = Math.max(30, Math.ceil(budget * 0.05));
|
|
15645
|
+
const initialCut = budget - overhead;
|
|
15646
|
+
const candidateLengths = [
|
|
15647
|
+
initialCut,
|
|
15648
|
+
...RETRY_RATIOS.map((ratio) => Math.floor(initialCut * ratio))
|
|
15649
|
+
];
|
|
15650
|
+
for (const cutLen of candidateLengths) {
|
|
15651
|
+
const result = tryRepairAndFit(json, cutLen, budget);
|
|
15652
|
+
if (result !== null) return result;
|
|
15653
|
+
}
|
|
15654
|
+
let lo = 1;
|
|
15655
|
+
let hi = Math.max(1, Math.floor(initialCut * 0.1));
|
|
15656
|
+
let bestResult = null;
|
|
15657
|
+
while (lo <= hi) {
|
|
15658
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
15659
|
+
const result = tryRepairAndFit(json, mid, budget);
|
|
15660
|
+
if (result !== null) {
|
|
15661
|
+
bestResult = result;
|
|
15662
|
+
lo = mid + 1;
|
|
15663
|
+
} else {
|
|
15664
|
+
hi = mid - 1;
|
|
15665
|
+
}
|
|
15666
|
+
}
|
|
15667
|
+
if (bestResult !== null) return bestResult;
|
|
15668
|
+
return minimal;
|
|
15669
|
+
}
|
|
15670
|
+
function truncatePlainString(str, maxLen) {
|
|
15671
|
+
if (maxLen <= TRUNCATION_SUFFIX.length) {
|
|
15672
|
+
return str.slice(0, maxLen);
|
|
15603
15673
|
}
|
|
15604
|
-
return
|
|
15674
|
+
return str.slice(0, maxLen - TRUNCATION_SUFFIX.length) + TRUNCATION_SUFFIX;
|
|
15605
15675
|
}
|
|
15676
|
+
function truncateString(value, budget) {
|
|
15677
|
+
if (value.length <= budget) return value;
|
|
15678
|
+
if (isJsonLike(value) && budget >= MIN_JSON_TRUNCATION_LENGTH) {
|
|
15679
|
+
return truncateJsonValue(value, budget);
|
|
15680
|
+
}
|
|
15681
|
+
return truncatePlainString(value, budget);
|
|
15682
|
+
}
|
|
15683
|
+
function serializeAttribute(value, maxSize) {
|
|
15684
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
15685
|
+
return value;
|
|
15686
|
+
}
|
|
15687
|
+
if (typeof value === "string") {
|
|
15688
|
+
return truncateString(value, maxSize);
|
|
15689
|
+
}
|
|
15690
|
+
if (Array.isArray(value)) {
|
|
15691
|
+
if (value.every((v) => v == null || typeof v === "number")) {
|
|
15692
|
+
const serializedLen = estimateArraySize(value);
|
|
15693
|
+
if (serializedLen <= maxSize) {
|
|
15694
|
+
return value;
|
|
15695
|
+
}
|
|
15696
|
+
} else if (value.every((v) => v == null || typeof v === "boolean")) {
|
|
15697
|
+
const serializedLen = estimateArraySize(value);
|
|
15698
|
+
if (serializedLen <= maxSize) {
|
|
15699
|
+
return value;
|
|
15700
|
+
}
|
|
15701
|
+
} else if (value.every((v) => v == null || typeof v === "string")) {
|
|
15702
|
+
const serializedLen = value.reduce(
|
|
15703
|
+
(sum, s) => sum + (s == null ? 4 : s.length + 2),
|
|
15704
|
+
2 + Math.max(0, value.length - 1)
|
|
15705
|
+
);
|
|
15706
|
+
if (serializedLen <= maxSize) {
|
|
15707
|
+
return value;
|
|
15708
|
+
}
|
|
15709
|
+
}
|
|
15710
|
+
}
|
|
15711
|
+
const serialized = safeStringify(value);
|
|
15712
|
+
return truncateString(serialized, maxSize);
|
|
15713
|
+
}
|
|
15714
|
+
function estimateArraySize(arr) {
|
|
15715
|
+
let size = 2;
|
|
15716
|
+
for (let i = 0; i < arr.length; i++) {
|
|
15717
|
+
if (i > 0) size += 1;
|
|
15718
|
+
const v = arr[i];
|
|
15719
|
+
if (v == null) size += 4;
|
|
15720
|
+
else size += String(v).length;
|
|
15721
|
+
}
|
|
15722
|
+
return size;
|
|
15723
|
+
}
|
|
15724
|
+
var TruncatingSerializer = class {
|
|
15725
|
+
constructor(config) {
|
|
15726
|
+
const merged = { ...DEFAULT_CONFIG, ...config };
|
|
15727
|
+
this.maxAttributeSize = merged.maxAttributeSize;
|
|
15728
|
+
}
|
|
15729
|
+
serializeAttribute(value, budget) {
|
|
15730
|
+
return serializeAttribute(value, budget ?? this.maxAttributeSize);
|
|
15731
|
+
}
|
|
15732
|
+
};
|
|
15606
15733
|
|
|
15607
15734
|
// src/session-manager.ts
|
|
15608
15735
|
var MODULE_NAME = "netra.session-manager";
|
|
@@ -15716,7 +15843,7 @@ var SessionManager = class _SessionManager {
|
|
|
15716
15843
|
try {
|
|
15717
15844
|
const span2 = api.trace.getActiveSpan();
|
|
15718
15845
|
if (span2?.isRecording()) {
|
|
15719
|
-
span2.setAttribute(key, typeof value === "string" ? value :
|
|
15846
|
+
span2.setAttribute(key, typeof value === "string" ? value : safeStringify(value));
|
|
15720
15847
|
} else {
|
|
15721
15848
|
Logger.warn(`setAttributeOnActiveSpan: no recording span for key '${key}'`);
|
|
15722
15849
|
}
|
|
@@ -15733,7 +15860,7 @@ var SessionManager = class _SessionManager {
|
|
|
15733
15860
|
try {
|
|
15734
15861
|
_SessionManager.setAttributeOnActiveSpan(
|
|
15735
15862
|
"netra.user.input",
|
|
15736
|
-
|
|
15863
|
+
safeStringify(value)
|
|
15737
15864
|
);
|
|
15738
15865
|
} catch (e) {
|
|
15739
15866
|
Logger.error("setInput failed:", e);
|
|
@@ -15748,7 +15875,7 @@ var SessionManager = class _SessionManager {
|
|
|
15748
15875
|
try {
|
|
15749
15876
|
_SessionManager.setAttributeOnActiveSpan(
|
|
15750
15877
|
"netra.user.output",
|
|
15751
|
-
|
|
15878
|
+
safeStringify(value)
|
|
15752
15879
|
);
|
|
15753
15880
|
} catch (e) {
|
|
15754
15881
|
Logger.error("setOutput failed:", e);
|
|
@@ -15763,7 +15890,7 @@ var SessionManager = class _SessionManager {
|
|
|
15763
15890
|
try {
|
|
15764
15891
|
RootSpanProcessor.setAttributeOnRootSpan(
|
|
15765
15892
|
"netra.root.input",
|
|
15766
|
-
|
|
15893
|
+
safeStringify(value)
|
|
15767
15894
|
);
|
|
15768
15895
|
} catch (e) {
|
|
15769
15896
|
Logger.error("setRootInput failed:", e);
|
|
@@ -15778,7 +15905,7 @@ var SessionManager = class _SessionManager {
|
|
|
15778
15905
|
try {
|
|
15779
15906
|
RootSpanProcessor.setAttributeOnRootSpan(
|
|
15780
15907
|
"netra.root.output",
|
|
15781
|
-
|
|
15908
|
+
safeStringify(value)
|
|
15782
15909
|
);
|
|
15783
15910
|
} catch (e) {
|
|
15784
15911
|
Logger.error("setRootOutput failed:", e);
|
|
@@ -15811,8 +15938,8 @@ var SessionManager = class _SessionManager {
|
|
|
15811
15938
|
*
|
|
15812
15939
|
* Reads and re-serialises the existing JSON array so entries accumulate
|
|
15813
15940
|
* rather than overwrite — matching the Python SDK's behaviour.
|
|
15814
|
-
*
|
|
15815
|
-
*
|
|
15941
|
+
* Uses span.setAttribute so the value flows through the processor pipeline
|
|
15942
|
+
* including the SerializationSpanProcessor for proper truncation.
|
|
15816
15943
|
*/
|
|
15817
15944
|
static addConversation(conversationType, role, content) {
|
|
15818
15945
|
if (!role || !content) {
|
|
@@ -15827,29 +15954,26 @@ var SessionManager = class _SessionManager {
|
|
|
15827
15954
|
}
|
|
15828
15955
|
let existing = [];
|
|
15829
15956
|
try {
|
|
15830
|
-
const raw = span2.
|
|
15957
|
+
const raw = span2.attributes?.["conversation"];
|
|
15831
15958
|
if (typeof raw === "string") {
|
|
15832
15959
|
const parsed = JSON.parse(raw);
|
|
15833
|
-
if (Array.isArray(parsed))
|
|
15960
|
+
if (Array.isArray(parsed)) {
|
|
15961
|
+
existing = parsed.filter(
|
|
15962
|
+
(entry) => !(entry && typeof entry === "object" && entry.__truncated__ === true && Object.keys(entry).length === 1)
|
|
15963
|
+
);
|
|
15964
|
+
}
|
|
15834
15965
|
}
|
|
15835
15966
|
} catch (e) {
|
|
15836
15967
|
Logger.warn("addConversation: failed to parse existing conversation, starting fresh:", e);
|
|
15837
15968
|
}
|
|
15838
|
-
const maxLen = Config.CONVERSATION_MAX_LEN;
|
|
15839
|
-
const processedContent = typeof content === "string" ? content.substring(0, maxLen) : content;
|
|
15840
15969
|
existing.push({
|
|
15841
15970
|
type: conversationType,
|
|
15842
15971
|
role,
|
|
15843
|
-
content
|
|
15844
|
-
format: typeof
|
|
15972
|
+
content,
|
|
15973
|
+
format: typeof content === "string" ? "text" : "json"
|
|
15845
15974
|
});
|
|
15846
15975
|
const payload = JSON.stringify(existing);
|
|
15847
|
-
|
|
15848
|
-
if (internalAttrs && typeof internalAttrs === "object") {
|
|
15849
|
-
internalAttrs["conversation"] = payload;
|
|
15850
|
-
} else {
|
|
15851
|
-
span2.setAttribute("conversation", payload);
|
|
15852
|
-
}
|
|
15976
|
+
span2.setAttribute("conversation", payload);
|
|
15853
15977
|
} catch (e) {
|
|
15854
15978
|
Logger.error("addConversation failed:", e);
|
|
15855
15979
|
}
|
|
@@ -17346,58 +17470,6 @@ var Prompts = class {
|
|
|
17346
17470
|
}
|
|
17347
17471
|
};
|
|
17348
17472
|
|
|
17349
|
-
// src/processors/attribute-size-limit-processor.ts
|
|
17350
|
-
var DEFAULT_MAX_ATTRIBUTE_SIZE = 32e3;
|
|
17351
|
-
var AttributeSizeLimitProcessor = class {
|
|
17352
|
-
constructor(maxAttributeSize) {
|
|
17353
|
-
this.maxAttributeSize = maxAttributeSize ?? DEFAULT_MAX_ATTRIBUTE_SIZE;
|
|
17354
|
-
}
|
|
17355
|
-
onStart(span2, _parentContext) {
|
|
17356
|
-
try {
|
|
17357
|
-
this._wrapSetAttribute(span2);
|
|
17358
|
-
} catch (e) {
|
|
17359
|
-
Logger.debug("AttributeSizeLimitProcessor.onStart error:", e);
|
|
17360
|
-
}
|
|
17361
|
-
}
|
|
17362
|
-
onEnd(_span) {
|
|
17363
|
-
}
|
|
17364
|
-
shutdown() {
|
|
17365
|
-
return Promise.resolve();
|
|
17366
|
-
}
|
|
17367
|
-
forceFlush() {
|
|
17368
|
-
return Promise.resolve();
|
|
17369
|
-
}
|
|
17370
|
-
_wrapSetAttribute(span2) {
|
|
17371
|
-
const original = span2.setAttribute.bind(span2);
|
|
17372
|
-
const maxLen = this.maxAttributeSize;
|
|
17373
|
-
const patched = (key, value) => {
|
|
17374
|
-
try {
|
|
17375
|
-
return original(key, truncateValue(value, maxLen));
|
|
17376
|
-
} catch {
|
|
17377
|
-
try {
|
|
17378
|
-
return original(key, value);
|
|
17379
|
-
} catch {
|
|
17380
|
-
return span2;
|
|
17381
|
-
}
|
|
17382
|
-
}
|
|
17383
|
-
};
|
|
17384
|
-
span2.setAttribute = patched;
|
|
17385
|
-
}
|
|
17386
|
-
};
|
|
17387
|
-
function truncateValue(value, maxLen) {
|
|
17388
|
-
if (typeof value === "string") {
|
|
17389
|
-
return value.length > maxLen ? value.substring(0, maxLen) : value;
|
|
17390
|
-
}
|
|
17391
|
-
if (Array.isArray(value)) {
|
|
17392
|
-
const serialized = JSON.stringify(value);
|
|
17393
|
-
if (serialized.length > maxLen) {
|
|
17394
|
-
return serialized.substring(0, maxLen);
|
|
17395
|
-
}
|
|
17396
|
-
return value;
|
|
17397
|
-
}
|
|
17398
|
-
return value;
|
|
17399
|
-
}
|
|
17400
|
-
|
|
17401
17473
|
// src/processors/instrumentation-span-processor.ts
|
|
17402
17474
|
var ALLOWED_INSTRUMENTATION_NAMES = /* @__PURE__ */ new Set([
|
|
17403
17475
|
"openai",
|
|
@@ -17431,12 +17503,6 @@ var ALLOWED_INSTRUMENTATION_NAMES = /* @__PURE__ */ new Set([
|
|
|
17431
17503
|
"elevenlabs"
|
|
17432
17504
|
]);
|
|
17433
17505
|
var InstrumentationSpanProcessor = class {
|
|
17434
|
-
constructor(maxAttributeLength) {
|
|
17435
|
-
this.maxAttributeLength = maxAttributeLength ?? Config.ATTRIBUTE_MAX_LEN;
|
|
17436
|
-
}
|
|
17437
|
-
/**
|
|
17438
|
-
* Detect the raw instrumentation name from the span's instrumentation scope.
|
|
17439
|
-
*/
|
|
17440
17506
|
detectRawInstrumentationName(span2) {
|
|
17441
17507
|
try {
|
|
17442
17508
|
const spanAny = span2;
|
|
@@ -17452,60 +17518,19 @@ var InstrumentationSpanProcessor = class {
|
|
|
17452
17518
|
return base;
|
|
17453
17519
|
}
|
|
17454
17520
|
} catch {
|
|
17521
|
+
Logger.debug("InstrumentationSpanProcessor: Error extracting base name:", name);
|
|
17455
17522
|
}
|
|
17456
17523
|
}
|
|
17457
17524
|
return name;
|
|
17458
17525
|
}
|
|
17459
17526
|
}
|
|
17460
17527
|
} catch {
|
|
17528
|
+
Logger.debug("InstrumentationSpanProcessor: Error detecting instrumentation name");
|
|
17461
17529
|
}
|
|
17462
17530
|
return null;
|
|
17463
17531
|
}
|
|
17464
|
-
|
|
17465
|
-
* Truncate a value to the maximum allowed length.
|
|
17466
|
-
* Handles strings, bytes, and recursively handles lists and objects.
|
|
17467
|
-
*/
|
|
17468
|
-
truncateValue(value) {
|
|
17469
|
-
try {
|
|
17470
|
-
if (typeof value === "string") {
|
|
17471
|
-
return value.length <= this.maxAttributeLength ? value : value.substring(0, this.maxAttributeLength);
|
|
17472
|
-
}
|
|
17473
|
-
if (Array.isArray(value)) {
|
|
17474
|
-
return value.map(
|
|
17475
|
-
(v) => typeof v === "string" ? this.truncateValue(v) : v
|
|
17476
|
-
);
|
|
17477
|
-
}
|
|
17478
|
-
if (typeof value === "object" && value !== null) {
|
|
17479
|
-
const result = {};
|
|
17480
|
-
for (const [k, v] of Object.entries(value)) {
|
|
17481
|
-
result[k] = typeof v === "string" ? this.truncateValue(v) : v;
|
|
17482
|
-
}
|
|
17483
|
-
return result;
|
|
17484
|
-
}
|
|
17485
|
-
} catch {
|
|
17486
|
-
return value;
|
|
17487
|
-
}
|
|
17488
|
-
return value;
|
|
17489
|
-
}
|
|
17490
|
-
/**
|
|
17491
|
-
* Called when a span starts. Wraps setAttribute to truncate values
|
|
17492
|
-
* and records the instrumentation name.
|
|
17493
|
-
*/
|
|
17494
|
-
onStart(span2, parentContext) {
|
|
17532
|
+
onStart(span2, _parentContext) {
|
|
17495
17533
|
try {
|
|
17496
|
-
const originalSetAttribute = span2.setAttribute.bind(span2);
|
|
17497
|
-
span2.setAttribute = (key, value) => {
|
|
17498
|
-
try {
|
|
17499
|
-
const truncated = this.truncateValue(value);
|
|
17500
|
-
return originalSetAttribute(key, truncated);
|
|
17501
|
-
} catch {
|
|
17502
|
-
try {
|
|
17503
|
-
return originalSetAttribute(key, value);
|
|
17504
|
-
} catch {
|
|
17505
|
-
return span2;
|
|
17506
|
-
}
|
|
17507
|
-
}
|
|
17508
|
-
};
|
|
17509
17534
|
const name = this.detectRawInstrumentationName(span2);
|
|
17510
17535
|
if (name && ALLOWED_INSTRUMENTATION_NAMES.has(name.toLowerCase())) {
|
|
17511
17536
|
span2.setAttribute(`${Config.LIBRARY_NAME}.instrumentation.name`, name);
|
|
@@ -17517,20 +17542,11 @@ var InstrumentationSpanProcessor = class {
|
|
|
17517
17542
|
);
|
|
17518
17543
|
}
|
|
17519
17544
|
}
|
|
17520
|
-
|
|
17521
|
-
* Called when a span ends. No-op for this processor.
|
|
17522
|
-
*/
|
|
17523
|
-
onEnd(span2) {
|
|
17545
|
+
onEnd(_span) {
|
|
17524
17546
|
}
|
|
17525
|
-
/**
|
|
17526
|
-
* Shuts down the processor.
|
|
17527
|
-
*/
|
|
17528
17547
|
shutdown() {
|
|
17529
17548
|
return Promise.resolve();
|
|
17530
17549
|
}
|
|
17531
|
-
/**
|
|
17532
|
-
* Forces a flush of any pending spans.
|
|
17533
|
-
*/
|
|
17534
17550
|
forceFlush() {
|
|
17535
17551
|
return Promise.resolve();
|
|
17536
17552
|
}
|
|
@@ -17642,119 +17658,128 @@ var SENSITIVE_KEYS = /* @__PURE__ */ new Set([
|
|
|
17642
17658
|
"span"
|
|
17643
17659
|
]);
|
|
17644
17660
|
var SCRUB_REPLACEMENT = "[SCRUBBED]";
|
|
17645
|
-
|
|
17646
|
-
|
|
17647
|
-
|
|
17648
|
-
|
|
17649
|
-
|
|
17650
|
-
const keyLower = key.toLowerCase();
|
|
17651
|
-
for (const sensitiveKey of SENSITIVE_KEYS) {
|
|
17652
|
-
if (keyLower.includes(sensitiveKey)) {
|
|
17653
|
-
return true;
|
|
17654
|
-
}
|
|
17661
|
+
function isSensitiveKey(key) {
|
|
17662
|
+
const keyLower = key.toLowerCase();
|
|
17663
|
+
for (const sensitiveKey of SENSITIVE_KEYS) {
|
|
17664
|
+
if (keyLower.includes(sensitiveKey)) {
|
|
17665
|
+
return true;
|
|
17655
17666
|
}
|
|
17656
|
-
return false;
|
|
17657
17667
|
}
|
|
17658
|
-
|
|
17659
|
-
|
|
17660
|
-
|
|
17661
|
-
|
|
17662
|
-
|
|
17663
|
-
|
|
17664
|
-
|
|
17668
|
+
return false;
|
|
17669
|
+
}
|
|
17670
|
+
function scrubStringValue(value) {
|
|
17671
|
+
let scrubbed = value;
|
|
17672
|
+
scrubbed = scrubbed.replace(LONG_DIGIT_PATTERN, SCRUB_REPLACEMENT);
|
|
17673
|
+
for (const pattern of Object.values(SENSITIVE_PATTERNS)) {
|
|
17674
|
+
pattern.lastIndex = 0;
|
|
17675
|
+
if (pattern.test(scrubbed)) {
|
|
17665
17676
|
pattern.lastIndex = 0;
|
|
17666
|
-
|
|
17667
|
-
pattern.lastIndex = 0;
|
|
17668
|
-
scrubbed = scrubbed.replace(pattern, SCRUB_REPLACEMENT);
|
|
17669
|
-
}
|
|
17677
|
+
scrubbed = scrubbed.replace(pattern, SCRUB_REPLACEMENT);
|
|
17670
17678
|
}
|
|
17671
|
-
return scrubbed;
|
|
17672
17679
|
}
|
|
17673
|
-
|
|
17674
|
-
|
|
17675
|
-
|
|
17676
|
-
|
|
17677
|
-
|
|
17678
|
-
|
|
17679
|
-
const [, scrubbedValue] = this.scrubKeyValue(k, v);
|
|
17680
|
-
scrubbed[k] = scrubbedValue;
|
|
17681
|
-
}
|
|
17682
|
-
return scrubbed;
|
|
17680
|
+
return scrubbed;
|
|
17681
|
+
}
|
|
17682
|
+
function scrubDict(obj) {
|
|
17683
|
+
const result = {};
|
|
17684
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
17685
|
+
result[k] = scrubAny(k, v);
|
|
17683
17686
|
}
|
|
17684
|
-
|
|
17685
|
-
|
|
17686
|
-
|
|
17687
|
-
|
|
17688
|
-
|
|
17689
|
-
|
|
17690
|
-
|
|
17691
|
-
|
|
17692
|
-
|
|
17693
|
-
|
|
17694
|
-
|
|
17695
|
-
|
|
17696
|
-
|
|
17697
|
-
|
|
17687
|
+
return result;
|
|
17688
|
+
}
|
|
17689
|
+
function scrubList(arr) {
|
|
17690
|
+
return arr.map((item) => {
|
|
17691
|
+
if (typeof item === "string") return scrubStringValue(item);
|
|
17692
|
+
if (Array.isArray(item)) return scrubList(item);
|
|
17693
|
+
if (typeof item === "object" && item !== null) {
|
|
17694
|
+
return scrubDict(item);
|
|
17695
|
+
}
|
|
17696
|
+
return item;
|
|
17697
|
+
});
|
|
17698
|
+
}
|
|
17699
|
+
function scrubAny(key, value) {
|
|
17700
|
+
if (isSensitiveKey(key) && typeof value !== "object" && !Array.isArray(value)) {
|
|
17701
|
+
return SCRUB_REPLACEMENT;
|
|
17698
17702
|
}
|
|
17699
|
-
|
|
17700
|
-
|
|
17701
|
-
|
|
17702
|
-
|
|
17703
|
-
|
|
17704
|
-
|
|
17705
|
-
|
|
17706
|
-
|
|
17707
|
-
|
|
17708
|
-
|
|
17709
|
-
|
|
17710
|
-
|
|
17711
|
-
|
|
17703
|
+
if (typeof value === "string") return scrubStringValue(value);
|
|
17704
|
+
if (Array.isArray(value)) return scrubList(value);
|
|
17705
|
+
if (typeof value === "object" && value !== null) {
|
|
17706
|
+
return scrubDict(value);
|
|
17707
|
+
}
|
|
17708
|
+
return value;
|
|
17709
|
+
}
|
|
17710
|
+
function scrubValue(key, value) {
|
|
17711
|
+
return scrubAny(key, value);
|
|
17712
|
+
}
|
|
17713
|
+
var ScrubbingSpanProcessor = class {
|
|
17714
|
+
onStart(span2, _parentContext) {
|
|
17715
|
+
try {
|
|
17716
|
+
this.wrapSetAttribute(span2);
|
|
17717
|
+
} catch (e) {
|
|
17718
|
+
Logger.error("ScrubbingSpanProcessor.onStart error:", e);
|
|
17712
17719
|
}
|
|
17713
|
-
return [key, value];
|
|
17714
17720
|
}
|
|
17715
|
-
|
|
17716
|
-
* Called when a span starts. No-op for this processor.
|
|
17717
|
-
*/
|
|
17718
|
-
onStart(span2, parentContext) {
|
|
17721
|
+
onEnd(_span) {
|
|
17719
17722
|
}
|
|
17720
|
-
|
|
17721
|
-
|
|
17722
|
-
|
|
17723
|
-
|
|
17724
|
-
|
|
17725
|
-
|
|
17726
|
-
|
|
17727
|
-
|
|
17728
|
-
|
|
17729
|
-
|
|
17730
|
-
|
|
17731
|
-
|
|
17732
|
-
|
|
17733
|
-
|
|
17734
|
-
|
|
17735
|
-
|
|
17736
|
-
Object.keys(spanAny.attributes).forEach(
|
|
17737
|
-
(k) => delete spanAny.attributes[k]
|
|
17738
|
-
);
|
|
17739
|
-
Object.assign(spanAny.attributes, scrubbedAttributes);
|
|
17723
|
+
shutdown() {
|
|
17724
|
+
return Promise.resolve();
|
|
17725
|
+
}
|
|
17726
|
+
forceFlush() {
|
|
17727
|
+
return Promise.resolve();
|
|
17728
|
+
}
|
|
17729
|
+
wrapSetAttribute(span2) {
|
|
17730
|
+
const original = span2.setAttribute.bind(span2);
|
|
17731
|
+
const patched = (key, value) => {
|
|
17732
|
+
try {
|
|
17733
|
+
return original(key, scrubValue(key, value));
|
|
17734
|
+
} catch {
|
|
17735
|
+
try {
|
|
17736
|
+
return original(key, value);
|
|
17737
|
+
} catch {
|
|
17738
|
+
return span2;
|
|
17740
17739
|
}
|
|
17741
17740
|
}
|
|
17741
|
+
};
|
|
17742
|
+
span2.setAttribute = patched;
|
|
17743
|
+
}
|
|
17744
|
+
};
|
|
17745
|
+
|
|
17746
|
+
// src/processors/serialization-span-processor.ts
|
|
17747
|
+
var SerializationSpanProcessor = class {
|
|
17748
|
+
constructor(maxAttributeSize) {
|
|
17749
|
+
this.maxAttributeSize = maxAttributeSize ?? Config.SPAN_ATTRIBUTE_MAX_SIZE;
|
|
17750
|
+
}
|
|
17751
|
+
onStart(span2, _parentContext) {
|
|
17752
|
+
try {
|
|
17753
|
+
this.wrapSetAttribute(span2);
|
|
17742
17754
|
} catch (e) {
|
|
17743
|
-
Logger.
|
|
17755
|
+
Logger.debug("SerializationSpanProcessor.onStart error:", e);
|
|
17744
17756
|
}
|
|
17745
17757
|
}
|
|
17746
|
-
|
|
17747
|
-
|
|
17748
|
-
*/
|
|
17758
|
+
onEnd(_span) {
|
|
17759
|
+
}
|
|
17749
17760
|
shutdown() {
|
|
17750
17761
|
return Promise.resolve();
|
|
17751
17762
|
}
|
|
17752
|
-
/**
|
|
17753
|
-
* Forces a flush of any pending spans.
|
|
17754
|
-
*/
|
|
17755
17763
|
forceFlush() {
|
|
17756
17764
|
return Promise.resolve();
|
|
17757
17765
|
}
|
|
17766
|
+
wrapSetAttribute(span2) {
|
|
17767
|
+
const original = span2.setAttribute.bind(span2);
|
|
17768
|
+
const maxSize = this.maxAttributeSize;
|
|
17769
|
+
const patched = (key, value) => {
|
|
17770
|
+
try {
|
|
17771
|
+
const truncated = serializeAttribute(value, maxSize);
|
|
17772
|
+
return original(key, truncated);
|
|
17773
|
+
} catch {
|
|
17774
|
+
try {
|
|
17775
|
+
return original(key, value);
|
|
17776
|
+
} catch {
|
|
17777
|
+
return span2;
|
|
17778
|
+
}
|
|
17779
|
+
}
|
|
17780
|
+
};
|
|
17781
|
+
span2.setAttribute = patched;
|
|
17782
|
+
}
|
|
17758
17783
|
};
|
|
17759
17784
|
function getContextManager() {
|
|
17760
17785
|
try {
|
|
@@ -17864,107 +17889,195 @@ var SessionSpanProcessor = class {
|
|
|
17864
17889
|
return Promise.resolve();
|
|
17865
17890
|
}
|
|
17866
17891
|
};
|
|
17867
|
-
|
|
17892
|
+
|
|
17893
|
+
// src/processors/root-instrument-filter-processor.ts
|
|
17894
|
+
var INVALID_SPAN_ID = "0000000000000000";
|
|
17868
17895
|
var INSTRUMENTATION_PREFIXES = [
|
|
17869
17896
|
"opentelemetry.instrumentation.",
|
|
17870
17897
|
"netra.instrumentation.",
|
|
17871
17898
|
"@opentelemetry/instrumentation-",
|
|
17872
17899
|
"@traceloop/instrumentation-"
|
|
17873
17900
|
];
|
|
17874
|
-
var
|
|
17875
|
-
var
|
|
17901
|
+
var MAX_ROOT_CANDIDATES = 4096;
|
|
17902
|
+
var ROOT_CANDIDATE_TTL_MS = 6e5;
|
|
17903
|
+
var EVICTION_INTERVAL_MS = 1e4;
|
|
17904
|
+
function canonicalInstrumentName(name) {
|
|
17905
|
+
return name.toLowerCase().replace(/_/g, "");
|
|
17906
|
+
}
|
|
17907
|
+
var ROOT_BLOCK_CANDIDATE_FIELD = "_netraRootBlockCandidate";
|
|
17908
|
+
var ROOT_BLOCK_CANDIDATES = /* @__PURE__ */ new Map();
|
|
17909
|
+
function getRootBlockCandidatesFor(seedIds) {
|
|
17910
|
+
const out = /* @__PURE__ */ new Map();
|
|
17911
|
+
const stack = [...seedIds];
|
|
17912
|
+
while (stack.length > 0) {
|
|
17913
|
+
const spanId = stack.pop();
|
|
17914
|
+
if (spanId === void 0 || out.has(spanId)) {
|
|
17915
|
+
continue;
|
|
17916
|
+
}
|
|
17917
|
+
const entry = ROOT_BLOCK_CANDIDATES.get(spanId);
|
|
17918
|
+
if (!entry) {
|
|
17919
|
+
continue;
|
|
17920
|
+
}
|
|
17921
|
+
out.set(spanId, entry.parentCtx);
|
|
17922
|
+
const parentId = entry.parentCtx?.spanId;
|
|
17923
|
+
if (parentId && parentId !== INVALID_SPAN_ID) {
|
|
17924
|
+
stack.push(parentId);
|
|
17925
|
+
}
|
|
17926
|
+
}
|
|
17927
|
+
return out;
|
|
17928
|
+
}
|
|
17929
|
+
function resetRootBlockCandidates() {
|
|
17930
|
+
ROOT_BLOCK_CANDIDATES.clear();
|
|
17931
|
+
}
|
|
17932
|
+
function rootBlockCandidatesContains(spanIds) {
|
|
17933
|
+
if (spanIds.size === 0) {
|
|
17934
|
+
return false;
|
|
17935
|
+
}
|
|
17936
|
+
for (const spanId of spanIds) {
|
|
17937
|
+
if (ROOT_BLOCK_CANDIDATES.has(spanId)) {
|
|
17938
|
+
return true;
|
|
17939
|
+
}
|
|
17940
|
+
}
|
|
17941
|
+
return false;
|
|
17942
|
+
}
|
|
17943
|
+
function isRootBlockCandidate(span2) {
|
|
17944
|
+
return Boolean(span2?.[ROOT_BLOCK_CANDIDATE_FIELD]);
|
|
17945
|
+
}
|
|
17876
17946
|
var RootInstrumentFilterProcessor = class {
|
|
17877
17947
|
constructor(allowedRootInstrumentNames) {
|
|
17878
|
-
this.
|
|
17879
|
-
this._allowed = new Set(
|
|
17948
|
+
this._lastEvictionAt = 0;
|
|
17949
|
+
this._allowed = new Set(
|
|
17950
|
+
[...allowedRootInstrumentNames].map(canonicalInstrumentName)
|
|
17951
|
+
);
|
|
17952
|
+
resetRootBlockCandidates();
|
|
17880
17953
|
}
|
|
17881
|
-
onStart(span2,
|
|
17954
|
+
onStart(span2, _parentContext) {
|
|
17882
17955
|
try {
|
|
17883
|
-
this._processSpanStart(span2
|
|
17956
|
+
this._processSpanStart(span2);
|
|
17884
17957
|
} catch {
|
|
17885
17958
|
}
|
|
17886
17959
|
}
|
|
17887
17960
|
onEnd(span2) {
|
|
17888
17961
|
try {
|
|
17889
|
-
|
|
17962
|
+
const now = Date.now();
|
|
17963
|
+
this._markEnded(span2, now);
|
|
17964
|
+
this._evictStaleCandidates(now);
|
|
17890
17965
|
} catch {
|
|
17891
17966
|
}
|
|
17892
17967
|
}
|
|
17968
|
+
/**
|
|
17969
|
+
* No-op — the candidate registry is deliberately NOT cleared here.
|
|
17970
|
+
*
|
|
17971
|
+
* `MultiSpanProcessor.shutdown()` invokes every registered processor's
|
|
17972
|
+
* `shutdown()` concurrently (`Promise.all`), so clearing the shared registry
|
|
17973
|
+
* here could race with the exporter's final flush still reading it to
|
|
17974
|
+
* reparent buffered blocked roots. Fresh sessions instead reset the registry
|
|
17975
|
+
* on construction (see the constructor); it is also bounded
|
|
17976
|
+
* (`MAX_ROOT_CANDIDATES`) and TTL-evicted, so leaving it intact on shutdown
|
|
17977
|
+
* is safe.
|
|
17978
|
+
*/
|
|
17893
17979
|
shutdown() {
|
|
17894
|
-
this._blockedTraceIds.clear();
|
|
17895
17980
|
return Promise.resolve();
|
|
17896
17981
|
}
|
|
17897
17982
|
forceFlush() {
|
|
17898
17983
|
return Promise.resolve();
|
|
17899
17984
|
}
|
|
17900
|
-
_processSpanStart(span2
|
|
17901
|
-
const parentSpanId = this._resolveParentSpanId(parentContext) ?? this._getParentSpanIdFromSpan(span2);
|
|
17902
|
-
const isChild = parentSpanId !== null && parentSpanId !== "0000000000000000";
|
|
17903
|
-
if (isChild) {
|
|
17904
|
-
this._maybeBlockChild(span2);
|
|
17905
|
-
} else {
|
|
17906
|
-
this._maybeBlockRoot(span2);
|
|
17907
|
-
}
|
|
17908
|
-
}
|
|
17909
|
-
_maybeBlockChild(span2) {
|
|
17910
|
-
const traceId = this._getTraceId(span2);
|
|
17911
|
-
if (!traceId) {
|
|
17912
|
-
return;
|
|
17913
|
-
}
|
|
17914
|
-
if (this._blockedTraceIds.has(traceId)) {
|
|
17915
|
-
this._markBlocked(span2);
|
|
17916
|
-
}
|
|
17917
|
-
}
|
|
17918
|
-
_maybeBlockRoot(span2) {
|
|
17985
|
+
_processSpanStart(span2) {
|
|
17919
17986
|
if (!this._isFromInstrumentationLibrary(span2)) {
|
|
17920
17987
|
return;
|
|
17921
17988
|
}
|
|
17922
17989
|
const instrName = this._extractInstrumentationName(span2);
|
|
17923
|
-
if (instrName === null || this._allowed.has(instrName)) {
|
|
17990
|
+
if (instrName === null || this._allowed.has(canonicalInstrumentName(instrName))) {
|
|
17924
17991
|
return;
|
|
17925
17992
|
}
|
|
17926
|
-
const
|
|
17927
|
-
if (
|
|
17928
|
-
|
|
17929
|
-
this._evictOverflow();
|
|
17993
|
+
const spanId = this._getOwnSpanId(span2);
|
|
17994
|
+
if (spanId === null || spanId === INVALID_SPAN_ID) {
|
|
17995
|
+
return;
|
|
17930
17996
|
}
|
|
17931
|
-
this.
|
|
17997
|
+
const parentCtx = this._getParentSpanContext(span2);
|
|
17998
|
+
this._markCandidate(span2);
|
|
17999
|
+
this._recordCandidate(spanId, parentCtx);
|
|
17932
18000
|
}
|
|
17933
|
-
|
|
17934
|
-
|
|
17935
|
-
|
|
17936
|
-
|
|
18001
|
+
_markCandidate(span2) {
|
|
18002
|
+
try {
|
|
18003
|
+
span2[ROOT_BLOCK_CANDIDATE_FIELD] = true;
|
|
18004
|
+
} catch {
|
|
17937
18005
|
}
|
|
17938
|
-
|
|
17939
|
-
|
|
17940
|
-
|
|
18006
|
+
}
|
|
18007
|
+
/**
|
|
18008
|
+
* Register `spanId` as an active candidate. `move-to-end` semantics
|
|
18009
|
+
* (delete+set) refresh insertion order; overflow drops the oldest entry.
|
|
18010
|
+
*/
|
|
18011
|
+
_recordCandidate(spanId, parentCtx) {
|
|
18012
|
+
ROOT_BLOCK_CANDIDATES.delete(spanId);
|
|
18013
|
+
ROOT_BLOCK_CANDIDATES.set(spanId, { parentCtx, endedAt: null });
|
|
18014
|
+
while (ROOT_BLOCK_CANDIDATES.size > MAX_ROOT_CANDIDATES) {
|
|
18015
|
+
const oldest = ROOT_BLOCK_CANDIDATES.keys().next().value;
|
|
18016
|
+
if (oldest === void 0) {
|
|
18017
|
+
break;
|
|
18018
|
+
}
|
|
18019
|
+
ROOT_BLOCK_CANDIDATES.delete(oldest);
|
|
17941
18020
|
}
|
|
17942
|
-
return sc.spanId;
|
|
17943
18021
|
}
|
|
17944
|
-
|
|
17945
|
-
|
|
17946
|
-
const
|
|
17947
|
-
if (
|
|
17948
|
-
return
|
|
18022
|
+
/** Start the TTL clock for a just-ended candidate, if it has an entry. */
|
|
18023
|
+
_markEnded(span2, now) {
|
|
18024
|
+
const spanId = this._getOwnSpanId(span2);
|
|
18025
|
+
if (spanId === null) {
|
|
18026
|
+
return;
|
|
18027
|
+
}
|
|
18028
|
+
const entry = ROOT_BLOCK_CANDIDATES.get(spanId);
|
|
18029
|
+
if (entry) {
|
|
18030
|
+
entry.endedAt = now;
|
|
17949
18031
|
}
|
|
17950
|
-
return parent;
|
|
17951
18032
|
}
|
|
17952
|
-
|
|
17953
|
-
|
|
17954
|
-
|
|
17955
|
-
|
|
17956
|
-
|
|
18033
|
+
/**
|
|
18034
|
+
* Evict entries whose span ended more than `ROOT_CANDIDATE_TTL_MS` ago.
|
|
18035
|
+
* Active candidates (`endedAt === null`) are skipped — never evicted while the
|
|
18036
|
+
* span is still open.
|
|
18037
|
+
*
|
|
18038
|
+
* The scan cannot break early: the registry is ordered by span *start*
|
|
18039
|
+
* (insertion) whereas staleness is measured from span *end*, and those two
|
|
18040
|
+
* orders do not coincide (a long-lived active root sits at the head while
|
|
18041
|
+
* short spans behind it may already be stale). A full sweep is therefore
|
|
18042
|
+
* required, but it is time-throttled (`EVICTION_INTERVAL_MS`) so it does not
|
|
18043
|
+
* run on every span end.
|
|
18044
|
+
*/
|
|
18045
|
+
_evictStaleCandidates(now) {
|
|
18046
|
+
if (now - this._lastEvictionAt < EVICTION_INTERVAL_MS) {
|
|
18047
|
+
return;
|
|
18048
|
+
}
|
|
18049
|
+
this._lastEvictionAt = now;
|
|
18050
|
+
const cutoff = now - ROOT_CANDIDATE_TTL_MS;
|
|
18051
|
+
for (const [spanId, entry] of ROOT_BLOCK_CANDIDATES) {
|
|
18052
|
+
if (entry.endedAt !== null && entry.endedAt <= cutoff) {
|
|
18053
|
+
ROOT_BLOCK_CANDIDATES.delete(spanId);
|
|
17957
18054
|
}
|
|
17958
|
-
} catch {
|
|
17959
18055
|
}
|
|
17960
|
-
return null;
|
|
17961
18056
|
}
|
|
17962
|
-
|
|
18057
|
+
_getOwnSpanId(span2) {
|
|
17963
18058
|
try {
|
|
17964
|
-
span2.
|
|
18059
|
+
const sc = span2.spanContext?.() ?? span2.spanContext;
|
|
18060
|
+
const spanId = sc?.spanId;
|
|
18061
|
+
return typeof spanId === "string" && spanId ? spanId : null;
|
|
17965
18062
|
} catch {
|
|
18063
|
+
return null;
|
|
17966
18064
|
}
|
|
17967
18065
|
}
|
|
18066
|
+
/**
|
|
18067
|
+
* Resolve the parent `SpanContext` recorded on the span, normalizing an
|
|
18068
|
+
* invalid/sentinel parent to `undefined` (= trace root).
|
|
18069
|
+
*/
|
|
18070
|
+
_getParentSpanContext(span2) {
|
|
18071
|
+
const spanAny = span2;
|
|
18072
|
+
const parent = spanAny.parentSpanContext ?? spanAny.parent;
|
|
18073
|
+
if (!parent) {
|
|
18074
|
+
return void 0;
|
|
18075
|
+
}
|
|
18076
|
+
if (!parent.spanId || parent.spanId === INVALID_SPAN_ID) {
|
|
18077
|
+
return void 0;
|
|
18078
|
+
}
|
|
18079
|
+
return parent;
|
|
18080
|
+
}
|
|
17968
18081
|
_isFromInstrumentationLibrary(span2) {
|
|
17969
18082
|
const spanAny = span2;
|
|
17970
18083
|
const scope = spanAny.instrumentationLibrary || spanAny.instrumentationScope;
|
|
@@ -17998,25 +18111,6 @@ var RootInstrumentFilterProcessor = class {
|
|
|
17998
18111
|
}
|
|
17999
18112
|
return name;
|
|
18000
18113
|
}
|
|
18001
|
-
_evictStaleTraces() {
|
|
18002
|
-
const cutoff = Date.now() - BLOCKED_TRACE_TTL_MS;
|
|
18003
|
-
for (const [traceId, entry] of this._blockedTraceIds) {
|
|
18004
|
-
if (entry.timestamp > cutoff) {
|
|
18005
|
-
break;
|
|
18006
|
-
}
|
|
18007
|
-
this._blockedTraceIds.delete(traceId);
|
|
18008
|
-
}
|
|
18009
|
-
}
|
|
18010
|
-
_evictOverflow() {
|
|
18011
|
-
while (this._blockedTraceIds.size > MAX_BLOCKED_TRACES) {
|
|
18012
|
-
const first = this._blockedTraceIds.keys().next().value;
|
|
18013
|
-
if (first !== void 0) {
|
|
18014
|
-
this._blockedTraceIds.delete(first);
|
|
18015
|
-
} else {
|
|
18016
|
-
break;
|
|
18017
|
-
}
|
|
18018
|
-
}
|
|
18019
|
-
}
|
|
18020
18114
|
};
|
|
18021
18115
|
|
|
18022
18116
|
// src/processors/span-io-processor.ts
|
|
@@ -18539,7 +18633,7 @@ function buildInputMessages(kwargs, requestType) {
|
|
|
18539
18633
|
tool_use_id: block.tool_use_id,
|
|
18540
18634
|
content: block.content,
|
|
18541
18635
|
is_error: block.is_error ?? false
|
|
18542
|
-
}
|
|
18636
|
+
})
|
|
18543
18637
|
});
|
|
18544
18638
|
}
|
|
18545
18639
|
}
|
|
@@ -18569,7 +18663,7 @@ function buildInputMessages(kwargs, requestType) {
|
|
|
18569
18663
|
} else {
|
|
18570
18664
|
const input = kwargs.input ?? kwargs.inputs;
|
|
18571
18665
|
if (hasContent(input)) {
|
|
18572
|
-
const content = safeStringify(input
|
|
18666
|
+
const content = safeStringify(input);
|
|
18573
18667
|
messages.push({ role: "user", content });
|
|
18574
18668
|
}
|
|
18575
18669
|
}
|
|
@@ -18706,7 +18800,7 @@ function setRequestAttributes(span2, kwargs, requestType, system) {
|
|
|
18706
18800
|
}
|
|
18707
18801
|
setModelParams(span2, kwargs);
|
|
18708
18802
|
if (Array.isArray(kwargs.tools)) {
|
|
18709
|
-
span2.setAttribute("tools", safeStringify(kwargs.tools
|
|
18803
|
+
span2.setAttribute("tools", safeStringify(kwargs.tools));
|
|
18710
18804
|
}
|
|
18711
18805
|
if (kwargs.reasoning !== void 0) {
|
|
18712
18806
|
span2.setAttribute(
|
|
@@ -18720,7 +18814,7 @@ function setRequestAttributes(span2, kwargs, requestType, system) {
|
|
|
18720
18814
|
if (kwargs.suffix !== void 0) {
|
|
18721
18815
|
span2.setAttribute(
|
|
18722
18816
|
"llm.request.suffix",
|
|
18723
|
-
safeStringify(kwargs.suffix
|
|
18817
|
+
safeStringify(kwargs.suffix)
|
|
18724
18818
|
);
|
|
18725
18819
|
}
|
|
18726
18820
|
}
|
|
@@ -19012,7 +19106,6 @@ var TRACKED_STREAM_EVENTS = /* @__PURE__ */ new Set([
|
|
|
19012
19106
|
"text",
|
|
19013
19107
|
"finalMessage"
|
|
19014
19108
|
]);
|
|
19015
|
-
var MAX_TOOL_ATTR_LENGTH = 4096;
|
|
19016
19109
|
function wrapRunnableTools(tools, tracer, parentContext) {
|
|
19017
19110
|
return tools.map((tool) => {
|
|
19018
19111
|
if (typeof tool.run !== "function") return tool;
|
|
@@ -19027,7 +19120,7 @@ function wrapRunnableTools(tools, tracer, parentContext) {
|
|
|
19027
19120
|
};
|
|
19028
19121
|
if (toolUseId) attrs[SpanAttributes2.LLM_REQUEST_TOOL_ID] = toolUseId;
|
|
19029
19122
|
if (traceContent) {
|
|
19030
|
-
attrs.input = safeStringify(input
|
|
19123
|
+
attrs.input = safeStringify(input);
|
|
19031
19124
|
}
|
|
19032
19125
|
const span2 = tracer.startSpan(
|
|
19033
19126
|
toolName,
|
|
@@ -19041,10 +19134,7 @@ function wrapRunnableTools(tools, tracer, parentContext) {
|
|
|
19041
19134
|
() => originalRun.call(this, input, runContext)
|
|
19042
19135
|
);
|
|
19043
19136
|
if (traceContent) {
|
|
19044
|
-
span2.setAttribute(
|
|
19045
|
-
"output",
|
|
19046
|
-
safeStringify(result, MAX_TOOL_ATTR_LENGTH)
|
|
19047
|
-
);
|
|
19137
|
+
span2.setAttribute("output", safeStringify(result));
|
|
19048
19138
|
}
|
|
19049
19139
|
span2.setStatus({ code: api.SpanStatusCode.OK });
|
|
19050
19140
|
return result;
|
|
@@ -20039,7 +20129,7 @@ function extractModelName(model) {
|
|
|
20039
20129
|
function buildGoogleInputMessages(params, cfg) {
|
|
20040
20130
|
const messages = [];
|
|
20041
20131
|
if (hasContent(cfg.systemInstruction)) {
|
|
20042
|
-
const sysContent = typeof cfg.systemInstruction === "string" ? cfg.systemInstruction : safeStringify(cfg.systemInstruction
|
|
20132
|
+
const sysContent = typeof cfg.systemInstruction === "string" ? cfg.systemInstruction : safeStringify(cfg.systemInstruction);
|
|
20043
20133
|
messages.push({ role: "system", content: sysContent });
|
|
20044
20134
|
}
|
|
20045
20135
|
const history = params._history;
|
|
@@ -20072,7 +20162,7 @@ function buildGoogleInputMessages(params, cfg) {
|
|
|
20072
20162
|
} else {
|
|
20073
20163
|
messages.push({
|
|
20074
20164
|
role: "user",
|
|
20075
|
-
content: safeStringify(item
|
|
20165
|
+
content: safeStringify(item)
|
|
20076
20166
|
});
|
|
20077
20167
|
}
|
|
20078
20168
|
}
|
|
@@ -20085,7 +20175,7 @@ function buildGoogleInputMessages(params, cfg) {
|
|
|
20085
20175
|
} else {
|
|
20086
20176
|
messages.push({
|
|
20087
20177
|
role: "user",
|
|
20088
|
-
content: safeStringify(contents
|
|
20178
|
+
content: safeStringify(contents)
|
|
20089
20179
|
});
|
|
20090
20180
|
}
|
|
20091
20181
|
return messages;
|
|
@@ -20101,10 +20191,10 @@ function extractTextFromParts(parts) {
|
|
|
20101
20191
|
if (typeof part.text === "string") {
|
|
20102
20192
|
texts.push(part.text);
|
|
20103
20193
|
} else if (part.functionCall) {
|
|
20104
|
-
texts.push(safeStringify(part.functionCall
|
|
20194
|
+
texts.push(safeStringify(part.functionCall));
|
|
20105
20195
|
} else if (part.functionResponse) {
|
|
20106
20196
|
texts.push(
|
|
20107
|
-
safeStringify(part.functionResponse
|
|
20197
|
+
safeStringify(part.functionResponse)
|
|
20108
20198
|
);
|
|
20109
20199
|
}
|
|
20110
20200
|
}
|
|
@@ -20226,8 +20316,7 @@ function buildGoogleOutputMessages(response) {
|
|
|
20226
20316
|
messages.push({
|
|
20227
20317
|
role: "tool",
|
|
20228
20318
|
content: safeStringify(
|
|
20229
|
-
{ name: fc.name, arguments: fc.args }
|
|
20230
|
-
Config.CONVERSATION_MAX_LEN
|
|
20319
|
+
{ name: fc.name, arguments: fc.args }
|
|
20231
20320
|
)
|
|
20232
20321
|
});
|
|
20233
20322
|
}
|
|
@@ -20247,8 +20336,7 @@ function buildGoogleOutputMessages(response) {
|
|
|
20247
20336
|
messages.push({
|
|
20248
20337
|
role: "tool",
|
|
20249
20338
|
content: safeStringify(
|
|
20250
|
-
{ name: fc.name, arguments: fc.args }
|
|
20251
|
-
Config.CONVERSATION_MAX_LEN
|
|
20339
|
+
{ name: fc.name, arguments: fc.args }
|
|
20252
20340
|
)
|
|
20253
20341
|
});
|
|
20254
20342
|
}
|
|
@@ -20784,10 +20872,7 @@ function _setPromptAttributes(span2, kwargs, args) {
|
|
|
20784
20872
|
promptIndex++;
|
|
20785
20873
|
}
|
|
20786
20874
|
if (inlineDataParts.length > 0) {
|
|
20787
|
-
span2.setAttribute(
|
|
20788
|
-
`gen_ai.prompt.${slotIndex}.has_inline_data`,
|
|
20789
|
-
true
|
|
20790
|
-
);
|
|
20875
|
+
span2.setAttribute(`gen_ai.prompt.${slotIndex}.has_inline_data`, true);
|
|
20791
20876
|
span2.setAttribute(
|
|
20792
20877
|
`gen_ai.prompt.${slotIndex}.inline_data_count`,
|
|
20793
20878
|
inlineDataParts.length
|
|
@@ -24159,7 +24244,6 @@ var openAIInstrumentor = new NetraOpenAIInstrumentor();
|
|
|
24159
24244
|
var INSTRUMENTATION_NAME6 = "netra.instrumentation.openai_agents";
|
|
24160
24245
|
var DEFAULT_LLM_SYSTEM = "openai";
|
|
24161
24246
|
var MAX_INDEXED_MESSAGES = 128;
|
|
24162
|
-
var MAX_STRINGIFY_LENGTH = 65536;
|
|
24163
24247
|
var NETRA_SPAN_TYPE_ATTR = "netra.span.type";
|
|
24164
24248
|
var NETRA_WORKFLOW_NAME = "netra.workflow.name";
|
|
24165
24249
|
var NETRA_AGENT_NAME = "netra.agent.name";
|
|
@@ -24183,17 +24267,6 @@ var GEN_AI_TOOL_NAME = "gen_ai.tool.name";
|
|
|
24183
24267
|
var GEN_AI_RESPONSE_ID = "gen_ai.response.id";
|
|
24184
24268
|
|
|
24185
24269
|
// src/instrumentation/openai-agents/utils.ts
|
|
24186
|
-
function safeJsonStringify(obj, maxLength = MAX_STRINGIFY_LENGTH) {
|
|
24187
|
-
try {
|
|
24188
|
-
if (typeof obj === "string") {
|
|
24189
|
-
return maxLength > 0 && obj.length > maxLength ? obj.slice(0, maxLength) : obj;
|
|
24190
|
-
}
|
|
24191
|
-
const s = JSON.stringify(obj);
|
|
24192
|
-
return maxLength > 0 && s.length > maxLength ? s.slice(0, maxLength) : s;
|
|
24193
|
-
} catch {
|
|
24194
|
-
return String(obj);
|
|
24195
|
-
}
|
|
24196
|
-
}
|
|
24197
24270
|
function getNetraSpanType(data) {
|
|
24198
24271
|
switch (data.type) {
|
|
24199
24272
|
case "agent":
|
|
@@ -24215,7 +24288,8 @@ function getNetraSpanType(data) {
|
|
|
24215
24288
|
function getSpanName(agentSpan) {
|
|
24216
24289
|
const data = agentSpan.spanData;
|
|
24217
24290
|
if (data.name) return data.name;
|
|
24218
|
-
if (data.type === "handoff" && data.to_agent)
|
|
24291
|
+
if (data.type === "handoff" && data.to_agent)
|
|
24292
|
+
return `handoff to ${data.to_agent}`;
|
|
24219
24293
|
return `openai.agents.${data.type}`;
|
|
24220
24294
|
}
|
|
24221
24295
|
function extractContentString(content) {
|
|
@@ -24231,7 +24305,7 @@ function extractContentString(content) {
|
|
|
24231
24305
|
}
|
|
24232
24306
|
}
|
|
24233
24307
|
}
|
|
24234
|
-
return texts.length > 0 ? texts.join(" ") :
|
|
24308
|
+
return texts.length > 0 ? texts.join(" ") : safeStringify(content);
|
|
24235
24309
|
}
|
|
24236
24310
|
return String(content);
|
|
24237
24311
|
}
|
|
@@ -24318,12 +24392,12 @@ function setGenerationAttributes(span2, data, systemName) {
|
|
|
24318
24392
|
span2.setAttribute(SpanAttributes2.LLM_PRESENCE_PENALTY, Number(config.presence_penalty));
|
|
24319
24393
|
}
|
|
24320
24394
|
if (config.stop !== void 0) {
|
|
24321
|
-
span2.setAttribute(SpanAttributes2.LLM_CHAT_STOP_SEQUENCES,
|
|
24395
|
+
span2.setAttribute(SpanAttributes2.LLM_CHAT_STOP_SEQUENCES, safeStringify(config.stop));
|
|
24322
24396
|
}
|
|
24323
24397
|
if (config.reasoning_effort !== void 0) {
|
|
24324
24398
|
span2.setAttribute(SpanAttributes2.LLM_REQUEST_REASONING_EFFORT, String(config.reasoning_effort));
|
|
24325
24399
|
} else if (config.reasoning !== void 0) {
|
|
24326
|
-
span2.setAttribute(SpanAttributes2.LLM_REQUEST_REASONING_EFFORT,
|
|
24400
|
+
span2.setAttribute(SpanAttributes2.LLM_REQUEST_REASONING_EFFORT, safeStringify(config.reasoning));
|
|
24327
24401
|
}
|
|
24328
24402
|
}
|
|
24329
24403
|
const effectiveOutput = unwrapGenerationOutput(data.output);
|
|
@@ -24383,11 +24457,11 @@ function setFunctionAttributes(span2, data) {
|
|
|
24383
24457
|
}
|
|
24384
24458
|
if (data.input !== void 0) {
|
|
24385
24459
|
span2.setAttribute(`${SpanAttributes2.LLM_PROMPTS}.0.role`, "tool");
|
|
24386
|
-
span2.setAttribute(`${SpanAttributes2.LLM_PROMPTS}.0.content`,
|
|
24460
|
+
span2.setAttribute(`${SpanAttributes2.LLM_PROMPTS}.0.content`, safeStringify(data.input));
|
|
24387
24461
|
}
|
|
24388
24462
|
if (data.output !== void 0) {
|
|
24389
24463
|
span2.setAttribute(`${SpanAttributes2.LLM_COMPLETIONS}.0.role`, "tool");
|
|
24390
|
-
span2.setAttribute(`${SpanAttributes2.LLM_COMPLETIONS}.0.content`,
|
|
24464
|
+
span2.setAttribute(`${SpanAttributes2.LLM_COMPLETIONS}.0.content`, safeStringify(data.output));
|
|
24391
24465
|
}
|
|
24392
24466
|
}
|
|
24393
24467
|
function setHandoffAttributes(span2, data) {
|
|
@@ -24417,7 +24491,7 @@ function setCustomAttributes(span2, data) {
|
|
|
24417
24491
|
span2.setAttribute(NETRA_SPAN_NAME, data.name);
|
|
24418
24492
|
}
|
|
24419
24493
|
if (data.data !== void 0) {
|
|
24420
|
-
span2.setAttribute(NETRA_CUSTOM_DATA,
|
|
24494
|
+
span2.setAttribute(NETRA_CUSTOM_DATA, safeStringify(data.data));
|
|
24421
24495
|
}
|
|
24422
24496
|
}
|
|
24423
24497
|
function setUsageAttributes3(span2, usage) {
|
|
@@ -24483,7 +24557,7 @@ function setResponseObjectAttributes(span2, response) {
|
|
|
24483
24557
|
span2.setAttribute(SpanAttributes2.LLM_PRESENCE_PENALTY, resp.presence_penalty);
|
|
24484
24558
|
}
|
|
24485
24559
|
if (resp.reasoning !== void 0) {
|
|
24486
|
-
span2.setAttribute(SpanAttributes2.LLM_REQUEST_REASONING_EFFORT,
|
|
24560
|
+
span2.setAttribute(SpanAttributes2.LLM_REQUEST_REASONING_EFFORT, safeStringify(resp.reasoning));
|
|
24487
24561
|
}
|
|
24488
24562
|
if (resp.usage) {
|
|
24489
24563
|
setResponseObjectUsageAttributes(span2, resp.usage);
|
|
@@ -24529,7 +24603,7 @@ function setIndexedPromptAttributes(span2, input, startIndex = 0) {
|
|
|
24529
24603
|
span2.setAttribute(`${SpanAttributes2.LLM_PROMPTS}.${index}.role`, "assistant");
|
|
24530
24604
|
span2.setAttribute(
|
|
24531
24605
|
`${SpanAttributes2.LLM_PROMPTS}.${index}.content`,
|
|
24532
|
-
|
|
24606
|
+
safeStringify({ name: msg.name, arguments: msg.arguments })
|
|
24533
24607
|
);
|
|
24534
24608
|
} else if (msgType === "function_call_output" || msgType === "function_call_result") {
|
|
24535
24609
|
span2.setAttribute(`${SpanAttributes2.LLM_PROMPTS}.${index}.role`, "tool");
|
|
@@ -24573,7 +24647,7 @@ function setIndexedCompletionAttributes(span2, responseData) {
|
|
|
24573
24647
|
span2.setAttribute(`${SpanAttributes2.LLM_COMPLETIONS}.${index}.role`, "assistant");
|
|
24574
24648
|
span2.setAttribute(
|
|
24575
24649
|
`${SpanAttributes2.LLM_COMPLETIONS}.${index}.content`,
|
|
24576
|
-
|
|
24650
|
+
safeStringify({ name: element.name, arguments: element.arguments })
|
|
24577
24651
|
);
|
|
24578
24652
|
const toolCallId = element.call_id || element.id;
|
|
24579
24653
|
if (toolCallId) {
|
|
@@ -24610,7 +24684,7 @@ function setIndexedCompletionAttributes(span2, responseData) {
|
|
|
24610
24684
|
span2.setAttribute(`${SpanAttributes2.LLM_COMPLETIONS}.${index}.role`, "assistant");
|
|
24611
24685
|
span2.setAttribute(
|
|
24612
24686
|
`${SpanAttributes2.LLM_COMPLETIONS}.${index}.content`,
|
|
24613
|
-
|
|
24687
|
+
safeStringify({ name: func.name ?? "", arguments: func.arguments ?? "" })
|
|
24614
24688
|
);
|
|
24615
24689
|
if (tc.id) {
|
|
24616
24690
|
span2.setAttribute(`${SpanAttributes2.LLM_COMPLETIONS}.${index}.tool_call_id`, String(tc.id));
|
|
@@ -24713,7 +24787,7 @@ var _NetraAgentsTracingProcessor = class _NetraAgentsTracingProcessor {
|
|
|
24713
24787
|
span2.setAttribute(NETRA_AGENTS_GROUP_ID, agentTrace.groupId);
|
|
24714
24788
|
}
|
|
24715
24789
|
if (agentTrace.metadata) {
|
|
24716
|
-
span2.setAttribute(NETRA_AGENTS_METADATA,
|
|
24790
|
+
span2.setAttribute(NETRA_AGENTS_METADATA, safeStringify(agentTrace.metadata));
|
|
24717
24791
|
}
|
|
24718
24792
|
this._rootSpans.set(agentTrace.traceId, span2);
|
|
24719
24793
|
}
|
|
@@ -24799,7 +24873,8 @@ var _NetraAgentsTracingProcessor = class _NetraAgentsTracingProcessor {
|
|
|
24799
24873
|
}
|
|
24800
24874
|
}
|
|
24801
24875
|
if (agentSpan.error) {
|
|
24802
|
-
const
|
|
24876
|
+
const MAX_ERROR_DATA_LEN = 4096;
|
|
24877
|
+
const errorMsg = agentSpan.error.data ? `${agentSpan.error.message}: ${safeStringify(agentSpan.error.data, { maxLength: MAX_ERROR_DATA_LEN })}` : agentSpan.error.message;
|
|
24803
24878
|
span2.setStatus({ code: api.SpanStatusCode.ERROR, message: errorMsg });
|
|
24804
24879
|
span2.recordException(new Error(agentSpan.error.message));
|
|
24805
24880
|
this._traceErrors.add(agentSpan.traceId);
|
|
@@ -25453,6 +25528,131 @@ function getTraceId(span2) {
|
|
|
25453
25528
|
return "";
|
|
25454
25529
|
}
|
|
25455
25530
|
}
|
|
25531
|
+
function getSpanId(span2) {
|
|
25532
|
+
try {
|
|
25533
|
+
const spanId = span2.spanContext().spanId;
|
|
25534
|
+
return typeof spanId === "string" && spanId ? spanId : null;
|
|
25535
|
+
} catch {
|
|
25536
|
+
return null;
|
|
25537
|
+
}
|
|
25538
|
+
}
|
|
25539
|
+
function normalizeParent(parent) {
|
|
25540
|
+
if (!parent) {
|
|
25541
|
+
return void 0;
|
|
25542
|
+
}
|
|
25543
|
+
if (!parent.spanId || parent.spanId === INVALID_SPAN_ID) {
|
|
25544
|
+
return void 0;
|
|
25545
|
+
}
|
|
25546
|
+
return parent;
|
|
25547
|
+
}
|
|
25548
|
+
function findRootSpansBlocked(spans, parentsOfSpansBlockedByName) {
|
|
25549
|
+
const candidates = collectRootBlockCandidates(spans);
|
|
25550
|
+
if (candidates.size === 0) {
|
|
25551
|
+
return { rootConnectedIds: /* @__PURE__ */ new Set(), parentsOfRootSpansBlocked: /* @__PURE__ */ new Map() };
|
|
25552
|
+
}
|
|
25553
|
+
if (parentsOfSpansBlockedByName) {
|
|
25554
|
+
for (const [spanId, parentCtx] of parentsOfSpansBlockedByName) {
|
|
25555
|
+
if (!candidates.has(spanId)) {
|
|
25556
|
+
candidates.set(spanId, parentCtx);
|
|
25557
|
+
}
|
|
25558
|
+
}
|
|
25559
|
+
}
|
|
25560
|
+
const rootConnectedIds = findRootConnectedCandidates(spans, candidates);
|
|
25561
|
+
const parentsOfRootSpansBlocked = /* @__PURE__ */ new Map();
|
|
25562
|
+
for (const spanId of rootConnectedIds) {
|
|
25563
|
+
parentsOfRootSpansBlocked.set(spanId, candidates.get(spanId));
|
|
25564
|
+
}
|
|
25565
|
+
return { rootConnectedIds, parentsOfRootSpansBlocked };
|
|
25566
|
+
}
|
|
25567
|
+
function collectRootBlockCandidates(spans) {
|
|
25568
|
+
const inBatch = /* @__PURE__ */ new Map();
|
|
25569
|
+
const parentIds = /* @__PURE__ */ new Set();
|
|
25570
|
+
for (const span2 of spans) {
|
|
25571
|
+
const spanId = getSpanId(span2);
|
|
25572
|
+
if (isRootBlockCandidate(span2) && spanId !== null && spanId !== INVALID_SPAN_ID) {
|
|
25573
|
+
inBatch.set(spanId, normalizeParent(span2.parentSpanContext));
|
|
25574
|
+
}
|
|
25575
|
+
const parent = span2.parentSpanContext;
|
|
25576
|
+
const parentId = parent?.spanId;
|
|
25577
|
+
if (parentId && parentId !== INVALID_SPAN_ID) {
|
|
25578
|
+
parentIds.add(parentId);
|
|
25579
|
+
}
|
|
25580
|
+
}
|
|
25581
|
+
const unresolvedParents = /* @__PURE__ */ new Set();
|
|
25582
|
+
for (const parentId of parentIds) {
|
|
25583
|
+
if (!inBatch.has(parentId)) {
|
|
25584
|
+
unresolvedParents.add(parentId);
|
|
25585
|
+
}
|
|
25586
|
+
}
|
|
25587
|
+
if (!rootBlockCandidatesContains(unresolvedParents)) {
|
|
25588
|
+
return inBatch;
|
|
25589
|
+
}
|
|
25590
|
+
const candidates = getRootBlockCandidatesFor(unresolvedParents);
|
|
25591
|
+
for (const [spanId, parentCtx] of inBatch) {
|
|
25592
|
+
candidates.set(spanId, parentCtx);
|
|
25593
|
+
}
|
|
25594
|
+
return candidates;
|
|
25595
|
+
}
|
|
25596
|
+
function findRootConnectedCandidates(spans, candidates) {
|
|
25597
|
+
const memo = /* @__PURE__ */ new Map();
|
|
25598
|
+
const rootConnectedIds = /* @__PURE__ */ new Set();
|
|
25599
|
+
const resolvesToRoot = (startId) => {
|
|
25600
|
+
const walkedIds = [];
|
|
25601
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
25602
|
+
let currentId = startId;
|
|
25603
|
+
let reachesRoot = false;
|
|
25604
|
+
while (true) {
|
|
25605
|
+
const memoized = memo.get(currentId);
|
|
25606
|
+
if (memoized !== void 0) {
|
|
25607
|
+
reachesRoot = memoized;
|
|
25608
|
+
break;
|
|
25609
|
+
}
|
|
25610
|
+
if (!candidates.has(currentId)) {
|
|
25611
|
+
reachesRoot = false;
|
|
25612
|
+
break;
|
|
25613
|
+
}
|
|
25614
|
+
if (seenIds.has(currentId)) {
|
|
25615
|
+
reachesRoot = false;
|
|
25616
|
+
break;
|
|
25617
|
+
}
|
|
25618
|
+
walkedIds.push(currentId);
|
|
25619
|
+
seenIds.add(currentId);
|
|
25620
|
+
const parentCtx = candidates.get(currentId);
|
|
25621
|
+
if (!parentCtx) {
|
|
25622
|
+
reachesRoot = true;
|
|
25623
|
+
break;
|
|
25624
|
+
}
|
|
25625
|
+
if (parentCtx.isRemote) {
|
|
25626
|
+
reachesRoot = false;
|
|
25627
|
+
break;
|
|
25628
|
+
}
|
|
25629
|
+
const parentId = parentCtx.spanId;
|
|
25630
|
+
if (!parentId || parentId === INVALID_SPAN_ID) {
|
|
25631
|
+
reachesRoot = true;
|
|
25632
|
+
break;
|
|
25633
|
+
}
|
|
25634
|
+
currentId = parentId;
|
|
25635
|
+
}
|
|
25636
|
+
for (const spanId of walkedIds) {
|
|
25637
|
+
memo.set(spanId, reachesRoot);
|
|
25638
|
+
if (reachesRoot) {
|
|
25639
|
+
rootConnectedIds.add(spanId);
|
|
25640
|
+
}
|
|
25641
|
+
}
|
|
25642
|
+
return reachesRoot;
|
|
25643
|
+
};
|
|
25644
|
+
for (const span2 of spans) {
|
|
25645
|
+
const spanId = getSpanId(span2);
|
|
25646
|
+
if (spanId !== null && spanId !== INVALID_SPAN_ID) {
|
|
25647
|
+
resolvesToRoot(spanId);
|
|
25648
|
+
}
|
|
25649
|
+
const parentId = span2.parentSpanContext?.spanId;
|
|
25650
|
+
if (parentId && parentId !== INVALID_SPAN_ID) {
|
|
25651
|
+
resolvesToRoot(parentId);
|
|
25652
|
+
}
|
|
25653
|
+
}
|
|
25654
|
+
return rootConnectedIds;
|
|
25655
|
+
}
|
|
25456
25656
|
|
|
25457
25657
|
// src/exporters/filteringSpanExporter.ts
|
|
25458
25658
|
var ReparentedSpan = class {
|
|
@@ -25525,63 +25725,139 @@ var _FilteringSpanExporter = class _FilteringSpanExporter {
|
|
|
25525
25725
|
this.localPatternCache = /* @__PURE__ */ new Map();
|
|
25526
25726
|
this.compiled = compilePatterns(globalPatterns);
|
|
25527
25727
|
}
|
|
25728
|
+
/**
|
|
25729
|
+
* Filter `spans`, reparent survivors, and forward them to the wrapped exporter.
|
|
25730
|
+
*
|
|
25731
|
+
* While a trial/quota block is active the whole batch is dropped and its trace
|
|
25732
|
+
* ids are remembered so their later spans are dropped too. Otherwise the batch
|
|
25733
|
+
* is classified into name/local drops and root-instrument drops, the survivors
|
|
25734
|
+
* are reparented past any dropped ancestor, and only they are forwarded.
|
|
25735
|
+
*/
|
|
25528
25736
|
export(spans, resultCallback) {
|
|
25529
25737
|
if (isTrialBlocked()) {
|
|
25530
|
-
|
|
25531
|
-
const traceId = getTraceId(span2);
|
|
25532
|
-
if (traceId) addBlockedTraceId(traceId);
|
|
25533
|
-
}
|
|
25738
|
+
this.recordBlockedTraceIds(spans);
|
|
25534
25739
|
resultCallback({ code: core.ExportResultCode.SUCCESS });
|
|
25535
25740
|
return;
|
|
25536
25741
|
}
|
|
25537
|
-
const filtered = [];
|
|
25538
|
-
const batchBlockedMap = /* @__PURE__ */ new Map();
|
|
25539
25742
|
const localBlockedSnapshot = this.localBlockedMap ? new Map(this.localBlockedMap) : void 0;
|
|
25743
|
+
const parentsOfSpansBlockedByName = this.findSpansBlockedByName(spans);
|
|
25744
|
+
const { rootConnectedIds: rootSpansBlocked, parentsOfRootSpansBlocked } = findRootSpansBlocked(spans, parentsOfSpansBlockedByName);
|
|
25745
|
+
const allBlockedSpanIds = /* @__PURE__ */ new Set([
|
|
25746
|
+
...parentsOfSpansBlockedByName.keys(),
|
|
25747
|
+
...rootSpansBlocked
|
|
25748
|
+
]);
|
|
25749
|
+
const survivingSpans = this.collectSurvivors(spans, allBlockedSpanIds);
|
|
25750
|
+
const reparentMap = this.buildReparentMap(
|
|
25751
|
+
parentsOfRootSpansBlocked,
|
|
25752
|
+
parentsOfSpansBlockedByName,
|
|
25753
|
+
localBlockedSnapshot
|
|
25754
|
+
);
|
|
25755
|
+
if (reparentMap.size > 0) {
|
|
25756
|
+
this.reparentSpans(survivingSpans, reparentMap);
|
|
25757
|
+
}
|
|
25758
|
+
this.evictRememberedIfNeeded();
|
|
25759
|
+
if (survivingSpans.length === 0) {
|
|
25760
|
+
resultCallback({ code: core.ExportResultCode.SUCCESS });
|
|
25761
|
+
return;
|
|
25762
|
+
}
|
|
25763
|
+
this.exporter.export(survivingSpans, resultCallback);
|
|
25764
|
+
}
|
|
25765
|
+
shutdown() {
|
|
25766
|
+
this.rememberedBlockedParentMap.clear();
|
|
25767
|
+
this.localPatternCache.clear();
|
|
25768
|
+
return this.exporter.shutdown();
|
|
25769
|
+
}
|
|
25770
|
+
forceFlush() {
|
|
25771
|
+
return this.exporter.forceFlush?.() ?? Promise.resolve();
|
|
25772
|
+
}
|
|
25773
|
+
/**
|
|
25774
|
+
* Remember the trace ids seen during a block so their later spans are dropped
|
|
25775
|
+
* too, even after the block expires.
|
|
25776
|
+
*/
|
|
25777
|
+
recordBlockedTraceIds(spans) {
|
|
25778
|
+
for (const span2 of spans) {
|
|
25779
|
+
const traceId = getTraceId(span2);
|
|
25780
|
+
if (traceId) addBlockedTraceId(traceId);
|
|
25781
|
+
}
|
|
25782
|
+
}
|
|
25783
|
+
/**
|
|
25784
|
+
* Find the spans dropped unconditionally by a global or local name rule.
|
|
25785
|
+
*
|
|
25786
|
+
* Trace-blocked spans are skipped entirely (dropped without reparenting). Each
|
|
25787
|
+
* dropped span is also recorded in the cross-batch remembered map so a child
|
|
25788
|
+
* arriving in a later batch can still be reparented past it. The returned map
|
|
25789
|
+
* feeds both the root-connected candidate walk — as transparent dropped
|
|
25790
|
+
* ancestors — and the reparent map.
|
|
25791
|
+
*
|
|
25792
|
+
* @returns A `{droppedSpanId -> normalizedParent}` map for the name/locally
|
|
25793
|
+
* blocked spans in this batch.
|
|
25794
|
+
*/
|
|
25795
|
+
findSpansBlockedByName(spans) {
|
|
25796
|
+
const parentMap = /* @__PURE__ */ new Map();
|
|
25540
25797
|
for (const span2 of spans) {
|
|
25541
25798
|
const traceId = getTraceId(span2);
|
|
25542
25799
|
if (traceId && isTraceIdBlocked(traceId)) continue;
|
|
25543
25800
|
const name = span2.name;
|
|
25544
25801
|
const globallyBlocked = matchesAnyPattern(name, this.compiled);
|
|
25545
|
-
|
|
25546
|
-
const locallyBlocked = localPatterns.length > 0 && matchesAnyPattern(name, this.getCompiledLocalPatterns(localPatterns)) || this.hasLocalBlockFlag(span2);
|
|
25547
|
-
if (!globallyBlocked && !locallyBlocked) {
|
|
25548
|
-
filtered.push(span2);
|
|
25549
|
-
continue;
|
|
25550
|
-
}
|
|
25802
|
+
if (!globallyBlocked && !this.isLocallyBlocked(span2, name)) continue;
|
|
25551
25803
|
const spanId = span2.spanContext().spanId;
|
|
25552
|
-
const parentCtx = span2.parentSpanContext;
|
|
25553
|
-
|
|
25804
|
+
const parentCtx = normalizeParent(span2.parentSpanContext);
|
|
25805
|
+
parentMap.set(spanId, parentCtx);
|
|
25554
25806
|
this.rememberedBlockedParentMap.set(spanId, parentCtx);
|
|
25555
25807
|
}
|
|
25556
|
-
|
|
25808
|
+
return parentMap;
|
|
25809
|
+
}
|
|
25810
|
+
/**
|
|
25811
|
+
* Check whether `span` is blocked by its per-span local rules — either its
|
|
25812
|
+
* name matches a local pattern or it carries the local-block flag.
|
|
25813
|
+
*/
|
|
25814
|
+
isLocallyBlocked(span2, name) {
|
|
25815
|
+
const localPatterns = this.readLocalBlockPatterns(span2);
|
|
25816
|
+
if (localPatterns.length > 0 && matchesAnyPattern(name, this.getCompiledLocalPatterns(localPatterns))) {
|
|
25817
|
+
return true;
|
|
25818
|
+
}
|
|
25819
|
+
return this.hasLocalBlockFlag(span2);
|
|
25820
|
+
}
|
|
25821
|
+
/**
|
|
25822
|
+
* Return the spans that survive filtering: not trace-blocked and not in
|
|
25823
|
+
* `allBlockedSpanIds` (name/local drops or the root-instrument policy).
|
|
25824
|
+
*/
|
|
25825
|
+
collectSurvivors(spans, allBlockedSpanIds) {
|
|
25826
|
+
const survivingSpans = [];
|
|
25827
|
+
for (const span2 of spans) {
|
|
25828
|
+
const traceId = getTraceId(span2);
|
|
25829
|
+
if (traceId && isTraceIdBlocked(traceId)) continue;
|
|
25830
|
+
if (allBlockedSpanIds.has(span2.spanContext().spanId)) continue;
|
|
25831
|
+
survivingSpans.push(span2);
|
|
25832
|
+
}
|
|
25833
|
+
return survivingSpans;
|
|
25834
|
+
}
|
|
25835
|
+
/**
|
|
25836
|
+
* Merge the cross-batch remembered map with this batch's dropped-parent maps.
|
|
25837
|
+
*
|
|
25838
|
+
* Ordering matters — later wins on conflict: the remembered map and the
|
|
25839
|
+
* injected local-block snapshot are the base, overlaid by root-blocked
|
|
25840
|
+
* parents, then this batch's name/local blocks, so in-batch drops win.
|
|
25841
|
+
*
|
|
25842
|
+
* @returns The merged `{droppedSpanId -> parent}` map used for reparenting.
|
|
25843
|
+
*/
|
|
25844
|
+
buildReparentMap(parentsOfRootSpansBlocked, parentsOfSpansBlockedByName, localBlockedSnapshot) {
|
|
25845
|
+
const reparentMap = /* @__PURE__ */ new Map();
|
|
25557
25846
|
for (const [k, v] of this.rememberedBlockedParentMap) {
|
|
25558
|
-
|
|
25847
|
+
reparentMap.set(k, v);
|
|
25559
25848
|
}
|
|
25560
25849
|
if (localBlockedSnapshot) {
|
|
25561
25850
|
for (const [k, v] of localBlockedSnapshot) {
|
|
25562
|
-
|
|
25851
|
+
reparentMap.set(k, v);
|
|
25563
25852
|
}
|
|
25564
25853
|
}
|
|
25565
|
-
for (const [k, v] of
|
|
25566
|
-
|
|
25854
|
+
for (const [k, v] of parentsOfRootSpansBlocked) {
|
|
25855
|
+
reparentMap.set(k, v);
|
|
25567
25856
|
}
|
|
25568
|
-
|
|
25569
|
-
|
|
25857
|
+
for (const [k, v] of parentsOfSpansBlockedByName) {
|
|
25858
|
+
reparentMap.set(k, v);
|
|
25570
25859
|
}
|
|
25571
|
-
|
|
25572
|
-
if (filtered.length === 0) {
|
|
25573
|
-
resultCallback({ code: core.ExportResultCode.SUCCESS });
|
|
25574
|
-
return;
|
|
25575
|
-
}
|
|
25576
|
-
this.exporter.export(filtered, resultCallback);
|
|
25577
|
-
}
|
|
25578
|
-
shutdown() {
|
|
25579
|
-
this.rememberedBlockedParentMap.clear();
|
|
25580
|
-
this.localPatternCache.clear();
|
|
25581
|
-
return this.exporter.shutdown();
|
|
25582
|
-
}
|
|
25583
|
-
forceFlush() {
|
|
25584
|
-
return this.exporter.forceFlush?.() ?? Promise.resolve();
|
|
25860
|
+
return reparentMap;
|
|
25585
25861
|
}
|
|
25586
25862
|
getCompiledLocalPatterns(patterns) {
|
|
25587
25863
|
const key = patterns.join("\0");
|
|
@@ -25609,23 +25885,30 @@ var _FilteringSpanExporter = class _FilteringSpanExporter {
|
|
|
25609
25885
|
this.rememberedBlockedParentMap.delete(key);
|
|
25610
25886
|
}
|
|
25611
25887
|
}
|
|
25612
|
-
|
|
25888
|
+
/**
|
|
25889
|
+
* Read the per-span local-block patterns set by `LocalFilteringSpanProcessor`,
|
|
25890
|
+
* or an empty list when none are set.
|
|
25891
|
+
*/
|
|
25892
|
+
readLocalBlockPatterns(span2) {
|
|
25613
25893
|
const value = span2.attributes?.["netra.local_blocked_spans"];
|
|
25614
25894
|
if (Array.isArray(value) && value.every((v) => typeof v === "string")) {
|
|
25615
25895
|
return value.filter((v) => v !== "");
|
|
25616
25896
|
}
|
|
25617
25897
|
return [];
|
|
25618
25898
|
}
|
|
25899
|
+
/** Check whether the processor explicitly flagged `span` as locally blocked. */
|
|
25619
25900
|
hasLocalBlockFlag(span2) {
|
|
25620
25901
|
return span2.attributes?.["netra.local_blocked"] === true;
|
|
25621
25902
|
}
|
|
25622
25903
|
/**
|
|
25623
|
-
*
|
|
25624
|
-
* with a ReparentedSpan pointing to the nearest non-blocked ancestor.
|
|
25904
|
+
* Reparent each span past any dropped ancestor onto its first surviving one.
|
|
25625
25905
|
*
|
|
25626
|
-
*
|
|
25906
|
+
* Walks the chain of dropped parents (following `blockedMap`) until a surviving
|
|
25907
|
+
* parent — or `undefined` (promote to root) — is reached, then wraps the span
|
|
25908
|
+
* in a `ReparentedSpan` pointing there. A cycle guard (visited set) prevents
|
|
25909
|
+
* infinite loops in malformed traces.
|
|
25627
25910
|
*/
|
|
25628
|
-
|
|
25911
|
+
reparentSpans(spans, blockedMap) {
|
|
25629
25912
|
for (let i = 0; i < spans.length; i++) {
|
|
25630
25913
|
const span2 = spans[i];
|
|
25631
25914
|
let parent = span2.parentSpanContext;
|
|
@@ -26226,24 +26509,22 @@ function addCustomSpanProcessors(tracerProvider, config, rootInstrumentNames) {
|
|
|
26226
26509
|
);
|
|
26227
26510
|
provider.addSpanProcessor(rootFilterProcessor);
|
|
26228
26511
|
}
|
|
26512
|
+
if (config.enableScrubbing) {
|
|
26513
|
+
const scrubbingProcessor = new ScrubbingSpanProcessor();
|
|
26514
|
+
provider.addSpanProcessor(scrubbingProcessor);
|
|
26515
|
+
}
|
|
26516
|
+
const serializationProcessor = new SerializationSpanProcessor();
|
|
26517
|
+
provider.addSpanProcessor(serializationProcessor);
|
|
26518
|
+
const spanIOProcessor = new SpanIOProcessor();
|
|
26519
|
+
provider.addSpanProcessor(spanIOProcessor);
|
|
26229
26520
|
const instrumentationProcessor = new InstrumentationSpanProcessor();
|
|
26230
26521
|
provider.addSpanProcessor(instrumentationProcessor);
|
|
26231
26522
|
const sessionProcessor = new SessionSpanProcessor(config.environment);
|
|
26232
26523
|
provider.addSpanProcessor(sessionProcessor);
|
|
26233
|
-
const spanIOProcessor = new SpanIOProcessor();
|
|
26234
|
-
provider.addSpanProcessor(spanIOProcessor);
|
|
26235
26524
|
const llmTraceProcessor = new LlmTraceIdentifierSpanProcessor();
|
|
26236
26525
|
provider.addSpanProcessor(llmTraceProcessor);
|
|
26237
26526
|
const rootSpanProcessor = new RootSpanProcessor();
|
|
26238
26527
|
provider.addSpanProcessor(rootSpanProcessor);
|
|
26239
|
-
if (config.enableScrubbing) {
|
|
26240
|
-
const scrubbingProcessor = new ScrubbingSpanProcessor();
|
|
26241
|
-
provider.addSpanProcessor(scrubbingProcessor);
|
|
26242
|
-
}
|
|
26243
|
-
const sizeLimitProcessor = new AttributeSizeLimitProcessor(
|
|
26244
|
-
Config.SPAN_ATTRIBUTE_MAX_SIZE
|
|
26245
|
-
);
|
|
26246
|
-
provider.addSpanProcessor(sizeLimitProcessor);
|
|
26247
26528
|
Logger.debug("Custom span processors registered successfully");
|
|
26248
26529
|
return provider;
|
|
26249
26530
|
} catch (e) {
|
|
@@ -26914,13 +27195,13 @@ function spanHasOutput(span2) {
|
|
|
26914
27195
|
function addInputAttributes(span2, args, entityType) {
|
|
26915
27196
|
span2.setAttribute(`${Config.LIBRARY_NAME}.entity.type`, entityType);
|
|
26916
27197
|
if (args.length > 0) {
|
|
26917
|
-
span2.setAttribute("input", safeStringify(args
|
|
27198
|
+
span2.setAttribute("input", safeStringify(args));
|
|
26918
27199
|
}
|
|
26919
27200
|
}
|
|
26920
27201
|
function addOutputAttributes(span2, result) {
|
|
26921
27202
|
if (result === void 0 || spanHasOutput(span2)) return;
|
|
26922
27203
|
try {
|
|
26923
|
-
span2.setAttribute("output",
|
|
27204
|
+
span2.setAttribute("output", safeStringify(result));
|
|
26924
27205
|
} catch (e) {
|
|
26925
27206
|
span2.setAttribute("output_error", String(e));
|
|
26926
27207
|
}
|
|
@@ -27398,7 +27679,6 @@ Netra.withBlockedSpansLocal = withBlockedSpansLocal;
|
|
|
27398
27679
|
var index_default = Netra;
|
|
27399
27680
|
|
|
27400
27681
|
exports.Aggregation = Aggregation;
|
|
27401
|
-
exports.AttributeSizeLimitProcessor = AttributeSizeLimitProcessor;
|
|
27402
27682
|
exports.BaseTask = BaseTask;
|
|
27403
27683
|
exports.ChartType = ChartType;
|
|
27404
27684
|
exports.Config = Config;
|
|
@@ -27425,11 +27705,13 @@ exports.RunEntryContext = RunEntryContext;
|
|
|
27425
27705
|
exports.RunStatus = RunStatus;
|
|
27426
27706
|
exports.Scope = Scope;
|
|
27427
27707
|
exports.ScrubbingSpanProcessor = ScrubbingSpanProcessor;
|
|
27708
|
+
exports.SerializationSpanProcessor = SerializationSpanProcessor;
|
|
27428
27709
|
exports.SessionSpanProcessor = SessionSpanProcessor;
|
|
27429
27710
|
exports.Simulation = Simulation;
|
|
27430
27711
|
exports.SpanIOProcessor = SpanIOProcessor;
|
|
27431
27712
|
exports.SpanType = SpanType;
|
|
27432
27713
|
exports.TrialAwareOTLPExporter = TrialAwareOTLPExporter;
|
|
27714
|
+
exports.TruncatingSerializer = TruncatingSerializer;
|
|
27433
27715
|
exports.Usage = Usage;
|
|
27434
27716
|
exports.agent = agent;
|
|
27435
27717
|
exports.default = index_default;
|
|
@@ -27438,6 +27720,7 @@ exports.mistralAIInstrumentor = mistralAIInstrumentor;
|
|
|
27438
27720
|
exports.netraExpressMiddleware = netraExpressMiddleware;
|
|
27439
27721
|
exports.openaiAgentsInstrumentor = openaiAgentsInstrumentor;
|
|
27440
27722
|
exports.runWithExtractedContext = runWithExtractedContext;
|
|
27723
|
+
exports.safeStringify = safeStringify;
|
|
27441
27724
|
exports.span = span;
|
|
27442
27725
|
exports.task = task;
|
|
27443
27726
|
exports.workflow = workflow;
|