@fallom/trace 0.1.4 → 0.1.5
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.d.mts +9 -6
- package/dist/index.d.ts +9 -6
- package/dist/index.js +26 -5
- package/dist/index.mjs +26 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
interface SessionContext {
|
|
8
8
|
configKey: string;
|
|
9
9
|
sessionId: string;
|
|
10
|
+
customerId?: string;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
13
|
* Initialize Fallom tracing. Auto-instruments all LLM calls.
|
|
@@ -42,34 +43,36 @@ declare function init$3(options?: {
|
|
|
42
43
|
* Set the current session context.
|
|
43
44
|
*
|
|
44
45
|
* All subsequent LLM calls in this async context will be
|
|
45
|
-
* automatically tagged with this configKey and
|
|
46
|
+
* automatically tagged with this configKey, sessionId, and customerId.
|
|
46
47
|
*
|
|
47
48
|
* @param configKey - Your config name (e.g., "linkedin-agent")
|
|
48
49
|
* @param sessionId - Your session/conversation ID
|
|
50
|
+
* @param customerId - Optional customer/user identifier for analytics
|
|
49
51
|
*
|
|
50
52
|
* @example
|
|
51
53
|
* ```typescript
|
|
52
|
-
* trace.setSession("linkedin-agent", sessionId);
|
|
53
|
-
* await agent.run(message); // Automatically traced with session
|
|
54
|
+
* trace.setSession("linkedin-agent", sessionId, "user_123");
|
|
55
|
+
* await agent.run(message); // Automatically traced with session + customer
|
|
54
56
|
* ```
|
|
55
57
|
*/
|
|
56
|
-
declare function setSession(configKey: string, sessionId: string): void;
|
|
58
|
+
declare function setSession(configKey: string, sessionId: string, customerId?: string): void;
|
|
57
59
|
/**
|
|
58
60
|
* Run a function with session context.
|
|
59
61
|
* Use this to ensure session context propagates across async boundaries.
|
|
60
62
|
*
|
|
61
63
|
* @param configKey - Your config name
|
|
62
64
|
* @param sessionId - Your session ID
|
|
65
|
+
* @param customerId - Optional customer/user identifier
|
|
63
66
|
* @param fn - Function to run with session context
|
|
64
67
|
*
|
|
65
68
|
* @example
|
|
66
69
|
* ```typescript
|
|
67
|
-
* await trace.runWithSession("my-agent", sessionId, async () => {
|
|
70
|
+
* await trace.runWithSession("my-agent", sessionId, "user_123", async () => {
|
|
68
71
|
* await agent.run(message); // Has session context
|
|
69
72
|
* });
|
|
70
73
|
* ```
|
|
71
74
|
*/
|
|
72
|
-
declare function runWithSession<T>(configKey: string, sessionId: string,
|
|
75
|
+
declare function runWithSession<T>(configKey: string, sessionId: string, customerIdOrFn: string | (() => T), fn?: () => T): T;
|
|
73
76
|
/**
|
|
74
77
|
* Get current session context, if any.
|
|
75
78
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
interface SessionContext {
|
|
8
8
|
configKey: string;
|
|
9
9
|
sessionId: string;
|
|
10
|
+
customerId?: string;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
13
|
* Initialize Fallom tracing. Auto-instruments all LLM calls.
|
|
@@ -42,34 +43,36 @@ declare function init$3(options?: {
|
|
|
42
43
|
* Set the current session context.
|
|
43
44
|
*
|
|
44
45
|
* All subsequent LLM calls in this async context will be
|
|
45
|
-
* automatically tagged with this configKey and
|
|
46
|
+
* automatically tagged with this configKey, sessionId, and customerId.
|
|
46
47
|
*
|
|
47
48
|
* @param configKey - Your config name (e.g., "linkedin-agent")
|
|
48
49
|
* @param sessionId - Your session/conversation ID
|
|
50
|
+
* @param customerId - Optional customer/user identifier for analytics
|
|
49
51
|
*
|
|
50
52
|
* @example
|
|
51
53
|
* ```typescript
|
|
52
|
-
* trace.setSession("linkedin-agent", sessionId);
|
|
53
|
-
* await agent.run(message); // Automatically traced with session
|
|
54
|
+
* trace.setSession("linkedin-agent", sessionId, "user_123");
|
|
55
|
+
* await agent.run(message); // Automatically traced with session + customer
|
|
54
56
|
* ```
|
|
55
57
|
*/
|
|
56
|
-
declare function setSession(configKey: string, sessionId: string): void;
|
|
58
|
+
declare function setSession(configKey: string, sessionId: string, customerId?: string): void;
|
|
57
59
|
/**
|
|
58
60
|
* Run a function with session context.
|
|
59
61
|
* Use this to ensure session context propagates across async boundaries.
|
|
60
62
|
*
|
|
61
63
|
* @param configKey - Your config name
|
|
62
64
|
* @param sessionId - Your session ID
|
|
65
|
+
* @param customerId - Optional customer/user identifier
|
|
63
66
|
* @param fn - Function to run with session context
|
|
64
67
|
*
|
|
65
68
|
* @example
|
|
66
69
|
* ```typescript
|
|
67
|
-
* await trace.runWithSession("my-agent", sessionId, async () => {
|
|
70
|
+
* await trace.runWithSession("my-agent", sessionId, "user_123", async () => {
|
|
68
71
|
* await agent.run(message); // Has session context
|
|
69
72
|
* });
|
|
70
73
|
* ```
|
|
71
74
|
*/
|
|
72
|
-
declare function runWithSession<T>(configKey: string, sessionId: string,
|
|
75
|
+
declare function runWithSession<T>(configKey: string, sessionId: string, customerIdOrFn: string | (() => T), fn?: () => T): T;
|
|
73
76
|
/**
|
|
74
77
|
* Get current session context, if any.
|
|
75
78
|
*/
|
package/dist/index.js
CHANGED
|
@@ -930,7 +930,15 @@ var fallomSpanProcessor = {
|
|
|
930
930
|
if (ctx) {
|
|
931
931
|
span2.setAttribute("fallom.config_key", ctx.configKey);
|
|
932
932
|
span2.setAttribute("fallom.session_id", ctx.sessionId);
|
|
933
|
-
|
|
933
|
+
if (ctx.customerId) {
|
|
934
|
+
span2.setAttribute("fallom.customer_id", ctx.customerId);
|
|
935
|
+
}
|
|
936
|
+
log2(
|
|
937
|
+
" Added session context:",
|
|
938
|
+
ctx.configKey,
|
|
939
|
+
ctx.sessionId,
|
|
940
|
+
ctx.customerId
|
|
941
|
+
);
|
|
934
942
|
} else {
|
|
935
943
|
log2(" No session context available");
|
|
936
944
|
}
|
|
@@ -1044,16 +1052,23 @@ async function tryAddInstrumentation(instrumentations, pkg, className) {
|
|
|
1044
1052
|
log2(` \u274C ${pkg} not installed`);
|
|
1045
1053
|
}
|
|
1046
1054
|
}
|
|
1047
|
-
function setSession(configKey, sessionId) {
|
|
1055
|
+
function setSession(configKey, sessionId, customerId) {
|
|
1048
1056
|
const store = sessionStorage.getStore();
|
|
1049
1057
|
if (store) {
|
|
1050
1058
|
store.configKey = configKey;
|
|
1051
1059
|
store.sessionId = sessionId;
|
|
1060
|
+
store.customerId = customerId;
|
|
1052
1061
|
}
|
|
1053
|
-
fallbackSession = { configKey, sessionId };
|
|
1062
|
+
fallbackSession = { configKey, sessionId, customerId };
|
|
1054
1063
|
}
|
|
1055
|
-
function runWithSession(configKey, sessionId, fn) {
|
|
1056
|
-
|
|
1064
|
+
function runWithSession(configKey, sessionId, customerIdOrFn, fn) {
|
|
1065
|
+
if (typeof customerIdOrFn === "function") {
|
|
1066
|
+
return sessionStorage.run({ configKey, sessionId }, customerIdOrFn);
|
|
1067
|
+
}
|
|
1068
|
+
return sessionStorage.run(
|
|
1069
|
+
{ configKey, sessionId, customerId: customerIdOrFn },
|
|
1070
|
+
fn
|
|
1071
|
+
);
|
|
1057
1072
|
}
|
|
1058
1073
|
function getSession() {
|
|
1059
1074
|
return sessionStorage.getStore() || fallbackSession || void 0;
|
|
@@ -1144,6 +1159,7 @@ function wrapOpenAI(client) {
|
|
|
1144
1159
|
sendTrace({
|
|
1145
1160
|
config_key: ctx.configKey,
|
|
1146
1161
|
session_id: ctx.sessionId,
|
|
1162
|
+
customer_id: ctx.customerId,
|
|
1147
1163
|
name: "chat.completions.create",
|
|
1148
1164
|
model: response?.model || params?.model,
|
|
1149
1165
|
start_time: new Date(startTime).toISOString(),
|
|
@@ -1167,6 +1183,7 @@ function wrapOpenAI(client) {
|
|
|
1167
1183
|
sendTrace({
|
|
1168
1184
|
config_key: ctx.configKey,
|
|
1169
1185
|
session_id: ctx.sessionId,
|
|
1186
|
+
customer_id: ctx.customerId,
|
|
1170
1187
|
name: "chat.completions.create",
|
|
1171
1188
|
model: params?.model,
|
|
1172
1189
|
start_time: new Date(startTime).toISOString(),
|
|
@@ -1206,6 +1223,7 @@ function wrapAnthropic(client) {
|
|
|
1206
1223
|
sendTrace({
|
|
1207
1224
|
config_key: ctx.configKey,
|
|
1208
1225
|
session_id: ctx.sessionId,
|
|
1226
|
+
customer_id: ctx.customerId,
|
|
1209
1227
|
name: "messages.create",
|
|
1210
1228
|
model: response?.model || params?.model,
|
|
1211
1229
|
start_time: new Date(startTime).toISOString(),
|
|
@@ -1229,6 +1247,7 @@ function wrapAnthropic(client) {
|
|
|
1229
1247
|
sendTrace({
|
|
1230
1248
|
config_key: ctx.configKey,
|
|
1231
1249
|
session_id: ctx.sessionId,
|
|
1250
|
+
customer_id: ctx.customerId,
|
|
1232
1251
|
name: "messages.create",
|
|
1233
1252
|
model: params?.model,
|
|
1234
1253
|
start_time: new Date(startTime).toISOString(),
|
|
@@ -1269,6 +1288,7 @@ function wrapGoogleAI(model) {
|
|
|
1269
1288
|
sendTrace({
|
|
1270
1289
|
config_key: ctx.configKey,
|
|
1271
1290
|
session_id: ctx.sessionId,
|
|
1291
|
+
customer_id: ctx.customerId,
|
|
1272
1292
|
name: "generateContent",
|
|
1273
1293
|
model: model?.model || "gemini",
|
|
1274
1294
|
start_time: new Date(startTime).toISOString(),
|
|
@@ -1292,6 +1312,7 @@ function wrapGoogleAI(model) {
|
|
|
1292
1312
|
sendTrace({
|
|
1293
1313
|
config_key: ctx.configKey,
|
|
1294
1314
|
session_id: ctx.sessionId,
|
|
1315
|
+
customer_id: ctx.customerId,
|
|
1295
1316
|
name: "generateContent",
|
|
1296
1317
|
model: model?.model || "gemini",
|
|
1297
1318
|
start_time: new Date(startTime).toISOString(),
|
package/dist/index.mjs
CHANGED
|
@@ -664,7 +664,15 @@ var fallomSpanProcessor = {
|
|
|
664
664
|
if (ctx) {
|
|
665
665
|
span2.setAttribute("fallom.config_key", ctx.configKey);
|
|
666
666
|
span2.setAttribute("fallom.session_id", ctx.sessionId);
|
|
667
|
-
|
|
667
|
+
if (ctx.customerId) {
|
|
668
|
+
span2.setAttribute("fallom.customer_id", ctx.customerId);
|
|
669
|
+
}
|
|
670
|
+
log(
|
|
671
|
+
" Added session context:",
|
|
672
|
+
ctx.configKey,
|
|
673
|
+
ctx.sessionId,
|
|
674
|
+
ctx.customerId
|
|
675
|
+
);
|
|
668
676
|
} else {
|
|
669
677
|
log(" No session context available");
|
|
670
678
|
}
|
|
@@ -778,16 +786,23 @@ async function tryAddInstrumentation(instrumentations, pkg, className) {
|
|
|
778
786
|
log(` \u274C ${pkg} not installed`);
|
|
779
787
|
}
|
|
780
788
|
}
|
|
781
|
-
function setSession(configKey, sessionId) {
|
|
789
|
+
function setSession(configKey, sessionId, customerId) {
|
|
782
790
|
const store = sessionStorage.getStore();
|
|
783
791
|
if (store) {
|
|
784
792
|
store.configKey = configKey;
|
|
785
793
|
store.sessionId = sessionId;
|
|
794
|
+
store.customerId = customerId;
|
|
786
795
|
}
|
|
787
|
-
fallbackSession = { configKey, sessionId };
|
|
796
|
+
fallbackSession = { configKey, sessionId, customerId };
|
|
788
797
|
}
|
|
789
|
-
function runWithSession(configKey, sessionId, fn) {
|
|
790
|
-
|
|
798
|
+
function runWithSession(configKey, sessionId, customerIdOrFn, fn) {
|
|
799
|
+
if (typeof customerIdOrFn === "function") {
|
|
800
|
+
return sessionStorage.run({ configKey, sessionId }, customerIdOrFn);
|
|
801
|
+
}
|
|
802
|
+
return sessionStorage.run(
|
|
803
|
+
{ configKey, sessionId, customerId: customerIdOrFn },
|
|
804
|
+
fn
|
|
805
|
+
);
|
|
791
806
|
}
|
|
792
807
|
function getSession() {
|
|
793
808
|
return sessionStorage.getStore() || fallbackSession || void 0;
|
|
@@ -878,6 +893,7 @@ function wrapOpenAI(client) {
|
|
|
878
893
|
sendTrace({
|
|
879
894
|
config_key: ctx.configKey,
|
|
880
895
|
session_id: ctx.sessionId,
|
|
896
|
+
customer_id: ctx.customerId,
|
|
881
897
|
name: "chat.completions.create",
|
|
882
898
|
model: response?.model || params?.model,
|
|
883
899
|
start_time: new Date(startTime).toISOString(),
|
|
@@ -901,6 +917,7 @@ function wrapOpenAI(client) {
|
|
|
901
917
|
sendTrace({
|
|
902
918
|
config_key: ctx.configKey,
|
|
903
919
|
session_id: ctx.sessionId,
|
|
920
|
+
customer_id: ctx.customerId,
|
|
904
921
|
name: "chat.completions.create",
|
|
905
922
|
model: params?.model,
|
|
906
923
|
start_time: new Date(startTime).toISOString(),
|
|
@@ -940,6 +957,7 @@ function wrapAnthropic(client) {
|
|
|
940
957
|
sendTrace({
|
|
941
958
|
config_key: ctx.configKey,
|
|
942
959
|
session_id: ctx.sessionId,
|
|
960
|
+
customer_id: ctx.customerId,
|
|
943
961
|
name: "messages.create",
|
|
944
962
|
model: response?.model || params?.model,
|
|
945
963
|
start_time: new Date(startTime).toISOString(),
|
|
@@ -963,6 +981,7 @@ function wrapAnthropic(client) {
|
|
|
963
981
|
sendTrace({
|
|
964
982
|
config_key: ctx.configKey,
|
|
965
983
|
session_id: ctx.sessionId,
|
|
984
|
+
customer_id: ctx.customerId,
|
|
966
985
|
name: "messages.create",
|
|
967
986
|
model: params?.model,
|
|
968
987
|
start_time: new Date(startTime).toISOString(),
|
|
@@ -1003,6 +1022,7 @@ function wrapGoogleAI(model) {
|
|
|
1003
1022
|
sendTrace({
|
|
1004
1023
|
config_key: ctx.configKey,
|
|
1005
1024
|
session_id: ctx.sessionId,
|
|
1025
|
+
customer_id: ctx.customerId,
|
|
1006
1026
|
name: "generateContent",
|
|
1007
1027
|
model: model?.model || "gemini",
|
|
1008
1028
|
start_time: new Date(startTime).toISOString(),
|
|
@@ -1026,6 +1046,7 @@ function wrapGoogleAI(model) {
|
|
|
1026
1046
|
sendTrace({
|
|
1027
1047
|
config_key: ctx.configKey,
|
|
1028
1048
|
session_id: ctx.sessionId,
|
|
1049
|
+
customer_id: ctx.customerId,
|
|
1029
1050
|
name: "generateContent",
|
|
1030
1051
|
model: model?.model || "gemini",
|
|
1031
1052
|
start_time: new Date(startTime).toISOString(),
|