@mastra/observability 1.18.3-alpha.0 → 1.18.4-alpha.0
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.cjs +21 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -9
- package/dist/index.js.map +1 -1
- package/dist/instances/base.d.ts +1 -0
- package/dist/instances/base.d.ts.map +1 -1
- package/dist/metrics/auto-extract.d.ts +1 -1
- package/dist/metrics/auto-extract.d.ts.map +1 -1
- package/dist/metrics/types.d.ts +7 -0
- package/dist/metrics/types.d.ts.map +1 -1
- package/dist/model-tracing.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1409,6 +1409,13 @@ const PricingMeter = {
|
|
|
1409
1409
|
OUTPUT_IMAGE_TOKENS: "output_image_tokens",
|
|
1410
1410
|
OUTPUT_REASONING_TOKENS: "output_reasoning_tokens"
|
|
1411
1411
|
};
|
|
1412
|
+
/**
|
|
1413
|
+
* Local copy of `TokenMetrics` from `@mastra/core/observability`. Core added that export after
|
|
1414
|
+
* this package's minimum core version, so re-exporting it would raise the peer floor here and in
|
|
1415
|
+
* every exporter that depends on this package. `types.test.ts` keeps the two copies identical.
|
|
1416
|
+
*
|
|
1417
|
+
* TODO(mastra-v2): replace this with `export { TokenMetrics } from '@mastra/core/observability'`.
|
|
1418
|
+
*/
|
|
1412
1419
|
const TokenMetrics = {
|
|
1413
1420
|
TOTAL_INPUT: "mastra_model_total_input_tokens",
|
|
1414
1421
|
TOTAL_OUTPUT: "mastra_model_total_output_tokens",
|
|
@@ -1721,10 +1728,11 @@ function emitTokenMetrics(span, metrics) {
|
|
|
1721
1728
|
* ancestor span: the metric labels come from the ancestor's context, the
|
|
1722
1729
|
* cost calculation still uses the original model that incurred the tokens.
|
|
1723
1730
|
*/
|
|
1724
|
-
function emitTokenMetricsForUsage(usage, provider, model, metrics) {
|
|
1731
|
+
function emitTokenMetricsForUsage(usage, provider, model, usageIncomplete, metrics) {
|
|
1725
1732
|
emitUsageMetrics({
|
|
1726
1733
|
provider,
|
|
1727
|
-
model
|
|
1734
|
+
model,
|
|
1735
|
+
usageIncomplete
|
|
1728
1736
|
}, usage, metrics);
|
|
1729
1737
|
}
|
|
1730
1738
|
/** Emit all auto-extracted metrics for a live span end. */
|
|
@@ -1758,13 +1766,14 @@ function emitUsageMetrics(attrs, usage, metrics) {
|
|
|
1758
1766
|
} catch {
|
|
1759
1767
|
metricCosts = /* @__PURE__ */ new Map();
|
|
1760
1768
|
}
|
|
1769
|
+
const labels = attrs.usageIncomplete ? { usageIncomplete: "true" } : void 0;
|
|
1761
1770
|
const emit = (name, value) => {
|
|
1762
1771
|
const costContext = metricCosts.get(name);
|
|
1763
1772
|
if (!costContext) {
|
|
1764
|
-
metrics.emit(name, value);
|
|
1773
|
+
metrics.emit(name, value, labels);
|
|
1765
1774
|
return;
|
|
1766
1775
|
}
|
|
1767
|
-
metrics.emit(name, value,
|
|
1776
|
+
metrics.emit(name, value, labels, { costContext });
|
|
1768
1777
|
};
|
|
1769
1778
|
for (const sample of getTokenMetricSamples(usage)) emit(sample.name, sample.value);
|
|
1770
1779
|
}
|
|
@@ -2453,6 +2462,7 @@ var ModelSpanTracker = class {
|
|
|
2453
2462
|
...ctx?.parameters !== void 0 ? { parameters: ctx.parameters } : {},
|
|
2454
2463
|
...ctx?.providerOptions !== void 0 ? { providerOptions: ctx.providerOptions } : {},
|
|
2455
2464
|
...ctx?.availableTools !== void 0 ? { availableTools: ctx.availableTools } : {},
|
|
2465
|
+
...ctx?.tools !== void 0 ? { tools: ctx.tools } : {},
|
|
2456
2466
|
...ctx?.toolChoice !== void 0 ? { toolChoice: ctx.toolChoice } : {},
|
|
2457
2467
|
...ctx?.responseFormat !== void 0 ? { responseFormat: ctx.responseFormat } : {}
|
|
2458
2468
|
},
|
|
@@ -5116,7 +5126,7 @@ var BaseObservabilityInstance = class extends _mastra_core_base.MastraBase {
|
|
|
5116
5126
|
if (processedSpan) {
|
|
5117
5127
|
emitAutoExtractedMetrics(processedSpan, this.getMetricsContext(processedSpan));
|
|
5118
5128
|
const processedAttrs = processedSpan.attributes;
|
|
5119
|
-
if (excludedModelUsage && !processedAttrs?.usage) emitTokenMetricsForUsage(excludedModelUsage.usage, excludedModelUsage.provider, excludedModelUsage.model, this.getMetricsContext(processedSpan));
|
|
5129
|
+
if (excludedModelUsage && !processedAttrs?.usage) emitTokenMetricsForUsage(excludedModelUsage.usage, excludedModelUsage.provider, excludedModelUsage.model, excludedModelUsage.usageIncomplete, this.getMetricsContext(processedSpan));
|
|
5120
5130
|
}
|
|
5121
5131
|
} catch (err) {
|
|
5122
5132
|
this.logger.error("[Observability] Auto-extraction error:", err);
|
|
@@ -5179,7 +5189,8 @@ var BaseObservabilityInstance = class extends _mastra_core_base.MastraBase {
|
|
|
5179
5189
|
ancestor,
|
|
5180
5190
|
usage,
|
|
5181
5191
|
provider: endAttrs?.provider ?? liveAttrs?.provider,
|
|
5182
|
-
model: resolveModelId(endAttrs?.responseModel, endAttrs?.model, liveAttrs?.responseModel, liveAttrs?.model)
|
|
5192
|
+
model: resolveModelId(endAttrs?.responseModel, endAttrs?.model, liveAttrs?.responseModel, liveAttrs?.model),
|
|
5193
|
+
usageIncomplete: endAttrs?.usageIncomplete ?? liveAttrs?.usageIncomplete
|
|
5183
5194
|
};
|
|
5184
5195
|
}
|
|
5185
5196
|
/**
|
|
@@ -5201,7 +5212,8 @@ var BaseObservabilityInstance = class extends _mastra_core_base.MastraBase {
|
|
|
5201
5212
|
return {
|
|
5202
5213
|
usage,
|
|
5203
5214
|
provider: endAttrs?.provider ?? liveAttrs?.provider ?? stashed?.provider,
|
|
5204
|
-
model: resolveModelId(endAttrs?.responseModel, endAttrs?.model, liveAttrs?.responseModel, liveAttrs?.model, stashed?.model)
|
|
5215
|
+
model: resolveModelId(endAttrs?.responseModel, endAttrs?.model, liveAttrs?.responseModel, liveAttrs?.model, stashed?.model),
|
|
5216
|
+
usageIncomplete: endAttrs?.usageIncomplete ?? liveAttrs?.usageIncomplete
|
|
5205
5217
|
};
|
|
5206
5218
|
}
|
|
5207
5219
|
/**
|
|
@@ -5211,11 +5223,11 @@ var BaseObservabilityInstance = class extends _mastra_core_base.MastraBase {
|
|
|
5211
5223
|
* span instead of the hidden agent that incurred them.
|
|
5212
5224
|
*/
|
|
5213
5225
|
applyUsageRollup(target) {
|
|
5214
|
-
const { ancestor, usage, provider, model } = target;
|
|
5226
|
+
const { ancestor, usage, provider, model, usageIncomplete } = target;
|
|
5215
5227
|
const attrs = ancestor.attributes;
|
|
5216
5228
|
attrs.internalUsage = addUsageStats(attrs.internalUsage, usage);
|
|
5217
5229
|
try {
|
|
5218
|
-
emitTokenMetricsForUsage(usage, provider, model, this.getMetricsContext(ancestor));
|
|
5230
|
+
emitTokenMetricsForUsage(usage, provider, model, usageIncomplete, this.getMetricsContext(ancestor));
|
|
5219
5231
|
} catch (err) {
|
|
5220
5232
|
this.logger.error("[Observability] Usage rollup metric emission error:", err);
|
|
5221
5233
|
}
|