@fallom/trace 0.2.3 → 0.2.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.js CHANGED
@@ -1444,10 +1444,16 @@ function createStreamTextWrapper(aiModule, sessionCtx, debug = false) {
1444
1444
  let firstTokenTime = null;
1445
1445
  const modelId = params?.model?.modelId || String(params?.model || "unknown");
1446
1446
  if (result?.usage) {
1447
- result.usage.then(async (rawUsage) => {
1447
+ Promise.all([
1448
+ result.usage.catch(() => null),
1449
+ result.text?.catch(() => null),
1450
+ result.finishReason?.catch(() => null)
1451
+ ]).then(async ([rawUsage, responseText, finishReason]) => {
1448
1452
  const endTime = Date.now();
1449
1453
  if (debug || isDebugMode()) {
1450
1454
  console.log("\n\u{1F50D} [Fallom Debug] streamText raw usage:", JSON.stringify(rawUsage, null, 2));
1455
+ console.log("\u{1F50D} [Fallom Debug] streamText response text:", responseText?.slice(0, 100));
1456
+ console.log("\u{1F50D} [Fallom Debug] streamText finish reason:", finishReason);
1451
1457
  }
1452
1458
  let providerMetadata = result?.experimental_providerMetadata;
1453
1459
  if (providerMetadata && typeof providerMetadata.then === "function") {
@@ -1469,6 +1475,12 @@ function createStreamTextWrapper(aiModule, sessionCtx, debug = false) {
1469
1475
  system: params?.system,
1470
1476
  model: modelId
1471
1477
  });
1478
+ if (responseText || finishReason) {
1479
+ attributes["fallom.raw.response"] = JSON.stringify({
1480
+ text: responseText,
1481
+ finishReason
1482
+ });
1483
+ }
1472
1484
  }
1473
1485
  if (rawUsage) {
1474
1486
  attributes["fallom.raw.usage"] = JSON.stringify(rawUsage);
@@ -1665,10 +1677,16 @@ function createStreamObjectWrapper(aiModule, sessionCtx, debug = false) {
1665
1677
  const parentSpanId = traceCtx?.parentSpanId;
1666
1678
  const modelId = params?.model?.modelId || String(params?.model || "unknown");
1667
1679
  if (result?.usage) {
1668
- result.usage.then(async (rawUsage) => {
1680
+ Promise.all([
1681
+ result.usage.catch(() => null),
1682
+ result.object?.catch(() => null),
1683
+ result.finishReason?.catch(() => null)
1684
+ ]).then(async ([rawUsage, responseObject, finishReason]) => {
1669
1685
  const endTime = Date.now();
1670
1686
  if (debug || isDebugMode()) {
1671
1687
  console.log("\n\u{1F50D} [Fallom Debug] streamObject raw usage:", JSON.stringify(rawUsage, null, 2));
1688
+ console.log("\u{1F50D} [Fallom Debug] streamObject response object:", JSON.stringify(responseObject)?.slice(0, 100));
1689
+ console.log("\u{1F50D} [Fallom Debug] streamObject finish reason:", finishReason);
1672
1690
  }
1673
1691
  let providerMetadata = result?.experimental_providerMetadata;
1674
1692
  if (providerMetadata && typeof providerMetadata.then === "function") {
@@ -1691,6 +1709,12 @@ function createStreamObjectWrapper(aiModule, sessionCtx, debug = false) {
1691
1709
  model: modelId,
1692
1710
  schema: params?.schema ? "provided" : void 0
1693
1711
  });
1712
+ if (responseObject || finishReason) {
1713
+ attributes["fallom.raw.response"] = JSON.stringify({
1714
+ object: responseObject,
1715
+ finishReason
1716
+ });
1717
+ }
1694
1718
  }
1695
1719
  if (rawUsage) {
1696
1720
  attributes["fallom.raw.usage"] = JSON.stringify(rawUsage);
package/dist/index.mjs CHANGED
@@ -1166,10 +1166,16 @@ function createStreamTextWrapper(aiModule, sessionCtx, debug = false) {
1166
1166
  let firstTokenTime = null;
1167
1167
  const modelId = params?.model?.modelId || String(params?.model || "unknown");
1168
1168
  if (result?.usage) {
1169
- result.usage.then(async (rawUsage) => {
1169
+ Promise.all([
1170
+ result.usage.catch(() => null),
1171
+ result.text?.catch(() => null),
1172
+ result.finishReason?.catch(() => null)
1173
+ ]).then(async ([rawUsage, responseText, finishReason]) => {
1170
1174
  const endTime = Date.now();
1171
1175
  if (debug || isDebugMode()) {
1172
1176
  console.log("\n\u{1F50D} [Fallom Debug] streamText raw usage:", JSON.stringify(rawUsage, null, 2));
1177
+ console.log("\u{1F50D} [Fallom Debug] streamText response text:", responseText?.slice(0, 100));
1178
+ console.log("\u{1F50D} [Fallom Debug] streamText finish reason:", finishReason);
1173
1179
  }
1174
1180
  let providerMetadata = result?.experimental_providerMetadata;
1175
1181
  if (providerMetadata && typeof providerMetadata.then === "function") {
@@ -1191,6 +1197,12 @@ function createStreamTextWrapper(aiModule, sessionCtx, debug = false) {
1191
1197
  system: params?.system,
1192
1198
  model: modelId
1193
1199
  });
1200
+ if (responseText || finishReason) {
1201
+ attributes["fallom.raw.response"] = JSON.stringify({
1202
+ text: responseText,
1203
+ finishReason
1204
+ });
1205
+ }
1194
1206
  }
1195
1207
  if (rawUsage) {
1196
1208
  attributes["fallom.raw.usage"] = JSON.stringify(rawUsage);
@@ -1387,10 +1399,16 @@ function createStreamObjectWrapper(aiModule, sessionCtx, debug = false) {
1387
1399
  const parentSpanId = traceCtx?.parentSpanId;
1388
1400
  const modelId = params?.model?.modelId || String(params?.model || "unknown");
1389
1401
  if (result?.usage) {
1390
- result.usage.then(async (rawUsage) => {
1402
+ Promise.all([
1403
+ result.usage.catch(() => null),
1404
+ result.object?.catch(() => null),
1405
+ result.finishReason?.catch(() => null)
1406
+ ]).then(async ([rawUsage, responseObject, finishReason]) => {
1391
1407
  const endTime = Date.now();
1392
1408
  if (debug || isDebugMode()) {
1393
1409
  console.log("\n\u{1F50D} [Fallom Debug] streamObject raw usage:", JSON.stringify(rawUsage, null, 2));
1410
+ console.log("\u{1F50D} [Fallom Debug] streamObject response object:", JSON.stringify(responseObject)?.slice(0, 100));
1411
+ console.log("\u{1F50D} [Fallom Debug] streamObject finish reason:", finishReason);
1394
1412
  }
1395
1413
  let providerMetadata = result?.experimental_providerMetadata;
1396
1414
  if (providerMetadata && typeof providerMetadata.then === "function") {
@@ -1413,6 +1431,12 @@ function createStreamObjectWrapper(aiModule, sessionCtx, debug = false) {
1413
1431
  model: modelId,
1414
1432
  schema: params?.schema ? "provided" : void 0
1415
1433
  });
1434
+ if (responseObject || finishReason) {
1435
+ attributes["fallom.raw.response"] = JSON.stringify({
1436
+ object: responseObject,
1437
+ finishReason
1438
+ });
1439
+ }
1416
1440
  }
1417
1441
  if (rawUsage) {
1418
1442
  attributes["fallom.raw.usage"] = JSON.stringify(rawUsage);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fallom/trace",
3
- "version": "0.2.3",
3
+ "version": "0.2.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",