decord/source/962_extractRequestAttributes.js

438 lines
18 KiB
JavaScript
Raw Normal View History

2026-07-29 08:29:29 +00:00
// Module ID: 962
// Function ID: 963
// Name: extractRequestAttributes
// Dependencies: [5, 958, 963, 839, 960, 866, 965, 840, 869, 848]
// Exports: instrumentOpenAiClient
// Module 962 (extractRequestAttributes)
2026-08-24 06:08:38 +00:00
import _mod839 from "module_839" /* 839 */;
import _mod958 from "module_958" /* 958 */;
import buildMethodPath from "buildMethodPath" /* 960 */;
import getOperationName from "getOperationName" /* 963 */;
import closure_2 from "asyncGeneratorStep" /* 5 */;
2026-07-29 08:29:29 +00:00
2026-08-24 06:08:38 +00:00
function extractRequestAttributes(first, closure_1_1) {
2026-07-29 08:29:29 +00:00
let obj = { [closure_0(closure_1[1]).GEN_AI_SYSTEM_ATTRIBUTE]: "openai" };
2026-08-24 06:08:38 +00:00
obj[_mod958.GEN_AI_OPERATION_NAME_ATTRIBUTE] = getOperationName.getOperationName(closure_1_1);
obj[_mod839.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] = "auto.ai.openai";
2026-07-29 08:29:29 +00:00
if (first.length > 0) {
2026-08-04 21:03:28 +00:00
if (typeof first[0] === "object") {
2026-07-29 08:29:29 +00:00
if (null !== first[0]) {
first = first[0];
const _Array = Array;
const tmp5 = Array.isArray(first.tools) ? first.tools : [];
const items = [];
let arraySpreadResult = HermesBuiltin.arraySpread(tmp5, 0);
if (first.web_search_options) {
2026-08-04 21:03:28 +00:00
if (typeof first.web_search_options === "object") {
2026-07-29 08:29:29 +00:00
obj = { type: "web_search_options" };
const merged = Object.assign(first.web_search_options);
const items1 = [obj];
let items2 = items1;
}
arraySpreadResult = HermesBuiltin.arraySpread(items2, arraySpreadResult);
let json;
if (items.length > 0) {
const _JSON = JSON;
json = JSON.stringify(items);
}
if (json) {
obj[tmp(958).GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE] = json;
}
const _Object = Object;
const merged1 = Object.assign(obj, tmp(963).extractRequestParameters(first));
const tmpResult = tmp(963);
}
items2 = [];
}
return obj;
}
}
2026-08-24 06:08:38 +00:00
obj[_mod958.GEN_AI_REQUEST_MODEL_ATTRIBUTE] = "unknown";
2026-07-29 08:29:29 +00:00
}
function addRequestAttributes(setAttribute, input) {
if ("input" in input) {
input = input.input;
} else if ("messages" in input) {
input = input.messages;
}
if (input) {
if (0 !== length) {
2026-08-24 06:08:38 +00:00
const truncatedJsonString = buildMethodPath.getTruncatedJsonString(input);
const attr = setAttribute.setAttribute(_mod958.GEN_AI_REQUEST_MESSAGES_ATTRIBUTE, truncatedJsonString);
2026-07-29 08:29:29 +00:00
if (length) {
const attr1 = setAttribute.setAttribute(tmp2(958).GEN_AI_REQUEST_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE, length);
}
2026-08-24 06:08:38 +00:00
const obj = buildMethodPath;
2026-07-29 08:29:29 +00:00
tmp2 = require;
}
}
}
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
export const instrumentOpenAiClient = function instrumentOpenAiClient(arg0, arg1) {
obj = _require(obj[9]);
const client = obj.getClient();
let sendDefaultPii;
if (client != null) {
sendDefaultPii = client.getOptions().sendDefaultPii;
}
const BooleanResult = Boolean(sendDefaultPii);
obj = { recordInputs: BooleanResult, recordOutputs: BooleanResult };
const merged = Object.assign(arg1);
_require = "";
obj = {
get(self) {
let obj = self[arg1];
2026-08-24 06:08:38 +00:00
let methodPath = closure_1_0(closure_1_1[2]).buildMethodPath(str, String(arg1));
2026-08-04 21:03:28 +00:00
if (typeof obj === "function") {
2026-07-29 08:29:29 +00:00
if (tmpResult.shouldInstrument(methodPath)) {
str = obj;
2026-08-24 06:08:38 +00:00
closure_1 = methodPath;
str = self;
closure_3 = closure_1;
str = closure_1_2(() => {
closure_0 = [...arguments];
c3 = 0;
c4 = 0;
2026-07-29 08:29:29 +00:00
const iter = (function*() {
if (c4 === 2) {
c4 = 3;
HermesBuiltin.throwTypeError();
} else if (tmp4 === 3) {
if (arg0 === 1) {
throw arg1;
} else if (arg0 === 2) {
let obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
2026-08-24 06:08:38 +00:00
return { value: "HermesInternal", done: null };
2026-07-29 08:29:29 +00:00
}
} else {
try {
c4 = 2;
if (0 === c3) {
if (arg0 === 1) {
c4 = 3;
throw arg1;
} else if (arg0 === 2) {
c4 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
2026-08-24 06:08:38 +00:00
c2 = tmp5;
let dependencyMap = tmp2;
dependencyMap = undefined;
2026-07-29 08:29:29 +00:00
c2 = undefined;
c3 = undefined;
c4 = undefined;
c3 = 1;
c4 = 1;
2026-08-12 06:57:52 +00:00
return { value: "ct", done: true };
2026-07-29 08:29:29 +00:00
}
} else if (arg0 === 1) {
c4 = 3;
throw arg1;
} else if (arg0 === 2) {
c4 = 3;
let obj1 = { value: null, done: true };
obj1[0] = arg1;
return obj1;
} else {
2026-08-24 06:08:38 +00:00
dependencyMap = v0(closure_0, closure_1_1);
str = dependencyMap[str(undefined, dependencyMap[1]).GEN_AI_REQUEST_MODEL_ATTRIBUTE];
2026-07-29 08:29:29 +00:00
if (!str) {
str = "unknown";
}
2026-08-24 06:08:38 +00:00
obj = str(dependencyMap[2]);
v0 = obj.getOperationName(closure_1_1);
const stream = str[0];
if (stream) {
if (typeof stream === "object") {
2026-07-29 08:29:29 +00:00
c4 = 3;
}
let obj2 = { name: null, op: null, attributes: null };
const _HermesInternal2 = HermesInternal;
2026-08-24 06:08:38 +00:00
obj2[0] = "" + v0 + " " + str + " stream-response";
let obj5 = str(dependencyMap[5]);
obj2[1] = str(dependencyMap[2]).getSpanOperation(closure_1_1);
obj2[2] = dependencyMap;
2026-07-29 08:29:29 +00:00
obj5.startSpanManual(obj2, (() => {
2026-08-24 06:08:38 +00:00
closure_0 = closure_2_2(/* F121523 */ function() { ... });
2026-07-29 08:29:29 +00:00
return () => { ... };
})());
2026-08-24 06:08:38 +00:00
let obj7 = str(dependencyMap[2]);
2026-07-29 08:29:29 +00:00
}
2026-08-24 06:08:38 +00:00
obj1 = str(dependencyMap[5]);
2026-07-29 08:29:29 +00:00
let obj3 = { name: null, op: null, attributes: null };
const _HermesInternal = HermesInternal;
2026-08-24 06:08:38 +00:00
obj3[0] = "" + v0 + " " + str;
obj3 = str(dependencyMap[2]);
obj3[1] = obj3.getSpanOperation(closure_1_1);
obj3[2] = dependencyMap;
2026-07-29 08:29:29 +00:00
obj1.startSpan(obj3, (() => {
2026-08-24 06:08:38 +00:00
closure_0 = closure_2_2(/* F121525 */ function() { ... });
2026-07-29 08:29:29 +00:00
return () => { ... };
})());
}
} catch (tmp40) {
c4 = tmp;
throw tmp40;
}
}
})();
iter.next();
return iter;
});
function instrumentedMethod() {
const self = this;
const apply = str.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
}
}
return instrumentedMethod;
}
2026-08-04 21:03:28 +00:00
if (typeof obj === "function") {
2026-07-29 08:29:29 +00:00
instrumentedMethod = obj.bind(self);
} else {
instrumentedMethod = obj;
if (obj) {
instrumentedMethod = obj;
2026-08-04 21:03:28 +00:00
if (typeof obj === "object") {
2026-07-29 08:29:29 +00:00
str = methodPath;
if (methodPath === undefined) {
str = "";
}
let _Proxy = Proxy;
obj = { get: null };
obj[0] = function get(self) {
let obj = self[arg1];
2026-08-24 06:08:38 +00:00
let methodPath = closure_1_0(closure_1_1[2]).buildMethodPath(str, String(arg1));
2026-08-04 21:03:28 +00:00
if (typeof obj === "function") {
2026-07-29 08:29:29 +00:00
if (tmpResult.shouldInstrument(methodPath)) {
str = obj;
2026-08-24 06:08:38 +00:00
closure_1 = methodPath;
str = self;
closure_3 = closure_1;
str = closure_1_2(() => {
closure_0 = [...arguments];
c3 = 0;
c4 = 0;
2026-07-29 08:29:29 +00:00
const iter = (function*() {
if (c4 === 2) {
c4 = 3;
HermesBuiltin.throwTypeError();
} else if (tmp4 === 3) {
if (arg0 === 1) {
throw arg1;
} else if (arg0 === 2) {
let obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
2026-08-24 06:08:38 +00:00
return { value: "HermesInternal", done: null };
2026-07-29 08:29:29 +00:00
}
} else {
try {
c4 = 2;
if (0 === c3) {
if (arg0 === 1) {
c4 = 3;
throw arg1;
} else if (arg0 === 2) {
c4 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
2026-08-24 06:08:38 +00:00
c2 = tmp5;
let dependencyMap = tmp2;
dependencyMap = undefined;
2026-07-29 08:29:29 +00:00
c2 = undefined;
c3 = undefined;
c4 = undefined;
c3 = 1;
c4 = 1;
2026-08-12 06:57:52 +00:00
return { value: "ct", done: true };
2026-07-29 08:29:29 +00:00
}
} else if (arg0 === 1) {
c4 = 3;
throw arg1;
} else if (arg0 === 2) {
c4 = 3;
let obj1 = { value: null, done: true };
obj1[0] = arg1;
return obj1;
} else {
2026-08-24 06:08:38 +00:00
dependencyMap = v0(closure_0, closure_1_1);
str = dependencyMap[str(undefined, dependencyMap[1]).GEN_AI_REQUEST_MODEL_ATTRIBUTE];
2026-07-29 08:29:29 +00:00
if (!str) {
str = "unknown";
}
2026-08-24 06:08:38 +00:00
obj = str(dependencyMap[2]);
v0 = obj.getOperationName(closure_1_1);
const stream = str[0];
if (stream) {
if (typeof stream === "object") {
2026-07-29 08:29:29 +00:00
c4 = 3;
}
let obj2 = { name: null, op: null, attributes: null };
const _HermesInternal2 = HermesInternal;
2026-08-24 06:08:38 +00:00
obj2[0] = "" + v0 + " " + str + " stream-response";
let obj5 = str(dependencyMap[5]);
obj2[1] = str(dependencyMap[2]).getSpanOperation(closure_1_1);
obj2[2] = dependencyMap;
2026-07-29 08:29:29 +00:00
obj5.startSpanManual(obj2, (() => { ... })());
2026-08-24 06:08:38 +00:00
let obj7 = str(dependencyMap[2]);
2026-07-29 08:29:29 +00:00
}
2026-08-24 06:08:38 +00:00
obj1 = str(dependencyMap[5]);
2026-07-29 08:29:29 +00:00
let obj3 = { name: null, op: null, attributes: null };
const _HermesInternal = HermesInternal;
2026-08-24 06:08:38 +00:00
obj3[0] = "" + v0 + " " + str;
obj3 = str(dependencyMap[2]);
obj3[1] = obj3.getSpanOperation(closure_1_1);
obj3[2] = dependencyMap;
2026-07-29 08:29:29 +00:00
obj1.startSpan(obj3, (() => { ... })());
}
} catch (tmp40) {
c4 = tmp;
throw tmp40;
}
}
})();
iter.next();
return iter;
});
function instrumentedMethod() {
const self = this;
const apply = str.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
}
}
return instrumentedMethod;
}
2026-08-04 21:03:28 +00:00
if (typeof obj === "function") {
2026-07-29 08:29:29 +00:00
instrumentedMethod = obj.bind(self);
} else {
instrumentedMethod = obj;
if (obj) {
instrumentedMethod = obj;
2026-08-04 21:03:28 +00:00
if (typeof obj === "object") {
2026-07-29 08:29:29 +00:00
str = methodPath;
if (methodPath === undefined) {
str = "";
}
let _Proxy = Proxy;
obj = { get: null };
obj[0] = function get(self) {
let obj = self[arg1];
2026-08-24 06:08:38 +00:00
let methodPath = closure_1_0(closure_1_1[2]).buildMethodPath(str, String(arg1));
2026-08-04 21:03:28 +00:00
if (typeof obj === "function") {
2026-07-29 08:29:29 +00:00
if (tmpResult.shouldInstrument(methodPath)) {
str = obj;
2026-08-24 06:08:38 +00:00
closure_1 = methodPath;
str = self;
closure_3 = closure_1;
str = closure_1_2(() => {
closure_0 = [...arguments];
c3 = 0;
c4 = 0;
const iter = (/* F116346 */ function*() { ... })();
2026-07-29 08:29:29 +00:00
iter.next();
return iter;
});
function instrumentedMethod() {
const self = this;
const apply = str.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
}
}
return instrumentedMethod;
}
2026-08-04 21:03:28 +00:00
if (typeof obj === "function") {
2026-07-29 08:29:29 +00:00
instrumentedMethod = obj.bind(self);
} else {
instrumentedMethod = obj;
if (obj) {
instrumentedMethod = obj;
2026-08-04 21:03:28 +00:00
if (typeof obj === "object") {
2026-07-29 08:29:29 +00:00
str = methodPath;
if (methodPath === undefined) {
str = "";
}
let _Proxy = Proxy;
obj = { get: null };
obj[0] = function get(self) {
let obj = self[arg1];
2026-08-24 06:08:38 +00:00
let methodPath = closure_1_0(closure_1_1[2]).buildMethodPath(str, String(arg1));
2026-08-04 21:03:28 +00:00
if (typeof obj === "function") {
2026-07-29 08:29:29 +00:00
if (tmpResult.shouldInstrument(methodPath)) {
str = obj;
2026-08-24 06:08:38 +00:00
closure_1 = methodPath;
str = self;
closure_3 = closure_1;
str = closure_1_2(() => { ... });
2026-07-29 08:29:29 +00:00
function instrumentedMethod() { ... }
}
return instrumentedMethod;
}
2026-08-04 21:03:28 +00:00
if (typeof obj === "function") {
2026-07-29 08:29:29 +00:00
instrumentedMethod = obj.bind(self);
} else {
instrumentedMethod = obj;
if (obj) {
instrumentedMethod = obj;
2026-08-04 21:03:28 +00:00
if (typeof obj === "object") {
2026-07-29 08:29:29 +00:00
str = methodPath;
if (methodPath === undefined) {
str = "";
}
let _Proxy = Proxy;
obj = { get: null };
obj[0] = function get() { ... };
instrumentedMethod = new Proxy(obj, obj);
2026-08-24 06:08:38 +00:00
let tmp10 = closure_1;
2026-07-29 08:29:29 +00:00
}
}
}
};
instrumentedMethod = new Proxy(obj, obj);
2026-08-24 06:08:38 +00:00
let tmp10 = closure_1;
2026-07-29 08:29:29 +00:00
}
}
}
};
instrumentedMethod = new Proxy(obj, obj);
2026-08-24 06:08:38 +00:00
let tmp10 = closure_1;
2026-07-29 08:29:29 +00:00
}
}
}
};
instrumentedMethod = new Proxy(obj, obj);
2026-08-24 06:08:38 +00:00
let tmp10 = closure_1;
2026-07-29 08:29:29 +00:00
}
}
}
}
};
const proxy = new Proxy(arg0, obj);
return proxy;
};