@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/dist/index.mjs CHANGED
@@ -1,15 +1,15 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
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: () => 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 init(options = {}) {
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(instrumentations, "@traceloop/instrumentation-openai", "OpenAIInstrumentation");
726
- await tryAddInstrumentation(instrumentations, "@traceloop/instrumentation-anthropic", "AnthropicInstrumentation");
727
- await tryAddInstrumentation(instrumentations, "@traceloop/instrumentation-cohere", "CohereInstrumentation");
728
- await tryAddInstrumentation(instrumentations, "@traceloop/instrumentation-bedrock", "BedrockInstrumentation");
729
- await tryAddInstrumentation(instrumentations, "@traceloop/instrumentation-google-generativeai", "GoogleGenerativeAIInstrumentation");
730
- await tryAddInstrumentation(instrumentations, "@traceloop/instrumentation-azure", "AzureOpenAIInstrumentation");
731
- await tryAddInstrumentation(instrumentations, "@traceloop/instrumentation-vertexai", "VertexAIInstrumentation");
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(new InstrumentationClass({ traceContent: captureContent }));
767
+ instrumentations.push(
768
+ new InstrumentationClass({ traceContent: captureContent })
769
+ );
740
770
  log(` \u2705 Loaded ${pkg}`);
741
771
  } else {
742
- log(` \u26A0\uFE0F ${pkg} loaded but ${className} not found. Available:`, Object.keys(mod));
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(client.chat.completions);
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: () => init2
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 init2(options = {}) {
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
- init2();
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 init3(options = {}) {
1272
+ async function init4(options = {}) {
1196
1273
  const baseUrl3 = options.baseUrl || process.env.FALLOM_BASE_URL || "https://spans.fallom.com";
1197
- await init({
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
- init2({
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: init3,
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
- init3 as init,
1299
+ init4 as init,
1218
1300
  models_exports as models,
1301
+ prompts_exports as prompts,
1219
1302
  trace_exports as trace
1220
1303
  };
@@ -0,0 +1,14 @@
1
+ import {
2
+ clearPromptContext,
3
+ get,
4
+ getAB,
5
+ getPromptContext,
6
+ init
7
+ } from "./chunk-IGJD7GBO.mjs";
8
+ export {
9
+ clearPromptContext,
10
+ get,
11
+ getAB,
12
+ getPromptContext,
13
+ init
14
+ };
@@ -0,0 +1,14 @@
1
+ import {
2
+ clearPromptContext,
3
+ get,
4
+ getAB,
5
+ getPromptContext,
6
+ init
7
+ } from "./chunk-VNUUS74T.mjs";
8
+ export {
9
+ clearPromptContext,
10
+ get,
11
+ getAB,
12
+ getPromptContext,
13
+ init
14
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fallom/trace",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Model A/B testing and tracing for LLM applications. Zero latency, production-ready.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",