@mastra/observability 1.14.0 → 1.14.1-alpha.1
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/CHANGELOG.md +22 -0
- package/dist/index.cjs +45 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +45 -12
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1137,7 +1137,9 @@ function getModelVariants(model) {
|
|
|
1137
1137
|
add(model.replace(/[./]/g, "-"));
|
|
1138
1138
|
const slashIndex = model.indexOf("/");
|
|
1139
1139
|
if (slashIndex !== -1) {
|
|
1140
|
-
|
|
1140
|
+
const withoutVendor = model.substring(slashIndex + 1);
|
|
1141
|
+
add(withoutVendor);
|
|
1142
|
+
add(withoutVendor.replace(/\./g, "-"));
|
|
1141
1143
|
}
|
|
1142
1144
|
return [...variants];
|
|
1143
1145
|
}
|
|
@@ -1428,18 +1430,23 @@ function emitAutoExtractedMetrics(span, metrics) {
|
|
|
1428
1430
|
}
|
|
1429
1431
|
function emitUsageMetrics(attrs, usage, metrics) {
|
|
1430
1432
|
let metricCosts = /* @__PURE__ */ new Map();
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1433
|
+
const providedCostContext = getProvidedCostContext(attrs, usage);
|
|
1434
|
+
if (providedCostContext) {
|
|
1435
|
+
metricCosts = providedCostContext;
|
|
1436
|
+
} else {
|
|
1437
|
+
try {
|
|
1438
|
+
const provider = attrs.provider;
|
|
1439
|
+
const model = attrs.responseModel ?? attrs.model;
|
|
1440
|
+
if (provider && model) {
|
|
1441
|
+
metricCosts = estimateCosts({
|
|
1442
|
+
provider,
|
|
1443
|
+
model,
|
|
1444
|
+
usage
|
|
1445
|
+
});
|
|
1446
|
+
}
|
|
1447
|
+
} catch {
|
|
1448
|
+
metricCosts = /* @__PURE__ */ new Map();
|
|
1440
1449
|
}
|
|
1441
|
-
} catch {
|
|
1442
|
-
metricCosts = /* @__PURE__ */ new Map();
|
|
1443
1450
|
}
|
|
1444
1451
|
const emit = (name, value) => {
|
|
1445
1452
|
const costContext = metricCosts.get(name);
|
|
@@ -1453,6 +1460,32 @@ function emitUsageMetrics(attrs, usage, metrics) {
|
|
|
1453
1460
|
emit(sample.name, sample.value);
|
|
1454
1461
|
}
|
|
1455
1462
|
}
|
|
1463
|
+
function getProvidedCostContext(attrs, usage) {
|
|
1464
|
+
const costContext = attrs.costContext;
|
|
1465
|
+
if (typeof costContext?.estimatedCost !== "number") {
|
|
1466
|
+
return void 0;
|
|
1467
|
+
}
|
|
1468
|
+
const carrierMetric = usage.inputTokens !== void 0 ? TokenMetrics.TOTAL_INPUT : TokenMetrics.TOTAL_OUTPUT;
|
|
1469
|
+
const provider = costContext.provider ?? attrs.provider;
|
|
1470
|
+
const model = costContext.model ?? attrs.responseModel ?? attrs.model;
|
|
1471
|
+
const contexts = /* @__PURE__ */ new Map();
|
|
1472
|
+
for (const sample of getTokenMetricSamples(usage)) {
|
|
1473
|
+
contexts.set(sample.name, {
|
|
1474
|
+
provider,
|
|
1475
|
+
model
|
|
1476
|
+
});
|
|
1477
|
+
}
|
|
1478
|
+
contexts.set(carrierMetric, {
|
|
1479
|
+
...costContext,
|
|
1480
|
+
provider,
|
|
1481
|
+
model,
|
|
1482
|
+
costMetadata: {
|
|
1483
|
+
...costContext.costMetadata,
|
|
1484
|
+
allocation: "query_total"
|
|
1485
|
+
}
|
|
1486
|
+
});
|
|
1487
|
+
return contexts;
|
|
1488
|
+
}
|
|
1456
1489
|
function getDurationMetricName(span) {
|
|
1457
1490
|
switch (span.type) {
|
|
1458
1491
|
case SpanType.AGENT_RUN:
|