@mastra/observability 1.17.5-alpha.0 → 1.17.5-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/README.md +14 -85
- package/dist/context/logger.d.ts.map +1 -1
- package/dist/context/metrics.d.ts.map +1 -1
- package/dist/ids.d.ts +66 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/index.cjs +75 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +68 -12
- package/dist/index.js.map +1 -1
- package/dist/instances/base.d.ts.map +1 -1
- package/dist/recorded.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createRequire } from "module";
|
|
|
2
2
|
import { MastraBase } from "@mastra/core/base";
|
|
3
3
|
import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
|
|
4
4
|
import { ConsoleLogger, LogLevel, RegisteredLogger } from "@mastra/core/logger";
|
|
5
|
-
import { DEFAULT_BLOCKED_LABELS, EntityType, InternalSpans, SpanType, TracingEventType,
|
|
5
|
+
import { DEFAULT_BLOCKED_LABELS, EntityType, InternalSpans, SpanType, TracingEventType, noOpLoggerContext } from "@mastra/core/observability";
|
|
6
6
|
import { fetchWithRetry, getNestedValue, setNestedValue } from "@mastra/core/utils";
|
|
7
7
|
import { z } from "zod/v4";
|
|
8
8
|
import fs from "fs";
|
|
@@ -862,13 +862,76 @@ const observabilityRegistryConfigSchema = z.object({
|
|
|
862
862
|
return true;
|
|
863
863
|
}, { message: "A \"configSelector\" requires at least one config or default observability to be configured." });
|
|
864
864
|
//#endregion
|
|
865
|
-
//#region src/
|
|
865
|
+
//#region src/ids.ts
|
|
866
|
+
/**
|
|
867
|
+
* Signal and span id helpers.
|
|
868
|
+
*
|
|
869
|
+
* These two utilities also exist in `@mastra/core/observability`. This package
|
|
870
|
+
* deliberately keeps local copies rather than importing them.
|
|
871
|
+
*
|
|
872
|
+
* Importing a helper from core ties this package's real minimum core version to
|
|
873
|
+
* whichever release happened to add that helper. A named ESM import of an export
|
|
874
|
+
* that does not exist fails at link time, before any application code runs, so
|
|
875
|
+
* the mismatch surfaces as a startup crash rather than a resolvable install
|
|
876
|
+
* error. That is how `resolveExportedSpanId` (added in `@mastra/core@1.63.0`)
|
|
877
|
+
* broke deployments pinned to an older core while the declared peer floor still
|
|
878
|
+
* said `>=1.16.0`; `generateSignalId` (added in `@mastra/core@1.26.0`) had
|
|
879
|
+
* already raised the true floor the same way, unnoticed.
|
|
880
|
+
*
|
|
881
|
+
* Both helpers are self-contained: `generateSignalId` wraps `crypto.randomUUID`,
|
|
882
|
+
* and `resolveExportedSpanId` is structurally typed against an optional method
|
|
883
|
+
* rather than any core class. A local copy costs a few lines and lets the
|
|
884
|
+
* declared peer range stay honest.
|
|
885
|
+
*
|
|
886
|
+
* Keep them local. Re-importing either from core silently raises this package's
|
|
887
|
+
* minimum core version again.
|
|
888
|
+
*
|
|
889
|
+
* TODO(mastra-v2): delete this file and import both helpers from
|
|
890
|
+
* `@mastra/core/observability` again.
|
|
891
|
+
*
|
|
892
|
+
* The duplication exists only because a peer floor cannot be raised inside a
|
|
893
|
+
* major version without breaking consumers pinned to an older core. A v2
|
|
894
|
+
* release resets that floor anyway, so importing from core stops being a
|
|
895
|
+
* compatibility hazard at that point. On v2:
|
|
896
|
+
*
|
|
897
|
+
* 1. Set the `@mastra/core` peer range to the v2 line.
|
|
898
|
+
* 2. Re-point the four import sites -- `generateSignalId` in
|
|
899
|
+
* `context/logger.ts`, `context/metrics.ts` and `recorded.ts`, and
|
|
900
|
+
* `resolveExportedSpanId` in `instances/base.ts`.
|
|
901
|
+
* 3. Delete this file.
|
|
902
|
+
*
|
|
903
|
+
* Do not undo it before then: both helpers are still missing from cores inside
|
|
904
|
+
* this package's currently declared range (`generateSignalId` landed in core
|
|
905
|
+
* 1.26.0, `resolveExportedSpanId` in 1.63.0, floor is 1.16.0).
|
|
906
|
+
*
|
|
907
|
+
* Context: https://github.com/mastra-ai/mastra/issues/22885
|
|
908
|
+
*/
|
|
909
|
+
/** Generate a unique id for an observability signal (log, metric, score, feedback). */
|
|
910
|
+
function generateSignalId() {
|
|
911
|
+
return crypto.randomUUID();
|
|
912
|
+
}
|
|
866
913
|
/**
|
|
867
|
-
*
|
|
914
|
+
* Resolve the spanId an observability signal should reference for a span.
|
|
868
915
|
*
|
|
869
|
-
*
|
|
870
|
-
*
|
|
916
|
+
* Signals (logs, metrics, and a suspending run's resume link) must name a span
|
|
917
|
+
* that actually reached exporters. An internal or excluded span is never stored,
|
|
918
|
+
* so referencing its raw id leaves the signal pointing at nothing: log/metric
|
|
919
|
+
* span lookups 404, and a resumed run's exported children inherit a dangling
|
|
920
|
+
* parentSpanId and land as orphans. `undefined` is a valid answer, omitting the
|
|
921
|
+
* reference rather than pointing it at a span that does not exist.
|
|
922
|
+
*
|
|
923
|
+
* `getExportedSpanId` is optional on the `Span` interface, so the typeof guard
|
|
924
|
+
* separates "this implementation predates the method" (keep the old behavior of
|
|
925
|
+
* referencing the span's own id) from "the method ran and found nothing
|
|
926
|
+
* exportable" (undefined). Without it the two collapse and custom span
|
|
927
|
+
* implementations silently lose correlation.
|
|
871
928
|
*/
|
|
929
|
+
function resolveExportedSpanId(span) {
|
|
930
|
+
if (!span) return void 0;
|
|
931
|
+
return typeof span.getExportedSpanId === "function" ? span.getExportedSpanId() : span.id;
|
|
932
|
+
}
|
|
933
|
+
//#endregion
|
|
934
|
+
//#region src/context/logger.ts
|
|
872
935
|
/** Numeric priority used to compare log levels against the configured minimum. */
|
|
873
936
|
const LOG_LEVEL_PRIORITY = {
|
|
874
937
|
debug: 0,
|
|
@@ -939,13 +1002,6 @@ var LoggerContextImpl = class {
|
|
|
939
1002
|
//#endregion
|
|
940
1003
|
//#region src/context/metrics.ts
|
|
941
1004
|
/**
|
|
942
|
-
* MetricsContextImpl - User-facing metric emission API.
|
|
943
|
-
*
|
|
944
|
-
* All metrics are validated, cardinality-filtered, and constructed here
|
|
945
|
-
* before being routed through ObservabilityBus.emit().
|
|
946
|
-
* CorrelationContext and metadata are snapshotted at construction time.
|
|
947
|
-
*/
|
|
948
|
-
/**
|
|
949
1005
|
* User-facing metric emission API. All metrics are routed through
|
|
950
1006
|
* ObservabilityBus.emit() after validation and cardinality filtering.
|
|
951
1007
|
*/
|