@mastra/observability 1.21.1-alpha.0 → 1.21.1-alpha.2
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/exporters/test.d.ts.map +1 -1
- package/dist/index.cjs +144 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +143 -108
- package/dist/index.js.map +1 -1
- package/dist/instances/base.d.ts.map +1 -1
- package/dist/metrics/pricing-data.json +1070 -559
- package/dist/spans/base.d.ts +33 -1
- package/dist/spans/base.d.ts.map +1 -1
- package/dist/usage.d.ts +3 -0
- package/dist/usage.d.ts.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { TransformStream } from "stream/web";
|
|
|
12
12
|
import { coreFeatures } from "@mastra/core/features";
|
|
13
13
|
import { buildCreateSpanRecord, buildFeedbackRecord, buildLogRecord, buildMetricRecord, buildScoreRecord, buildUpdateSpanRecord } from "@mastra/core/storage";
|
|
14
14
|
import { createHash } from "crypto";
|
|
15
|
-
|
|
15
|
+
// src/bus/route-event.ts
|
|
16
16
|
/**
|
|
17
17
|
* Route a single event to the appropriate method on a handler.
|
|
18
18
|
*
|
|
@@ -79,8 +79,7 @@ function catchAsyncResult(result, handlerName, signal, logger) {
|
|
|
79
79
|
logger.error(`[Observability] ${signal} handler error [handler=${handlerName}]:`, err);
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
//#region src/bus/base.ts
|
|
82
|
+
// src/bus/base.ts
|
|
84
83
|
/**
|
|
85
84
|
* BaseObservabilityEventBus - Generic event bus for observability events.
|
|
86
85
|
*
|
|
@@ -155,8 +154,7 @@ var BaseObservabilityEventBus = class BaseObservabilityEventBus extends MastraBa
|
|
|
155
154
|
this.subscribers.clear();
|
|
156
155
|
}
|
|
157
156
|
};
|
|
158
|
-
|
|
159
|
-
//#region src/spans/serialization.ts
|
|
157
|
+
// src/spans/serialization.ts
|
|
160
158
|
/**
|
|
161
159
|
* Bounded serialization utilities for AI tracing.
|
|
162
160
|
*
|
|
@@ -522,8 +520,7 @@ function deepClean(value, options = DEFAULT_DEEP_CLEAN_OPTIONS) {
|
|
|
522
520
|
}
|
|
523
521
|
return helper(value, 0);
|
|
524
522
|
}
|
|
525
|
-
|
|
526
|
-
//#region src/bus/observability-bus.ts
|
|
523
|
+
// src/bus/observability-bus.ts
|
|
527
524
|
/**
|
|
528
525
|
* Apply deepClean() to non-tracing observability events. Tracing events are
|
|
529
526
|
* already deep-cleaned at span construction time (see spans/base.ts and
|
|
@@ -732,8 +729,7 @@ var ObservabilityBus = class extends BaseObservabilityEventBus {
|
|
|
732
729
|
await super.shutdown();
|
|
733
730
|
}
|
|
734
731
|
};
|
|
735
|
-
|
|
736
|
-
//#region src/config.ts
|
|
732
|
+
// src/config.ts
|
|
737
733
|
/**
|
|
738
734
|
* Sampling strategy types
|
|
739
735
|
*/
|
|
@@ -860,8 +856,7 @@ const observabilityRegistryConfigSchema = z.object({
|
|
|
860
856
|
}
|
|
861
857
|
return true;
|
|
862
858
|
}, { message: "A \"configSelector\" requires at least one config or default observability to be configured." });
|
|
863
|
-
|
|
864
|
-
//#region src/ids.ts
|
|
859
|
+
// src/ids.ts
|
|
865
860
|
/**
|
|
866
861
|
* Signal and span id helpers.
|
|
867
862
|
*
|
|
@@ -929,8 +924,7 @@ function resolveExportedSpanId(span) {
|
|
|
929
924
|
if (!span) return void 0;
|
|
930
925
|
return typeof span.getExportedSpanId === "function" ? span.getExportedSpanId() : span.id;
|
|
931
926
|
}
|
|
932
|
-
|
|
933
|
-
//#region src/context/logger.ts
|
|
927
|
+
// src/context/logger.ts
|
|
934
928
|
/** Numeric priority used to compare log levels against the configured minimum. */
|
|
935
929
|
const LOG_LEVEL_PRIORITY = {
|
|
936
930
|
debug: 0,
|
|
@@ -998,8 +992,7 @@ var LoggerContextImpl = class {
|
|
|
998
992
|
this.config.observabilityBus.emit(event);
|
|
999
993
|
}
|
|
1000
994
|
};
|
|
1001
|
-
|
|
1002
|
-
//#region src/context/metrics.ts
|
|
995
|
+
// src/context/metrics.ts
|
|
1003
996
|
/**
|
|
1004
997
|
* User-facing metric emission API. All metrics are routed through
|
|
1005
998
|
* ObservabilityBus.emit() after validation and cardinality filtering.
|
|
@@ -1074,14 +1067,12 @@ function cloneCostContext(costContext) {
|
|
|
1074
1067
|
costMetadata: costContext.costMetadata ? structuredClone(costContext.costMetadata) : void 0
|
|
1075
1068
|
};
|
|
1076
1069
|
}
|
|
1077
|
-
|
|
1078
|
-
//#region src/model-id.ts
|
|
1070
|
+
// src/model-id.ts
|
|
1079
1071
|
/** Return the first model id that contains non-whitespace characters. */
|
|
1080
1072
|
function resolveModelId(...candidates) {
|
|
1081
1073
|
return candidates.find((candidate) => candidate?.trim());
|
|
1082
1074
|
}
|
|
1083
|
-
|
|
1084
|
-
//#region src/metrics/pricing-model.ts
|
|
1075
|
+
// src/metrics/pricing-model.ts
|
|
1085
1076
|
var PricingTier = class {
|
|
1086
1077
|
index;
|
|
1087
1078
|
when;
|
|
@@ -1139,8 +1130,7 @@ var PricingModel = class {
|
|
|
1139
1130
|
return this.tiers[0] ?? null;
|
|
1140
1131
|
}
|
|
1141
1132
|
};
|
|
1142
|
-
|
|
1143
|
-
//#region src/metrics/models-dev.ts
|
|
1133
|
+
// src/metrics/models-dev.ts
|
|
1144
1134
|
/** Same catalog the model router reads in `@mastra/core` (`gateways/models-dev.ts`). */
|
|
1145
1135
|
const MODELS_DEV_API_URL = "https://models.dev/api.json";
|
|
1146
1136
|
/**
|
|
@@ -1271,8 +1261,7 @@ function sortedEntries(value) {
|
|
|
1271
1261
|
function isRecord(value) {
|
|
1272
1262
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1273
1263
|
}
|
|
1274
|
-
|
|
1275
|
-
//#region src/metrics/pricing-registry.ts
|
|
1264
|
+
// src/metrics/pricing-registry.ts
|
|
1276
1265
|
const DATA_FILE_NAME = "pricing-data.json";
|
|
1277
1266
|
const REFRESH_INTERVAL_MS = 864e5;
|
|
1278
1267
|
const MIN_REFRESH_ATTEMPT_INTERVAL_MS = 36e5;
|
|
@@ -1623,8 +1612,7 @@ function stripDateSuffix(model) {
|
|
|
1623
1612
|
stripped = model.replace(/-\d{2}-20\d{2}$/, "");
|
|
1624
1613
|
return stripped;
|
|
1625
1614
|
}
|
|
1626
|
-
|
|
1627
|
-
//#region src/metrics/types.ts
|
|
1615
|
+
// src/metrics/types.ts
|
|
1628
1616
|
const PricingMeter = {
|
|
1629
1617
|
INPUT_TOKENS: "input_tokens",
|
|
1630
1618
|
INPUT_AUDIO_TOKENS: "input_audio_tokens",
|
|
@@ -1660,8 +1648,7 @@ const TokenMetrics = {
|
|
|
1660
1648
|
OUTPUT_AUDIO: "mastra_model_output_audio_tokens",
|
|
1661
1649
|
OUTPUT_IMAGE: "mastra_model_output_image_tokens"
|
|
1662
1650
|
};
|
|
1663
|
-
|
|
1664
|
-
//#region src/metrics/usage-metrics.ts
|
|
1651
|
+
// src/metrics/usage-metrics.ts
|
|
1665
1652
|
function getTokenMetricSamples(usage) {
|
|
1666
1653
|
const samples = [];
|
|
1667
1654
|
const pushIfDefined = (name, value) => {
|
|
@@ -1695,8 +1682,7 @@ function getTokenMetricSamples(usage) {
|
|
|
1695
1682
|
}
|
|
1696
1683
|
return samples;
|
|
1697
1684
|
}
|
|
1698
|
-
|
|
1699
|
-
//#region src/metrics/estimator.ts
|
|
1685
|
+
// src/metrics/estimator.ts
|
|
1700
1686
|
function estimateCosts(args, pricingRegistry = PricingRegistry.getGlobal()) {
|
|
1701
1687
|
const { provider, model, usage } = args;
|
|
1702
1688
|
const results = /* @__PURE__ */ new Map();
|
|
@@ -1928,8 +1914,7 @@ function estimateCostForMeter(args) {
|
|
|
1928
1914
|
}
|
|
1929
1915
|
};
|
|
1930
1916
|
}
|
|
1931
|
-
|
|
1932
|
-
//#region src/metrics/auto-extract.ts
|
|
1917
|
+
// src/metrics/auto-extract.ts
|
|
1933
1918
|
/**
|
|
1934
1919
|
* Emits metrics derived from live spans.
|
|
1935
1920
|
*/
|
|
@@ -2083,8 +2068,7 @@ function getDurationMetricName(span) {
|
|
|
2083
2068
|
default: return null;
|
|
2084
2069
|
}
|
|
2085
2070
|
}
|
|
2086
|
-
|
|
2087
|
-
//#region src/metrics/cardinality.ts
|
|
2071
|
+
// src/metrics/cardinality.ts
|
|
2088
2072
|
/** Matches standard UUID v4 strings (case-insensitive). */
|
|
2089
2073
|
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
2090
2074
|
var CardinalityFilter = class {
|
|
@@ -2115,8 +2099,7 @@ var CardinalityFilter = class {
|
|
|
2115
2099
|
return filtered;
|
|
2116
2100
|
}
|
|
2117
2101
|
};
|
|
2118
|
-
|
|
2119
|
-
//#region src/usage.ts
|
|
2102
|
+
// src/usage.ts
|
|
2120
2103
|
/**
|
|
2121
2104
|
* For non-BYOK requests, `usage.cost` is the complete OpenRouter charge and
|
|
2122
2105
|
* `usage.costDetails.upstreamInferenceCost` is only its upstream breakdown. For BYOK requests,
|
|
@@ -2193,6 +2176,9 @@ function isDefined(value) {
|
|
|
2193
2176
|
* - Google/Gemini: cachedContentTokenCount, thoughtsTokenCount in providerMetadata.google.usageMetadata
|
|
2194
2177
|
* - OpenRouter: Uses OpenAI-compatible structure (cache tokens in usage)
|
|
2195
2178
|
*
|
|
2179
|
+
* Kept in sync with `packages/core/src/observability/usage.ts` (duplicated so exporters do not need a newer core).
|
|
2180
|
+
* Change both copies together; `usage.parity.test.ts` fails if they drift.
|
|
2181
|
+
*
|
|
2196
2182
|
* @param usage - The LanguageModelV2Usage from AI SDK response
|
|
2197
2183
|
* @param providerMetadata - Optional provider-specific metadata
|
|
2198
2184
|
* @returns UsageStats with inputDetails and outputDetails
|
|
@@ -2298,8 +2284,7 @@ function addUsageStats(a, b) {
|
|
|
2298
2284
|
outputDetails: mergeOutputDetails(a.outputDetails, b.outputDetails)
|
|
2299
2285
|
};
|
|
2300
2286
|
}
|
|
2301
|
-
|
|
2302
|
-
//#region src/model-tracing.ts
|
|
2287
|
+
// src/model-tracing.ts
|
|
2303
2288
|
/**
|
|
2304
2289
|
* Model Span Tracing
|
|
2305
2290
|
*
|
|
@@ -3099,8 +3084,7 @@ var ModelSpanTracker = class {
|
|
|
3099
3084
|
} }));
|
|
3100
3085
|
}
|
|
3101
3086
|
};
|
|
3102
|
-
|
|
3103
|
-
//#region src/spans/metadata.ts
|
|
3087
|
+
// src/spans/metadata.ts
|
|
3104
3088
|
/**
|
|
3105
3089
|
* Shared span-metadata helpers.
|
|
3106
3090
|
*
|
|
@@ -3167,8 +3151,29 @@ function mergeMetadata$1(parentMetadata, metadata) {
|
|
|
3167
3151
|
return metadata;
|
|
3168
3152
|
}
|
|
3169
3153
|
}
|
|
3170
|
-
|
|
3171
|
-
|
|
3154
|
+
// src/spans/base.ts
|
|
3155
|
+
const LINEAGE_KEYS = [
|
|
3156
|
+
"parentEntityType",
|
|
3157
|
+
"parentEntityId",
|
|
3158
|
+
"parentEntityName",
|
|
3159
|
+
"parentEntityVersionId",
|
|
3160
|
+
"rootEntityType",
|
|
3161
|
+
"rootEntityId",
|
|
3162
|
+
"rootEntityName",
|
|
3163
|
+
"rootEntityVersionId"
|
|
3164
|
+
];
|
|
3165
|
+
function ownEntityVersionId(span) {
|
|
3166
|
+
return span instanceof BaseSpan ? span.ownEntityVersionId : void 0;
|
|
3167
|
+
}
|
|
3168
|
+
/** Copy only the lineage fields that have values, so spans don't carry undefined keys */
|
|
3169
|
+
function definedLineage(source) {
|
|
3170
|
+
const lineage = {};
|
|
3171
|
+
for (const key of LINEAGE_KEYS) {
|
|
3172
|
+
const value = source[key];
|
|
3173
|
+
if (value !== void 0 && value !== null) lineage[key] = value;
|
|
3174
|
+
}
|
|
3175
|
+
return lineage;
|
|
3176
|
+
}
|
|
3172
3177
|
/**
|
|
3173
3178
|
* Determines if a span type should be considered internal based on flags.
|
|
3174
3179
|
* Returns false if flags are undefined.
|
|
@@ -3290,6 +3295,17 @@ var BaseSpan = class BaseSpan {
|
|
|
3290
3295
|
isExcluded;
|
|
3291
3296
|
/** Cached canonical correlation context for this live span */
|
|
3292
3297
|
correlationContext;
|
|
3298
|
+
/**
|
|
3299
|
+
* Parent and root entity restored by `rebuildSpan()`. A rebuilt span has no
|
|
3300
|
+
* live `parent`, so its original ancestors are only known from the cached export.
|
|
3301
|
+
*/
|
|
3302
|
+
restoredLineage;
|
|
3303
|
+
/**
|
|
3304
|
+
* Version declared for this span's own entity, or inherited from a parent span
|
|
3305
|
+
* of the same entity. Unlike `metadata.entityVersionId`, never an ancestor's
|
|
3306
|
+
* version for a different entity.
|
|
3307
|
+
*/
|
|
3308
|
+
ownEntityVersionId;
|
|
3293
3309
|
/** Child spans that have started but not yet ended */
|
|
3294
3310
|
#openChildren;
|
|
3295
3311
|
/** The span whose open-child set currently tracks this span: the parent, or a live ancestor after promotion */
|
|
@@ -3327,6 +3343,9 @@ var BaseSpan = class BaseSpan {
|
|
|
3327
3343
|
this.entityType = options.entityType ?? entityParent?.entityType;
|
|
3328
3344
|
this.entityId = options.entityId ?? entityParent?.entityId;
|
|
3329
3345
|
this.entityName = options.entityName ?? entityParent?.entityName;
|
|
3346
|
+
const declaredVersion = options.metadata?.entityVersionId;
|
|
3347
|
+
const sameEntityParent = entityParent instanceof BaseSpan && entityParent.entityType === this.entityType && entityParent.entityId === this.entityId;
|
|
3348
|
+
this.ownEntityVersionId = typeof declaredVersion === "string" ? declaredVersion : sameEntityParent ? entityParent.ownEntityVersionId : void 0;
|
|
3330
3349
|
if (this.isExcluded) {
|
|
3331
3350
|
this.attributes = {};
|
|
3332
3351
|
return;
|
|
@@ -3475,18 +3494,62 @@ var BaseSpan = class BaseSpan {
|
|
|
3475
3494
|
current = current.parent;
|
|
3476
3495
|
}
|
|
3477
3496
|
}
|
|
3478
|
-
/**
|
|
3497
|
+
/**
|
|
3498
|
+
* Restore the parent and root entity a span had before it was exported and
|
|
3499
|
+
* rebuilt (durable execution), so it and its new children keep their lineage.
|
|
3500
|
+
*/
|
|
3501
|
+
restoreEntityLineage(cached) {
|
|
3502
|
+
this.ownEntityVersionId = cached.ownEntityVersionId ?? void 0;
|
|
3503
|
+
const lineage = definedLineage(cached);
|
|
3504
|
+
if (Object.keys(lineage).length > 0) {
|
|
3505
|
+
this.restoredLineage = lineage;
|
|
3506
|
+
this.correlationContext = void 0;
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
3509
|
+
/**
|
|
3510
|
+
* Build and cache the canonical correlation context for this live span.
|
|
3511
|
+
*
|
|
3512
|
+
* Parent entity: the nearest ancestor that is not internal or excluded, the
|
|
3513
|
+
* same rule used for entity inheritance. Root entity: the top of the
|
|
3514
|
+
* in-process parent chain, which is not necessarily the distributed trace's
|
|
3515
|
+
* root when the trace continues from another service. The root walk does not
|
|
3516
|
+
* skip internal spans, so the root can name an entity whose span is not
|
|
3517
|
+
* exported. Logs, metrics, scores and feedback share these values.
|
|
3518
|
+
*
|
|
3519
|
+
* When the top of the live chain was rebuilt, its original ancestors only
|
|
3520
|
+
* survive in the restored lineage, so it supplies the root and, when no live
|
|
3521
|
+
* ancestor qualifies, the parent.
|
|
3522
|
+
*/
|
|
3479
3523
|
getCorrelationContext() {
|
|
3480
3524
|
if (this.correlationContext) return this.correlationContext;
|
|
3481
3525
|
const metadata = this.metadata ?? {};
|
|
3482
3526
|
const getMetadataString = (key) => typeof metadata[key] === "string" ? metadata[key] : void 0;
|
|
3483
|
-
const getSpanMetadataString = (span, key) => {
|
|
3484
|
-
const m = span?.metadata;
|
|
3485
|
-
return m && typeof m[key] === "string" ? m[key] : void 0;
|
|
3486
|
-
};
|
|
3487
3527
|
const parentSpan = this.getParentSpan(false);
|
|
3488
3528
|
let rootSpan = this;
|
|
3489
3529
|
while (rootSpan.parent) rootSpan = rootSpan.parent;
|
|
3530
|
+
const restored = rootSpan instanceof BaseSpan ? rootSpan.restoredLineage : void 0;
|
|
3531
|
+
const parentLineage = parentSpan ? {
|
|
3532
|
+
parentEntityType: parentSpan.entityType,
|
|
3533
|
+
parentEntityId: parentSpan.entityId,
|
|
3534
|
+
parentEntityName: parentSpan.entityName,
|
|
3535
|
+
parentEntityVersionId: ownEntityVersionId(parentSpan)
|
|
3536
|
+
} : {
|
|
3537
|
+
parentEntityType: restored?.parentEntityType,
|
|
3538
|
+
parentEntityId: restored?.parentEntityId,
|
|
3539
|
+
parentEntityName: restored?.parentEntityName,
|
|
3540
|
+
parentEntityVersionId: restored?.parentEntityVersionId
|
|
3541
|
+
};
|
|
3542
|
+
const rootLineage = restored ? {
|
|
3543
|
+
rootEntityType: restored.rootEntityType,
|
|
3544
|
+
rootEntityId: restored.rootEntityId,
|
|
3545
|
+
rootEntityName: restored.rootEntityName,
|
|
3546
|
+
rootEntityVersionId: restored.rootEntityVersionId
|
|
3547
|
+
} : {
|
|
3548
|
+
rootEntityType: rootSpan.entityType,
|
|
3549
|
+
rootEntityId: rootSpan.entityId,
|
|
3550
|
+
rootEntityName: rootSpan.entityName,
|
|
3551
|
+
rootEntityVersionId: ownEntityVersionId(rootSpan)
|
|
3552
|
+
};
|
|
3490
3553
|
const rootTags = rootSpan.tags?.length ? [...rootSpan.tags] : void 0;
|
|
3491
3554
|
this.correlationContext = {
|
|
3492
3555
|
traceId: this.traceId,
|
|
@@ -3495,15 +3558,9 @@ var BaseSpan = class BaseSpan {
|
|
|
3495
3558
|
entityType: this.entityType,
|
|
3496
3559
|
entityId: this.entityId,
|
|
3497
3560
|
entityName: this.entityName,
|
|
3498
|
-
entityVersionId:
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
parentEntityName: parentSpan?.entityName,
|
|
3502
|
-
parentEntityVersionId: getSpanMetadataString(parentSpan, "entityVersionId"),
|
|
3503
|
-
rootEntityType: rootSpan.entityType,
|
|
3504
|
-
rootEntityId: rootSpan.entityId,
|
|
3505
|
-
rootEntityName: rootSpan.entityName,
|
|
3506
|
-
rootEntityVersionId: getSpanMetadataString(rootSpan, "entityVersionId"),
|
|
3561
|
+
entityVersionId: this.ownEntityVersionId,
|
|
3562
|
+
...parentLineage,
|
|
3563
|
+
...rootLineage,
|
|
3507
3564
|
userId: getMetadataString("userId"),
|
|
3508
3565
|
organizationId: getMetadataString("organizationId"),
|
|
3509
3566
|
resourceId: getMetadataString("resourceId"),
|
|
@@ -3524,6 +3581,7 @@ var BaseSpan = class BaseSpan {
|
|
|
3524
3581
|
const hideOutput = this.traceState?.hideOutput ?? false;
|
|
3525
3582
|
const nestedUnderParent = this.traceState?.nestedUnderParent ?? false;
|
|
3526
3583
|
const links = validLinks(this.links);
|
|
3584
|
+
const correlation = this.getCorrelationContext();
|
|
3527
3585
|
return {
|
|
3528
3586
|
id: this.id,
|
|
3529
3587
|
traceId: this.traceId,
|
|
@@ -3543,6 +3601,8 @@ var BaseSpan = class BaseSpan {
|
|
|
3543
3601
|
isEvent: this.isEvent,
|
|
3544
3602
|
isRootSpan: this.isRootSpan,
|
|
3545
3603
|
...this.isInternal ? { isInternal: true } : {},
|
|
3604
|
+
...correlation.entityVersionId ? { entityVersionId: correlation.entityVersionId } : {},
|
|
3605
|
+
...definedLineage(correlation),
|
|
3546
3606
|
parentSpanId: this.getParentSpanId(includeInternalSpans),
|
|
3547
3607
|
externalParentSpanId: this.getExportedExternalParentSpanId(includeInternalSpans),
|
|
3548
3608
|
...nestedUnderParent ? { nestedUnderParent: true } : {},
|
|
@@ -3554,6 +3614,7 @@ var BaseSpan = class BaseSpan {
|
|
|
3554
3614
|
snapshot() {
|
|
3555
3615
|
return {
|
|
3556
3616
|
...this.exportSpan(),
|
|
3617
|
+
ownEntityVersionId: this.ownEntityVersionId ?? null,
|
|
3557
3618
|
...this.traceState ? { traceState: this.traceState } : {}
|
|
3558
3619
|
};
|
|
3559
3620
|
}
|
|
@@ -3585,8 +3646,7 @@ var BaseSpan = class BaseSpan {
|
|
|
3585
3646
|
return fn();
|
|
3586
3647
|
}
|
|
3587
3648
|
};
|
|
3588
|
-
|
|
3589
|
-
//#region src/spans/default.ts
|
|
3649
|
+
// src/spans/default.ts
|
|
3590
3650
|
/** Every AI SDK `APICallError` (v4, v5 and v6) carries this shared marker symbol. */
|
|
3591
3651
|
const API_CALL_ERROR_MARKER = Symbol.for("vercel.ai.error.AI_APICallError");
|
|
3592
3652
|
function isApiCallError(value) {
|
|
@@ -3777,8 +3837,7 @@ function getOrCreateTraceId(options) {
|
|
|
3777
3837
|
}
|
|
3778
3838
|
return generateTraceId();
|
|
3779
3839
|
}
|
|
3780
|
-
|
|
3781
|
-
//#region src/spans/no-op.ts
|
|
3840
|
+
// src/spans/no-op.ts
|
|
3782
3841
|
var NoOpSpan = class extends BaseSpan {
|
|
3783
3842
|
id;
|
|
3784
3843
|
traceId;
|
|
@@ -3797,8 +3856,7 @@ var NoOpSpan = class extends BaseSpan {
|
|
|
3797
3856
|
return true;
|
|
3798
3857
|
}
|
|
3799
3858
|
};
|
|
3800
|
-
|
|
3801
|
-
//#region src/exporters/base.ts
|
|
3859
|
+
// src/exporters/base.ts
|
|
3802
3860
|
/**
|
|
3803
3861
|
* Base Exporter for Observability
|
|
3804
3862
|
*
|
|
@@ -3960,8 +4018,7 @@ var BaseExporter = class {
|
|
|
3960
4018
|
this.logger.info(`${this.name} shutdown complete`);
|
|
3961
4019
|
}
|
|
3962
4020
|
};
|
|
3963
|
-
|
|
3964
|
-
//#region src/exporters/event-buffer.ts
|
|
4021
|
+
// src/exporters/event-buffer.ts
|
|
3965
4022
|
/**
|
|
3966
4023
|
* Buffers observability events (creates and updates) for batch flushing.
|
|
3967
4024
|
* Handles strategy-aware routing of tracing events and tracks created spans
|
|
@@ -4112,8 +4169,7 @@ var EventBuffer = class {
|
|
|
4112
4169
|
});
|
|
4113
4170
|
}
|
|
4114
4171
|
};
|
|
4115
|
-
|
|
4116
|
-
//#region src/exporters/default.ts
|
|
4172
|
+
// src/exporters/default.ts
|
|
4117
4173
|
/**
|
|
4118
4174
|
* Resolves the final tracing storage strategy based on config and observability store hints
|
|
4119
4175
|
*/
|
|
@@ -4551,8 +4607,7 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
4551
4607
|
this.logger.info("DefaultExporter shutdown complete");
|
|
4552
4608
|
}
|
|
4553
4609
|
};
|
|
4554
|
-
|
|
4555
|
-
//#region src/exporters/mastra-storage.ts
|
|
4610
|
+
// src/exporters/mastra-storage.ts
|
|
4556
4611
|
/**
|
|
4557
4612
|
* Resolves the final tracing storage strategy based on config and observability store hints
|
|
4558
4613
|
*/
|
|
@@ -4989,8 +5044,7 @@ var MastraStorageExporter = class extends BaseExporter {
|
|
|
4989
5044
|
this.logger.info("MastraStorageExporter shutdown complete");
|
|
4990
5045
|
}
|
|
4991
5046
|
};
|
|
4992
|
-
|
|
4993
|
-
//#region src/instances/platform-policy.ts
|
|
5047
|
+
// src/instances/platform-policy.ts
|
|
4994
5048
|
const MASTRA_BUILT_IN_STORAGE_EXPORTER_NAMES = /* @__PURE__ */ new Set(["mastra-storage-exporter", "mastra-default-observability-exporter"]);
|
|
4995
5049
|
function isMastraPlatformDeployment() {
|
|
4996
5050
|
return Boolean(process.env.MASTRA_DEPLOYMENT_ID);
|
|
@@ -4998,8 +5052,7 @@ function isMastraPlatformDeployment() {
|
|
|
4998
5052
|
function isMastraBuiltInStorageExporter(exporter) {
|
|
4999
5053
|
return exporter instanceof MastraStorageExporter || exporter instanceof DefaultExporter || MASTRA_BUILT_IN_STORAGE_EXPORTER_NAMES.has(exporter.name);
|
|
5000
5054
|
}
|
|
5001
|
-
|
|
5002
|
-
//#region src/instances/base.ts
|
|
5055
|
+
// src/instances/base.ts
|
|
5003
5056
|
/**
|
|
5004
5057
|
* BaseObservability - Abstract base class for Observability implementations
|
|
5005
5058
|
*/
|
|
@@ -5185,6 +5238,7 @@ var BaseObservabilityInstance = class extends MastraBase {
|
|
|
5185
5238
|
tracingPolicy: cached.isInternal ? { internal: InternalSpans.ALL } : void 0,
|
|
5186
5239
|
traceState: this.rebuildTraceState(cached)
|
|
5187
5240
|
});
|
|
5241
|
+
if (span instanceof BaseSpan) span.restoreEntityLineage(cached);
|
|
5188
5242
|
this.wireSpanLifecycle(span);
|
|
5189
5243
|
return span;
|
|
5190
5244
|
}
|
|
@@ -5711,13 +5765,11 @@ var BaseObservabilityInstance = class extends MastraBase {
|
|
|
5711
5765
|
this.logger.info(`[Observability] Shutdown completed [name=${this.name}]`);
|
|
5712
5766
|
}
|
|
5713
5767
|
};
|
|
5714
|
-
|
|
5715
|
-
//#region src/client/id.ts
|
|
5768
|
+
// src/client/id.ts
|
|
5716
5769
|
function generateClientSignalId() {
|
|
5717
5770
|
return globalThis.crypto.randomUUID();
|
|
5718
5771
|
}
|
|
5719
|
-
|
|
5720
|
-
//#region src/client/otlp.ts
|
|
5772
|
+
// src/client/otlp.ts
|
|
5721
5773
|
/**
|
|
5722
5774
|
* Hand-rolled OTLP/JSON decoder for the subset we need to ingest from
|
|
5723
5775
|
* client-side tool execution.
|
|
@@ -5905,8 +5957,7 @@ function buildExportedLog(decoded) {
|
|
|
5905
5957
|
data: decoded.attributes
|
|
5906
5958
|
};
|
|
5907
5959
|
}
|
|
5908
|
-
|
|
5909
|
-
//#region src/client/w3c.ts
|
|
5960
|
+
// src/client/w3c.ts
|
|
5910
5961
|
/**
|
|
5911
5962
|
* Hand-rolled W3C Trace Context and Baggage propagation.
|
|
5912
5963
|
*
|
|
@@ -5977,8 +6028,7 @@ function formatBaggage(entries) {
|
|
|
5977
6028
|
}
|
|
5978
6029
|
return parts.join(",");
|
|
5979
6030
|
}
|
|
5980
|
-
|
|
5981
|
-
//#region src/client/proxy.ts
|
|
6031
|
+
// src/client/proxy.ts
|
|
5982
6032
|
const DEFAULT_LIMITS = {
|
|
5983
6033
|
maxSpans: 10,
|
|
5984
6034
|
maxLogs: 10,
|
|
@@ -6116,8 +6166,7 @@ function validateParentLinks(spans, rootParent) {
|
|
|
6116
6166
|
function createClientObservabilityProxy(options) {
|
|
6117
6167
|
return new ClientObservabilityProxyImpl(options);
|
|
6118
6168
|
}
|
|
6119
|
-
|
|
6120
|
-
//#region src/exporters/tracking.ts
|
|
6169
|
+
// src/exporters/tracking.ts
|
|
6121
6170
|
/**
|
|
6122
6171
|
* TrackingExporter base class for vendor-specific observability exporters.
|
|
6123
6172
|
*
|
|
@@ -7198,8 +7247,7 @@ var TrackingExporter = class extends BaseExporter {
|
|
|
7198
7247
|
await super.shutdown();
|
|
7199
7248
|
}
|
|
7200
7249
|
};
|
|
7201
|
-
|
|
7202
|
-
//#region src/exporters/span-formatters.ts
|
|
7250
|
+
// src/exporters/span-formatters.ts
|
|
7203
7251
|
/**
|
|
7204
7252
|
* Chains multiple span formatters into a single formatter.
|
|
7205
7253
|
*
|
|
@@ -7236,8 +7284,7 @@ function chainFormatters(formatters) {
|
|
|
7236
7284
|
return currentSpan;
|
|
7237
7285
|
};
|
|
7238
7286
|
}
|
|
7239
|
-
|
|
7240
|
-
//#region src/exporters/auth-failure-cooldown.ts
|
|
7287
|
+
// src/exporters/auth-failure-cooldown.ts
|
|
7241
7288
|
const AUTH_FAILURE_STATUSES = /* @__PURE__ */ new Set([401, 403]);
|
|
7242
7289
|
const AUTH_COOLDOWN_BASE_MS = 6e4;
|
|
7243
7290
|
const AUTH_COOLDOWN_MAX_MS = 9e5;
|
|
@@ -7318,8 +7365,7 @@ var AuthFailureCooldown = class {
|
|
|
7318
7365
|
});
|
|
7319
7366
|
}
|
|
7320
7367
|
};
|
|
7321
|
-
|
|
7322
|
-
//#region src/exporters/cloud.ts
|
|
7368
|
+
// src/exporters/cloud.ts
|
|
7323
7369
|
const SIGNAL_PUBLISH_SUFFIXES$1 = {
|
|
7324
7370
|
traces: "/spans/publish",
|
|
7325
7371
|
logs: "/logs/publish",
|
|
@@ -7739,8 +7785,7 @@ var CloudExporter = class extends BaseExporter {
|
|
|
7739
7785
|
this.logger.info("CloudExporter shutdown complete");
|
|
7740
7786
|
}
|
|
7741
7787
|
};
|
|
7742
|
-
|
|
7743
|
-
//#region src/exporters/console.ts
|
|
7788
|
+
// src/exporters/console.ts
|
|
7744
7789
|
var ConsoleExporter = class extends BaseExporter {
|
|
7745
7790
|
name = "tracing-console-exporter";
|
|
7746
7791
|
constructor(config = {}) {
|
|
@@ -7803,8 +7848,7 @@ var ConsoleExporter = class extends BaseExporter {
|
|
|
7803
7848
|
this.logger.info("ConsoleExporter shutdown");
|
|
7804
7849
|
}
|
|
7805
7850
|
};
|
|
7806
|
-
|
|
7807
|
-
//#region src/exporters/mastra-platform.ts
|
|
7851
|
+
// src/exporters/mastra-platform.ts
|
|
7808
7852
|
const SIGNAL_PUBLISH_SUFFIXES = {
|
|
7809
7853
|
traces: "/spans/publish",
|
|
7810
7854
|
logs: "/logs/publish",
|
|
@@ -8335,8 +8379,7 @@ var MastraPlatformExporter = class extends BaseExporter {
|
|
|
8335
8379
|
this.logger.info("MastraPlatformExporter shutdown complete");
|
|
8336
8380
|
}
|
|
8337
8381
|
};
|
|
8338
|
-
|
|
8339
|
-
//#region src/exporters/test.ts
|
|
8382
|
+
// src/exporters/test.ts
|
|
8340
8383
|
/**
|
|
8341
8384
|
* Test Exporter for Observability
|
|
8342
8385
|
*
|
|
@@ -9382,8 +9425,7 @@ var TestExporter = class extends BaseExporter {
|
|
|
9382
9425
|
* @deprecated Use `TestExporter` instead. This alias will be removed in a future version.
|
|
9383
9426
|
*/
|
|
9384
9427
|
const JsonExporter = TestExporter;
|
|
9385
|
-
|
|
9386
|
-
//#region src/instances/default.ts
|
|
9428
|
+
// src/instances/default.ts
|
|
9387
9429
|
var DefaultObservabilityInstance = class extends BaseObservabilityInstance {
|
|
9388
9430
|
constructor(config) {
|
|
9389
9431
|
super(config);
|
|
@@ -9392,8 +9434,7 @@ var DefaultObservabilityInstance = class extends BaseObservabilityInstance {
|
|
|
9392
9434
|
return new DefaultSpan(options, this);
|
|
9393
9435
|
}
|
|
9394
9436
|
};
|
|
9395
|
-
|
|
9396
|
-
//#region src/recorded.ts
|
|
9437
|
+
// src/recorded.ts
|
|
9397
9438
|
function nullToUndefined(value) {
|
|
9398
9439
|
return value ?? void 0;
|
|
9399
9440
|
}
|
|
@@ -9697,8 +9738,7 @@ function hydrateRecordedTrace(args) {
|
|
|
9697
9738
|
debugRecordedAnnotationUnavailable
|
|
9698
9739
|
});
|
|
9699
9740
|
}
|
|
9700
|
-
|
|
9701
|
-
//#region src/registry.ts
|
|
9741
|
+
// src/registry.ts
|
|
9702
9742
|
/**
|
|
9703
9743
|
* Registry for Observability instances.
|
|
9704
9744
|
*/
|
|
@@ -9787,8 +9827,7 @@ var ObservabilityRegistry = class {
|
|
|
9787
9827
|
return new Map(this.#instances);
|
|
9788
9828
|
}
|
|
9789
9829
|
};
|
|
9790
|
-
|
|
9791
|
-
//#region src/span_processors/sensitive-data-filter.ts
|
|
9830
|
+
// src/span_processors/sensitive-data-filter.ts
|
|
9792
9831
|
/**
|
|
9793
9832
|
* Maximum number of traces to keep indexed-redaction state for.
|
|
9794
9833
|
* Spans never signal trace completion, so state is evicted least-recently-used.
|
|
@@ -9998,8 +10037,7 @@ var SensitiveDataFilter = class {
|
|
|
9998
10037
|
this.traceStates.clear();
|
|
9999
10038
|
}
|
|
10000
10039
|
};
|
|
10001
|
-
|
|
10002
|
-
//#region src/default.ts
|
|
10040
|
+
// src/default.ts
|
|
10003
10041
|
/**
|
|
10004
10042
|
* Type guard to check if an object is a BaseObservability instance
|
|
10005
10043
|
*/
|
|
@@ -10334,8 +10372,7 @@ var Observability = class extends MastraBase {
|
|
|
10334
10372
|
if (handlerResults.length > 0) await Promise.allSettled(handlerResults);
|
|
10335
10373
|
}
|
|
10336
10374
|
};
|
|
10337
|
-
|
|
10338
|
-
//#region src/features.ts
|
|
10375
|
+
// src/features.ts
|
|
10339
10376
|
/**
|
|
10340
10377
|
* Feature flags for @mastra/observability
|
|
10341
10378
|
*
|
|
@@ -10374,8 +10411,7 @@ var Observability = class extends MastraBase {
|
|
|
10374
10411
|
* ```
|
|
10375
10412
|
*/
|
|
10376
10413
|
const observabilityFeatures = /* @__PURE__ */ new Set(["model-inference-span", "internal-usage-rollup"]);
|
|
10377
|
-
|
|
10378
|
-
//#region src/tracing-options.ts
|
|
10414
|
+
// src/tracing-options.ts
|
|
10379
10415
|
/**
|
|
10380
10416
|
* Builds TracingOptions by composing one or more updater functions.
|
|
10381
10417
|
*
|
|
@@ -10396,7 +10432,6 @@ const observabilityFeatures = /* @__PURE__ */ new Set(["model-inference-span", "
|
|
|
10396
10432
|
function buildTracingOptions(...updaters) {
|
|
10397
10433
|
return updaters.reduce((opts, updater) => updater(opts), {});
|
|
10398
10434
|
}
|
|
10399
|
-
//#endregion
|
|
10400
10435
|
export { BaseExporter, BaseObservabilityEventBus, BaseObservabilityInstance, BaseSpan, CardinalityFilter, CloudExporter, ConsoleExporter, DEFAULT_DEEP_CLEAN_OPTIONS, DEFAULT_LIMITS, DefaultExporter, DefaultObservabilityInstance, DefaultSpan, JsonExporter, LoggerContextImpl, MastraPlatformExporter, MastraStorageExporter, MetricsContextImpl, ModelSpanTracker, NoOpSpan, OBSERVABILITY_CAPABILITIES_HEADER, Observability, ObservabilityBus, QUOTA_PAUSE_CAPABILITY, SamplingStrategyType, SensitiveDataFilter, TestExporter, TraceData, TrackingExporter, buildExportedLog, buildExportedSpan, buildTracingOptions, chainFormatters, createClientObservabilityProxy, decodeResourceLogs, decodeResourceSpans, deepClean, formatBaggage, formatTraceparent, getExternalParentId, isSerializedMap, mergeSerializationOptions, observabilityConfigValueSchema, observabilityFeatures, observabilityInstanceConfigSchema, observabilityRegistryConfigSchema, otlpSeverityToLogLevel, parseBaggage, parseTraceparent, reconstructSerializedMap, routeToHandler, samplingStrategySchema, serializationOptionsSchema, truncateString };
|
|
10401
10436
|
|
|
10402
10437
|
//# sourceMappingURL=index.js.map
|