@mastra/observability 1.6.0 → 1.7.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/CHANGELOG.md CHANGED
@@ -1,5 +1,69 @@
1
1
  # @mastra/observability
2
2
 
3
+ ## 1.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added DualLogger that transparently forwards all infrastructure logger calls (debug, info, warn, error, trackException) to the observability system (loggerVNext). This means all internal Mastra logs now automatically appear in your observability storage (e.g. DuckDB) without any code changes. ([#14899](https://github.com/mastra-ai/mastra/pull/14899))
8
+
9
+ **trackException** now extracts structured error data (errorId, domain, category, details, cause) and forwards it as an error-level log to observability storage, so exceptions are queryable alongside regular logs.
10
+
11
+ Added `logging` config option to ObservabilityInstance for controlling which logs reach observability storage:
12
+
13
+ ```ts
14
+ new Observability({
15
+ instance: new MastraObservability({
16
+ logging: {
17
+ enabled: true, // set to false to disable log forwarding
18
+ level: 'info', // minimum level: 'debug' | 'info' | 'warn' | 'error' | 'fatal'
19
+ },
20
+ }),
21
+ });
22
+ ```
23
+
24
+ - Add `registerExporter` method to the observability stack and Mastra class for runtime exporter registration ([#14730](https://github.com/mastra-ai/mastra/pull/14730))
25
+
26
+ ### Patch Changes
27
+
28
+ - Standardized all logger calls across the codebase to use static string messages with structured data objects. Dynamic values are now passed as key-value pairs in the second argument instead of being interpolated into template literal strings. This improves log filterability and searchability in observability storage. ([#14899](https://github.com/mastra-ai/mastra/pull/14899))
29
+
30
+ Removed ~150 redundant or noisy log calls including duplicate error logging after trackException and verbose in-memory storage CRUD traces.
31
+
32
+ - Updated dependencies [[`cbeec24`](https://github.com/mastra-ai/mastra/commit/cbeec24b3c97a1a296e7e461e66cc7f7d215dc50), [`cee146b`](https://github.com/mastra-ai/mastra/commit/cee146b5d858212e1df2b2730fc36d3ceda0e08d), [`aa0aeff`](https://github.com/mastra-ai/mastra/commit/aa0aeffa11efbef5e219fbd97bf43d263cfe3afe), [`2bcec65`](https://github.com/mastra-ai/mastra/commit/2bcec652d62b07eab15e9eb9822f70184526eede), [`ad9bded`](https://github.com/mastra-ai/mastra/commit/ad9bdedf86a824801f49928a8d40f6e31ff5450f), [`cbeec24`](https://github.com/mastra-ai/mastra/commit/cbeec24b3c97a1a296e7e461e66cc7f7d215dc50), [`208c0bb`](https://github.com/mastra-ai/mastra/commit/208c0bbacbf5a1da6318f2a0e0c544390e542ddc), [`f566ee7`](https://github.com/mastra-ai/mastra/commit/f566ee7d53a3da33a01103e2a5ac2070ddefe6b0)]:
33
+ - @mastra/core@1.20.0
34
+
35
+ ## 1.7.0-alpha.0
36
+
37
+ ### Minor Changes
38
+
39
+ - Added DualLogger that transparently forwards all infrastructure logger calls (debug, info, warn, error, trackException) to the observability system (loggerVNext). This means all internal Mastra logs now automatically appear in your observability storage (e.g. DuckDB) without any code changes. ([#14899](https://github.com/mastra-ai/mastra/pull/14899))
40
+
41
+ **trackException** now extracts structured error data (errorId, domain, category, details, cause) and forwards it as an error-level log to observability storage, so exceptions are queryable alongside regular logs.
42
+
43
+ Added `logging` config option to ObservabilityInstance for controlling which logs reach observability storage:
44
+
45
+ ```ts
46
+ new Observability({
47
+ instance: new MastraObservability({
48
+ logging: {
49
+ enabled: true, // set to false to disable log forwarding
50
+ level: 'info', // minimum level: 'debug' | 'info' | 'warn' | 'error' | 'fatal'
51
+ },
52
+ }),
53
+ });
54
+ ```
55
+
56
+ - Add `registerExporter` method to the observability stack and Mastra class for runtime exporter registration ([#14730](https://github.com/mastra-ai/mastra/pull/14730))
57
+
58
+ ### Patch Changes
59
+
60
+ - Standardized all logger calls across the codebase to use static string messages with structured data objects. Dynamic values are now passed as key-value pairs in the second argument instead of being interpolated into template literal strings. This improves log filterability and searchability in observability storage. ([#14899](https://github.com/mastra-ai/mastra/pull/14899))
61
+
62
+ Removed ~150 redundant or noisy log calls including duplicate error logging after trackException and verbose in-memory storage CRUD traces.
63
+
64
+ - Updated dependencies [[`cbeec24`](https://github.com/mastra-ai/mastra/commit/cbeec24b3c97a1a296e7e461e66cc7f7d215dc50), [`cee146b`](https://github.com/mastra-ai/mastra/commit/cee146b5d858212e1df2b2730fc36d3ceda0e08d), [`aa0aeff`](https://github.com/mastra-ai/mastra/commit/aa0aeffa11efbef5e219fbd97bf43d263cfe3afe), [`2bcec65`](https://github.com/mastra-ai/mastra/commit/2bcec652d62b07eab15e9eb9822f70184526eede), [`ad9bded`](https://github.com/mastra-ai/mastra/commit/ad9bdedf86a824801f49928a8d40f6e31ff5450f), [`cbeec24`](https://github.com/mastra-ai/mastra/commit/cbeec24b3c97a1a296e7e461e66cc7f7d215dc50), [`208c0bb`](https://github.com/mastra-ai/mastra/commit/208c0bbacbf5a1da6318f2a0e0c544390e542ddc), [`f566ee7`](https://github.com/mastra-ai/mastra/commit/f566ee7d53a3da33a01103e2a5ac2070ddefe6b0)]:
65
+ - @mastra/core@1.20.0-alpha.0
66
+
3
67
  ## 1.6.0
4
68
 
5
69
  ### Minor Changes
package/dist/config.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * including tracing configs, sampling strategies, and registry setup.
6
6
  */
7
7
  import type { RequestContext } from '@mastra/core/di';
8
- import type { ObservabilityInstance, ObservabilityExporter, ObservabilityBridge, SpanOutputProcessor, ConfigSelector, SerializationOptions, CardinalityConfig } from '@mastra/core/observability';
8
+ import type { ObservabilityInstance, ObservabilityExporter, ObservabilityBridge, SpanOutputProcessor, ConfigSelector, SerializationOptions, CardinalityConfig, LogLevel } from '@mastra/core/observability';
9
9
  import { z } from 'zod/v4';
10
10
  /**
11
11
  * Sampling strategy types
@@ -72,6 +72,16 @@ export interface ObservabilityInstanceConfig {
72
72
  * Applied to all metrics (auto-extracted and user-defined).
73
73
  */
74
74
  cardinality?: CardinalityConfig;
75
+ /**
76
+ * Configuration for the observability logger (loggerVNext).
77
+ * Controls log level filtering and whether dual-write logging is enabled.
78
+ */
79
+ logging?: {
80
+ /** Set to `false` to disable dual-write logging to observability storage. Defaults to `true`. */
81
+ enabled?: boolean;
82
+ /** Minimum log level to write to observability storage. Defaults to `'debug'`. */
83
+ level?: LogLevel;
84
+ };
75
85
  }
76
86
  /**
77
87
  * Complete Observability registry configuration
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAM3B;;GAEG;AACH,oBAAY,oBAAoB;IAC9B,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,KAAK,UAAU;IACf,MAAM,WAAW;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB;IAAE,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,oBAAoB,CAAC,KAAK,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,oBAAoB,CAAC,KAAK,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GACzD;IAAE,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,OAAO,CAAA;CAAE,CAAC;AAMhG;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,qFAAqF;IACr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AoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C;;;;OAIG;IACH,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC;;;OAGG;IACH,OAAO,CAAC,EAAE;QACR,iGAAiG;QACjG,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,kFAAkF;QAClF,KAAK,CAAC,EAAE,QAAQ,CAAC;KAClB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;;;OAIG;IACH,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;IACF,0FAA0F;IAC1F,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,2BAA2B,EAAE,MAAM,CAAC,GAAG,qBAAqB,CAAC,CAAC;IAC5F,yEAAyE;IACzE,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAMD;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;2BAejC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,0BAA0B;;;;;kBAO1B,CAAC;AAEd;;;;GAIG;AACH,eAAO,MAAM,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuB3C,CAAC;AAEJ;;;GAGG;AACH,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;iBAqBxC,CAAC;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,iCAAiC;;;;;;iBAqE3C,CAAC"}
package/dist/index.cjs CHANGED
@@ -19029,7 +19029,8 @@ var BaseObservabilityInstance = class extends base.MastraBase {
19029
19029
  bridge: config2.bridge ?? void 0,
19030
19030
  includeInternalSpans: config2.includeInternalSpans ?? false,
19031
19031
  requestContextKeys: config2.requestContextKeys ?? [],
19032
- serializationOptions: config2.serializationOptions
19032
+ serializationOptions: config2.serializationOptions,
19033
+ logging: config2.logging
19033
19034
  };
19034
19035
  this.cardinalityFilter = new CardinalityFilter(config2.cardinality);
19035
19036
  this.observabilityBus = new ObservabilityBus();
@@ -19174,6 +19175,21 @@ var BaseObservabilityInstance = class extends base.MastraBase {
19174
19175
  getExporters() {
19175
19176
  return [...this.exporters];
19176
19177
  }
19178
+ /**
19179
+ * Register an additional exporter at runtime.
19180
+ * Adds to both the bus (for event routing) and the config (for getExporters).
19181
+ */
19182
+ registerExporter(exporter) {
19183
+ this.observabilityBus.registerExporter(exporter);
19184
+ this.config.exporters ??= [];
19185
+ if (this.config.exporters.includes(exporter)) {
19186
+ return;
19187
+ }
19188
+ this.config.exporters.push(exporter);
19189
+ if (typeof exporter.__setLogger === "function") {
19190
+ exporter.__setLogger(this.logger);
19191
+ }
19192
+ }
19177
19193
  /**
19178
19194
  * Get all span output processors
19179
19195
  */
@@ -19209,6 +19225,9 @@ var BaseObservabilityInstance = class extends base.MastraBase {
19209
19225
  * `observabilityContext.loggerVNext` is a real logger instead of no-op.
19210
19226
  */
19211
19227
  getLoggerContext(span) {
19228
+ if (this.config.logging?.enabled === false) {
19229
+ return observability.noOpLoggerContext;
19230
+ }
19212
19231
  const correlationContext = span?.getCorrelationContext?.();
19213
19232
  const metadata = span?.metadata ? structuredClone(span.metadata) : void 0;
19214
19233
  return new LoggerContextImpl({
@@ -19216,7 +19235,8 @@ var BaseObservabilityInstance = class extends base.MastraBase {
19216
19235
  spanId: span?.id,
19217
19236
  correlationContext,
19218
19237
  metadata,
19219
- observabilityBus: this.observabilityBus
19238
+ observabilityBus: this.observabilityBus,
19239
+ minLevel: this.config.logging?.level
19220
19240
  });
19221
19241
  }
19222
19242
  /**