@fallom/trace 0.1.3 → 0.1.4
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/README.md +120 -1
- package/dist/chunk-IGJD7GBO.mjs +248 -0
- package/dist/chunk-VNUUS74T.mjs +242 -0
- package/dist/index.d.mts +132 -10
- package/dist/index.d.ts +132 -10
- package/dist/index.js +447 -116
- package/dist/index.mjs +115 -32
- package/dist/prompts-67DJ33I4.mjs +14 -0
- package/dist/prompts-ODF4KO2E.mjs +14 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
__export,
|
|
3
|
+
init,
|
|
4
|
+
prompts_exports
|
|
5
|
+
} from "./chunk-IGJD7GBO.mjs";
|
|
6
6
|
|
|
7
7
|
// src/trace.ts
|
|
8
8
|
var trace_exports = {};
|
|
9
9
|
__export(trace_exports, {
|
|
10
10
|
clearSession: () => clearSession,
|
|
11
11
|
getSession: () => getSession,
|
|
12
|
-
init: () =>
|
|
12
|
+
init: () => init2,
|
|
13
13
|
runWithSession: () => runWithSession,
|
|
14
14
|
setSession: () => setSession,
|
|
15
15
|
shutdown: () => shutdown,
|
|
@@ -679,7 +679,7 @@ var fallomSpanProcessor = {
|
|
|
679
679
|
return Promise.resolve();
|
|
680
680
|
}
|
|
681
681
|
};
|
|
682
|
-
async function
|
|
682
|
+
async function init2(options = {}) {
|
|
683
683
|
if (initialized) return;
|
|
684
684
|
debugMode = options.debug ?? false;
|
|
685
685
|
log("\u{1F680} Initializing Fallom tracing...");
|
|
@@ -722,13 +722,41 @@ async function init(options = {}) {
|
|
|
722
722
|
}
|
|
723
723
|
async function getInstrumentations() {
|
|
724
724
|
const instrumentations = [];
|
|
725
|
-
await tryAddInstrumentation(
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
await tryAddInstrumentation(
|
|
731
|
-
|
|
725
|
+
await tryAddInstrumentation(
|
|
726
|
+
instrumentations,
|
|
727
|
+
"@traceloop/instrumentation-openai",
|
|
728
|
+
"OpenAIInstrumentation"
|
|
729
|
+
);
|
|
730
|
+
await tryAddInstrumentation(
|
|
731
|
+
instrumentations,
|
|
732
|
+
"@traceloop/instrumentation-anthropic",
|
|
733
|
+
"AnthropicInstrumentation"
|
|
734
|
+
);
|
|
735
|
+
await tryAddInstrumentation(
|
|
736
|
+
instrumentations,
|
|
737
|
+
"@traceloop/instrumentation-cohere",
|
|
738
|
+
"CohereInstrumentation"
|
|
739
|
+
);
|
|
740
|
+
await tryAddInstrumentation(
|
|
741
|
+
instrumentations,
|
|
742
|
+
"@traceloop/instrumentation-bedrock",
|
|
743
|
+
"BedrockInstrumentation"
|
|
744
|
+
);
|
|
745
|
+
await tryAddInstrumentation(
|
|
746
|
+
instrumentations,
|
|
747
|
+
"@traceloop/instrumentation-google-generativeai",
|
|
748
|
+
"GoogleGenerativeAIInstrumentation"
|
|
749
|
+
);
|
|
750
|
+
await tryAddInstrumentation(
|
|
751
|
+
instrumentations,
|
|
752
|
+
"@traceloop/instrumentation-azure",
|
|
753
|
+
"AzureOpenAIInstrumentation"
|
|
754
|
+
);
|
|
755
|
+
await tryAddInstrumentation(
|
|
756
|
+
instrumentations,
|
|
757
|
+
"@traceloop/instrumentation-vertexai",
|
|
758
|
+
"VertexAIInstrumentation"
|
|
759
|
+
);
|
|
732
760
|
return instrumentations;
|
|
733
761
|
}
|
|
734
762
|
async function tryAddInstrumentation(instrumentations, pkg, className) {
|
|
@@ -736,10 +764,15 @@ async function tryAddInstrumentation(instrumentations, pkg, className) {
|
|
|
736
764
|
const mod = await import(pkg);
|
|
737
765
|
const InstrumentationClass = mod[className] || mod.default?.[className];
|
|
738
766
|
if (InstrumentationClass) {
|
|
739
|
-
instrumentations.push(
|
|
767
|
+
instrumentations.push(
|
|
768
|
+
new InstrumentationClass({ traceContent: captureContent })
|
|
769
|
+
);
|
|
740
770
|
log(` \u2705 Loaded ${pkg}`);
|
|
741
771
|
} else {
|
|
742
|
-
log(
|
|
772
|
+
log(
|
|
773
|
+
` \u26A0\uFE0F ${pkg} loaded but ${className} not found. Available:`,
|
|
774
|
+
Object.keys(mod)
|
|
775
|
+
);
|
|
743
776
|
}
|
|
744
777
|
} catch (e) {
|
|
745
778
|
log(` \u274C ${pkg} not installed`);
|
|
@@ -823,12 +856,20 @@ async function sendTrace(trace) {
|
|
|
823
856
|
}
|
|
824
857
|
}
|
|
825
858
|
function wrapOpenAI(client) {
|
|
826
|
-
const originalCreate = client.chat.completions.create.bind(
|
|
859
|
+
const originalCreate = client.chat.completions.create.bind(
|
|
860
|
+
client.chat.completions
|
|
861
|
+
);
|
|
827
862
|
client.chat.completions.create = async function(...args) {
|
|
828
863
|
const ctx = sessionStorage.getStore() || fallbackSession;
|
|
829
864
|
if (!ctx || !initialized) {
|
|
830
865
|
return originalCreate(...args);
|
|
831
866
|
}
|
|
867
|
+
let promptCtx = null;
|
|
868
|
+
try {
|
|
869
|
+
const { getPromptContext } = await import("./prompts-67DJ33I4.mjs");
|
|
870
|
+
promptCtx = getPromptContext();
|
|
871
|
+
} catch {
|
|
872
|
+
}
|
|
832
873
|
const params = args[0] || {};
|
|
833
874
|
const startTime = Date.now();
|
|
834
875
|
try {
|
|
@@ -847,7 +888,11 @@ function wrapOpenAI(client) {
|
|
|
847
888
|
completion_tokens: response?.usage?.completion_tokens,
|
|
848
889
|
total_tokens: response?.usage?.total_tokens,
|
|
849
890
|
input: captureContent ? JSON.stringify(params?.messages) : void 0,
|
|
850
|
-
output: captureContent ? response?.choices?.[0]?.message?.content : void 0
|
|
891
|
+
output: captureContent ? response?.choices?.[0]?.message?.content : void 0,
|
|
892
|
+
prompt_key: promptCtx?.promptKey,
|
|
893
|
+
prompt_version: promptCtx?.promptVersion,
|
|
894
|
+
prompt_ab_test_key: promptCtx?.abTestKey,
|
|
895
|
+
prompt_variant_index: promptCtx?.variantIndex
|
|
851
896
|
}).catch(() => {
|
|
852
897
|
});
|
|
853
898
|
return response;
|
|
@@ -862,7 +907,11 @@ function wrapOpenAI(client) {
|
|
|
862
907
|
end_time: new Date(endTime).toISOString(),
|
|
863
908
|
duration_ms: endTime - startTime,
|
|
864
909
|
status: "ERROR",
|
|
865
|
-
error_message: error?.message
|
|
910
|
+
error_message: error?.message,
|
|
911
|
+
prompt_key: promptCtx?.promptKey,
|
|
912
|
+
prompt_version: promptCtx?.promptVersion,
|
|
913
|
+
prompt_ab_test_key: promptCtx?.abTestKey,
|
|
914
|
+
prompt_variant_index: promptCtx?.variantIndex
|
|
866
915
|
}).catch(() => {
|
|
867
916
|
});
|
|
868
917
|
throw error;
|
|
@@ -877,6 +926,12 @@ function wrapAnthropic(client) {
|
|
|
877
926
|
if (!ctx || !initialized) {
|
|
878
927
|
return originalCreate(...args);
|
|
879
928
|
}
|
|
929
|
+
let promptCtx = null;
|
|
930
|
+
try {
|
|
931
|
+
const { getPromptContext } = await import("./prompts-67DJ33I4.mjs");
|
|
932
|
+
promptCtx = getPromptContext();
|
|
933
|
+
} catch {
|
|
934
|
+
}
|
|
880
935
|
const params = args[0] || {};
|
|
881
936
|
const startTime = Date.now();
|
|
882
937
|
try {
|
|
@@ -895,7 +950,11 @@ function wrapAnthropic(client) {
|
|
|
895
950
|
completion_tokens: response?.usage?.output_tokens,
|
|
896
951
|
total_tokens: (response?.usage?.input_tokens || 0) + (response?.usage?.output_tokens || 0),
|
|
897
952
|
input: captureContent ? JSON.stringify(params?.messages) : void 0,
|
|
898
|
-
output: captureContent ? response?.content?.[0]?.text : void 0
|
|
953
|
+
output: captureContent ? response?.content?.[0]?.text : void 0,
|
|
954
|
+
prompt_key: promptCtx?.promptKey,
|
|
955
|
+
prompt_version: promptCtx?.promptVersion,
|
|
956
|
+
prompt_ab_test_key: promptCtx?.abTestKey,
|
|
957
|
+
prompt_variant_index: promptCtx?.variantIndex
|
|
899
958
|
}).catch(() => {
|
|
900
959
|
});
|
|
901
960
|
return response;
|
|
@@ -910,7 +969,11 @@ function wrapAnthropic(client) {
|
|
|
910
969
|
end_time: new Date(endTime).toISOString(),
|
|
911
970
|
duration_ms: endTime - startTime,
|
|
912
971
|
status: "ERROR",
|
|
913
|
-
error_message: error?.message
|
|
972
|
+
error_message: error?.message,
|
|
973
|
+
prompt_key: promptCtx?.promptKey,
|
|
974
|
+
prompt_version: promptCtx?.promptVersion,
|
|
975
|
+
prompt_ab_test_key: promptCtx?.abTestKey,
|
|
976
|
+
prompt_variant_index: promptCtx?.variantIndex
|
|
914
977
|
}).catch(() => {
|
|
915
978
|
});
|
|
916
979
|
throw error;
|
|
@@ -925,6 +988,12 @@ function wrapGoogleAI(model) {
|
|
|
925
988
|
if (!ctx || !initialized) {
|
|
926
989
|
return originalGenerate(...args);
|
|
927
990
|
}
|
|
991
|
+
let promptCtx = null;
|
|
992
|
+
try {
|
|
993
|
+
const { getPromptContext } = await import("./prompts-67DJ33I4.mjs");
|
|
994
|
+
promptCtx = getPromptContext();
|
|
995
|
+
} catch {
|
|
996
|
+
}
|
|
928
997
|
const startTime = Date.now();
|
|
929
998
|
try {
|
|
930
999
|
const response = await originalGenerate(...args);
|
|
@@ -944,7 +1013,11 @@ function wrapGoogleAI(model) {
|
|
|
944
1013
|
completion_tokens: usage?.candidatesTokenCount,
|
|
945
1014
|
total_tokens: usage?.totalTokenCount,
|
|
946
1015
|
input: captureContent ? JSON.stringify(args[0]) : void 0,
|
|
947
|
-
output: captureContent ? result?.text?.() : void 0
|
|
1016
|
+
output: captureContent ? result?.text?.() : void 0,
|
|
1017
|
+
prompt_key: promptCtx?.promptKey,
|
|
1018
|
+
prompt_version: promptCtx?.promptVersion,
|
|
1019
|
+
prompt_ab_test_key: promptCtx?.abTestKey,
|
|
1020
|
+
prompt_variant_index: promptCtx?.variantIndex
|
|
948
1021
|
}).catch(() => {
|
|
949
1022
|
});
|
|
950
1023
|
return response;
|
|
@@ -959,7 +1032,11 @@ function wrapGoogleAI(model) {
|
|
|
959
1032
|
end_time: new Date(endTime).toISOString(),
|
|
960
1033
|
duration_ms: endTime - startTime,
|
|
961
1034
|
status: "ERROR",
|
|
962
|
-
error_message: error?.message
|
|
1035
|
+
error_message: error?.message,
|
|
1036
|
+
prompt_key: promptCtx?.promptKey,
|
|
1037
|
+
prompt_version: promptCtx?.promptVersion,
|
|
1038
|
+
prompt_ab_test_key: promptCtx?.abTestKey,
|
|
1039
|
+
prompt_variant_index: promptCtx?.variantIndex
|
|
963
1040
|
}).catch(() => {
|
|
964
1041
|
});
|
|
965
1042
|
throw error;
|
|
@@ -972,7 +1049,7 @@ function wrapGoogleAI(model) {
|
|
|
972
1049
|
var models_exports = {};
|
|
973
1050
|
__export(models_exports, {
|
|
974
1051
|
get: () => get,
|
|
975
|
-
init: () =>
|
|
1052
|
+
init: () => init3
|
|
976
1053
|
});
|
|
977
1054
|
import { createHash } from "crypto";
|
|
978
1055
|
var apiKey2 = null;
|
|
@@ -988,7 +1065,7 @@ function log2(msg) {
|
|
|
988
1065
|
console.log(`[Fallom] ${msg}`);
|
|
989
1066
|
}
|
|
990
1067
|
}
|
|
991
|
-
function
|
|
1068
|
+
function init3(options = {}) {
|
|
992
1069
|
apiKey2 = options.apiKey || process.env.FALLOM_API_KEY || null;
|
|
993
1070
|
baseUrl2 = options.baseUrl || process.env.FALLOM_BASE_URL || "https://spans.fallom.com";
|
|
994
1071
|
initialized2 = true;
|
|
@@ -1008,7 +1085,7 @@ function init2(options = {}) {
|
|
|
1008
1085
|
function ensureInit() {
|
|
1009
1086
|
if (!initialized2) {
|
|
1010
1087
|
try {
|
|
1011
|
-
|
|
1088
|
+
init3();
|
|
1012
1089
|
} catch {
|
|
1013
1090
|
}
|
|
1014
1091
|
}
|
|
@@ -1192,15 +1269,19 @@ async function recordSession(configKey, version, sessionId, model) {
|
|
|
1192
1269
|
}
|
|
1193
1270
|
|
|
1194
1271
|
// src/init.ts
|
|
1195
|
-
async function
|
|
1272
|
+
async function init4(options = {}) {
|
|
1196
1273
|
const baseUrl3 = options.baseUrl || process.env.FALLOM_BASE_URL || "https://spans.fallom.com";
|
|
1197
|
-
await
|
|
1274
|
+
await init2({
|
|
1198
1275
|
apiKey: options.apiKey,
|
|
1199
1276
|
baseUrl: baseUrl3,
|
|
1200
1277
|
captureContent: options.captureContent,
|
|
1201
1278
|
debug: options.debug
|
|
1202
1279
|
});
|
|
1203
|
-
|
|
1280
|
+
init3({
|
|
1281
|
+
apiKey: options.apiKey,
|
|
1282
|
+
baseUrl: baseUrl3
|
|
1283
|
+
});
|
|
1284
|
+
init({
|
|
1204
1285
|
apiKey: options.apiKey,
|
|
1205
1286
|
baseUrl: baseUrl3
|
|
1206
1287
|
});
|
|
@@ -1208,13 +1289,15 @@ async function init3(options = {}) {
|
|
|
1208
1289
|
|
|
1209
1290
|
// src/index.ts
|
|
1210
1291
|
var index_default = {
|
|
1211
|
-
init:
|
|
1292
|
+
init: init4,
|
|
1212
1293
|
trace: trace_exports,
|
|
1213
|
-
models: models_exports
|
|
1294
|
+
models: models_exports,
|
|
1295
|
+
prompts: prompts_exports
|
|
1214
1296
|
};
|
|
1215
1297
|
export {
|
|
1216
1298
|
index_default as default,
|
|
1217
|
-
|
|
1299
|
+
init4 as init,
|
|
1218
1300
|
models_exports as models,
|
|
1301
|
+
prompts_exports as prompts,
|
|
1219
1302
|
trace_exports as trace
|
|
1220
1303
|
};
|