@mastra/core 0.16.3 → 0.16.4-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.
Files changed (175) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/agent/agent.d.ts +1 -1
  3. package/dist/agent/agent.d.ts.map +1 -1
  4. package/dist/agent/agent.types.d.ts +7 -1
  5. package/dist/agent/agent.types.d.ts.map +1 -1
  6. package/dist/agent/index.cjs +11 -11
  7. package/dist/agent/index.js +2 -2
  8. package/dist/agent/input-processor/index.cjs +6 -6
  9. package/dist/agent/input-processor/index.js +1 -1
  10. package/dist/ai-tracing/exporters/cloud.d.ts.map +1 -1
  11. package/dist/ai-tracing/exporters/default.d.ts.map +1 -1
  12. package/dist/ai-tracing/index.cjs +42 -30
  13. package/dist/ai-tracing/index.d.ts +3 -2
  14. package/dist/ai-tracing/index.d.ts.map +1 -1
  15. package/dist/ai-tracing/index.js +1 -1
  16. package/dist/ai-tracing/registry.d.ts +11 -12
  17. package/dist/ai-tracing/registry.d.ts.map +1 -1
  18. package/dist/ai-tracing/span_processors/index.d.ts +5 -0
  19. package/dist/ai-tracing/span_processors/index.d.ts.map +1 -0
  20. package/dist/ai-tracing/span_processors/sensitive-data-filter.d.ts +79 -0
  21. package/dist/ai-tracing/span_processors/sensitive-data-filter.d.ts.map +1 -0
  22. package/dist/ai-tracing/spans/base.d.ts +59 -0
  23. package/dist/ai-tracing/spans/base.d.ts.map +1 -0
  24. package/dist/ai-tracing/spans/default.d.ts +13 -0
  25. package/dist/ai-tracing/spans/default.d.ts.map +1 -0
  26. package/dist/ai-tracing/spans/index.d.ts +7 -0
  27. package/dist/ai-tracing/spans/index.d.ts.map +1 -0
  28. package/dist/ai-tracing/spans/no-op.d.ts +15 -0
  29. package/dist/ai-tracing/spans/no-op.d.ts.map +1 -0
  30. package/dist/ai-tracing/{base.d.ts → tracers/base.d.ts} +11 -24
  31. package/dist/ai-tracing/tracers/base.d.ts.map +1 -0
  32. package/dist/ai-tracing/tracers/default.d.ts +7 -0
  33. package/dist/ai-tracing/tracers/default.d.ts.map +1 -0
  34. package/dist/ai-tracing/tracers/index.d.ts +6 -0
  35. package/dist/ai-tracing/tracers/index.d.ts.map +1 -0
  36. package/dist/ai-tracing/types.d.ts +181 -97
  37. package/dist/ai-tracing/types.d.ts.map +1 -1
  38. package/dist/ai-tracing/utils.d.ts +13 -30
  39. package/dist/ai-tracing/utils.d.ts.map +1 -1
  40. package/dist/{chunk-YW7UILPE.js → chunk-A3QHQYMC.js} +9 -4
  41. package/dist/chunk-A3QHQYMC.js.map +1 -0
  42. package/dist/{chunk-37GX66ZQ.cjs → chunk-BIXBJ4DU.cjs} +7 -7
  43. package/dist/{chunk-37GX66ZQ.cjs.map → chunk-BIXBJ4DU.cjs.map} +1 -1
  44. package/dist/{chunk-DWGGSV3L.js → chunk-BVE3UPHV.js} +4 -4
  45. package/dist/{chunk-DWGGSV3L.js.map → chunk-BVE3UPHV.js.map} +1 -1
  46. package/dist/{chunk-46ZMVRXN.js → chunk-CLEXBHVL.js} +5 -5
  47. package/dist/chunk-CLEXBHVL.js.map +1 -0
  48. package/dist/{chunk-PPMRSBCA.cjs → chunk-DORWTJUT.cjs} +25 -145
  49. package/dist/chunk-DORWTJUT.cjs.map +1 -0
  50. package/dist/{chunk-I77GWNQI.cjs → chunk-DUUXEPE5.cjs} +4 -4
  51. package/dist/{chunk-I77GWNQI.cjs.map → chunk-DUUXEPE5.cjs.map} +1 -1
  52. package/dist/{chunk-VK7LOYGD.cjs → chunk-EE5TG5UG.cjs} +12 -12
  53. package/dist/chunk-EE5TG5UG.cjs.map +1 -0
  54. package/dist/{chunk-CM4UEIAB.cjs → chunk-ELLP4WJF.cjs} +64 -53
  55. package/dist/chunk-ELLP4WJF.cjs.map +1 -0
  56. package/dist/{chunk-CWK46GAF.js → chunk-ENZVBXRB.js} +9 -2
  57. package/dist/chunk-ENZVBXRB.js.map +1 -0
  58. package/dist/{chunk-VVUCWRGD.cjs → chunk-ERRIEUC2.cjs} +415 -371
  59. package/dist/chunk-ERRIEUC2.cjs.map +1 -0
  60. package/dist/{chunk-AV5QBG6P.cjs → chunk-GJKL73EJ.cjs} +14 -10
  61. package/dist/chunk-GJKL73EJ.cjs.map +1 -0
  62. package/dist/{chunk-HHRWDBFK.js → chunk-J52TTT6T.js} +41 -30
  63. package/dist/chunk-J52TTT6T.js.map +1 -0
  64. package/dist/{chunk-SLQGF75B.js → chunk-KFXKSOXF.js} +3 -3
  65. package/dist/{chunk-SLQGF75B.js.map → chunk-KFXKSOXF.js.map} +1 -1
  66. package/dist/{chunk-33GDW3SI.cjs → chunk-KICLFGCP.cjs} +9 -2
  67. package/dist/chunk-KICLFGCP.cjs.map +1 -0
  68. package/dist/{chunk-2LEMTQEN.cjs → chunk-L34N5NMP.cjs} +4 -4
  69. package/dist/{chunk-2LEMTQEN.cjs.map → chunk-L34N5NMP.cjs.map} +1 -1
  70. package/dist/{chunk-WAN6BRTN.js → chunk-O5GOFG6A.js} +11 -7
  71. package/dist/chunk-O5GOFG6A.js.map +1 -0
  72. package/dist/{chunk-W5K2KOZX.js → chunk-ODLGLX2R.js} +410 -369
  73. package/dist/chunk-ODLGLX2R.js.map +1 -0
  74. package/dist/{chunk-S6MAHT7F.cjs → chunk-OXAN5SM7.cjs} +9 -4
  75. package/dist/chunk-OXAN5SM7.cjs.map +1 -0
  76. package/dist/{chunk-6ILOFPTU.js → chunk-PRTH6W72.js} +21 -141
  77. package/dist/chunk-PRTH6W72.js.map +1 -0
  78. package/dist/{chunk-3CYEVZGC.cjs → chunk-VH3RNDZA.cjs} +6 -6
  79. package/dist/{chunk-3CYEVZGC.cjs.map → chunk-VH3RNDZA.cjs.map} +1 -1
  80. package/dist/{chunk-BE6HGZV7.js → chunk-WNN3LIOF.js} +3 -3
  81. package/dist/{chunk-BE6HGZV7.js.map → chunk-WNN3LIOF.js.map} +1 -1
  82. package/dist/{chunk-7ARB2XCY.js → chunk-ZDMAOD35.js} +3 -3
  83. package/dist/{chunk-7ARB2XCY.js.map → chunk-ZDMAOD35.js.map} +1 -1
  84. package/dist/index.cjs +43 -43
  85. package/dist/index.js +9 -9
  86. package/dist/llm/model/model.d.ts.map +1 -1
  87. package/dist/llm/model/model.loop.d.ts.map +1 -1
  88. package/dist/loop/index.cjs +2 -2
  89. package/dist/loop/index.js +1 -1
  90. package/dist/loop/network/index.d.ts +2 -1
  91. package/dist/loop/network/index.d.ts.map +1 -1
  92. package/dist/mastra/index.cjs +2 -2
  93. package/dist/mastra/index.d.ts +2 -2
  94. package/dist/mastra/index.d.ts.map +1 -1
  95. package/dist/mastra/index.js +1 -1
  96. package/dist/memory/index.cjs +4 -4
  97. package/dist/memory/index.js +1 -1
  98. package/dist/network/index.cjs +2 -2
  99. package/dist/network/index.js +1 -1
  100. package/dist/network/vNext/index.cjs +29 -29
  101. package/dist/network/vNext/index.js +2 -2
  102. package/dist/processors/index.cjs +8 -8
  103. package/dist/processors/index.js +2 -2
  104. package/dist/relevance/index.cjs +4 -4
  105. package/dist/relevance/index.js +1 -1
  106. package/dist/scores/index.cjs +8 -8
  107. package/dist/scores/index.js +1 -1
  108. package/dist/server/types.d.ts +3 -0
  109. package/dist/server/types.d.ts.map +1 -1
  110. package/dist/storage/base.d.ts +2 -1
  111. package/dist/storage/base.d.ts.map +1 -1
  112. package/dist/storage/domains/workflows/base.d.ts +1 -0
  113. package/dist/storage/domains/workflows/base.d.ts.map +1 -1
  114. package/dist/storage/domains/workflows/inmemory.d.ts +2 -1
  115. package/dist/storage/domains/workflows/inmemory.d.ts.map +1 -1
  116. package/dist/storage/index.cjs +17 -12
  117. package/dist/storage/index.cjs.map +1 -1
  118. package/dist/storage/index.js +11 -6
  119. package/dist/storage/index.js.map +1 -1
  120. package/dist/storage/mock.d.ts +2 -1
  121. package/dist/storage/mock.d.ts.map +1 -1
  122. package/dist/storage/types.d.ts +1 -0
  123. package/dist/storage/types.d.ts.map +1 -1
  124. package/dist/stream/MastraAgentNetworkStream.d.ts +18 -0
  125. package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -0
  126. package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
  127. package/dist/stream/base/output.d.ts.map +1 -1
  128. package/dist/stream/index.cjs +3 -3
  129. package/dist/stream/index.js +1 -1
  130. package/dist/test-utils/llm-mock.cjs +2 -2
  131. package/dist/test-utils/llm-mock.js +1 -1
  132. package/dist/tools/index.cjs +2 -2
  133. package/dist/tools/index.js +1 -1
  134. package/dist/tools/stream.d.ts.map +1 -1
  135. package/dist/tools/tool-builder/builder.d.ts.map +1 -1
  136. package/dist/utils.cjs +17 -17
  137. package/dist/utils.js +1 -1
  138. package/dist/workflows/default.d.ts +15 -7
  139. package/dist/workflows/default.d.ts.map +1 -1
  140. package/dist/workflows/evented/index.cjs +10 -10
  141. package/dist/workflows/evented/index.js +1 -1
  142. package/dist/workflows/evented/workflow.d.ts +1 -21
  143. package/dist/workflows/evented/workflow.d.ts.map +1 -1
  144. package/dist/workflows/execution-engine.d.ts +1 -0
  145. package/dist/workflows/execution-engine.d.ts.map +1 -1
  146. package/dist/workflows/index.cjs +10 -10
  147. package/dist/workflows/index.js +1 -1
  148. package/dist/workflows/legacy/index.cjs +22 -22
  149. package/dist/workflows/legacy/index.js +1 -1
  150. package/dist/workflows/step.d.ts +1 -0
  151. package/dist/workflows/step.d.ts.map +1 -1
  152. package/dist/workflows/types.d.ts +3 -14
  153. package/dist/workflows/types.d.ts.map +1 -1
  154. package/dist/workflows/workflow.d.ts +13 -0
  155. package/dist/workflows/workflow.d.ts.map +1 -1
  156. package/package.json +1 -1
  157. package/dist/ai-tracing/base.d.ts.map +0 -1
  158. package/dist/ai-tracing/default.d.ts +0 -17
  159. package/dist/ai-tracing/default.d.ts.map +0 -1
  160. package/dist/ai-tracing/no-op.d.ts +0 -62
  161. package/dist/ai-tracing/no-op.d.ts.map +0 -1
  162. package/dist/chunk-33GDW3SI.cjs.map +0 -1
  163. package/dist/chunk-46ZMVRXN.js.map +0 -1
  164. package/dist/chunk-6ILOFPTU.js.map +0 -1
  165. package/dist/chunk-AV5QBG6P.cjs.map +0 -1
  166. package/dist/chunk-CM4UEIAB.cjs.map +0 -1
  167. package/dist/chunk-CWK46GAF.js.map +0 -1
  168. package/dist/chunk-HHRWDBFK.js.map +0 -1
  169. package/dist/chunk-PPMRSBCA.cjs.map +0 -1
  170. package/dist/chunk-S6MAHT7F.cjs.map +0 -1
  171. package/dist/chunk-VK7LOYGD.cjs.map +0 -1
  172. package/dist/chunk-VVUCWRGD.cjs.map +0 -1
  173. package/dist/chunk-W5K2KOZX.js.map +0 -1
  174. package/dist/chunk-WAN6BRTN.js.map +0 -1
  175. package/dist/chunk-YW7UILPE.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { RuntimeContext } from './chunk-HLRWYUFN.js';
2
2
  import { MastraError } from './chunk-MCOVMKIS.js';
3
- import { ToolStream } from './chunk-YW7UILPE.js';
3
+ import { ToolStream } from './chunk-A3QHQYMC.js';
4
4
  import { isVercelTool, validateToolInput } from './chunk-BJGHUKKM.js';
5
5
  import { MastraBase } from './chunk-6GF5M4GX.js';
6
6
  import { RegisteredLogger, ConsoleLogger, LogLevel } from './chunk-X3GXU6TZ.js';
@@ -9,51 +9,238 @@ import jsonSchemaToZod from 'json-schema-to-zod';
9
9
  import { z } from 'zod';
10
10
  import { convertZodSchemaToAISDKSchema, OpenAIReasoningSchemaCompatLayer, OpenAISchemaCompatLayer, GoogleSchemaCompatLayer, AnthropicSchemaCompatLayer, DeepSeekSchemaCompatLayer, MetaSchemaCompatLayer, applyCompatLayer } from '@mastra/schema-compat';
11
11
 
12
- // src/ai-tracing/no-op.ts
13
- var NoOpAISpan = class _NoOpAISpan {
14
- id;
12
+ // src/ai-tracing/spans/base.ts
13
+ var BaseAISpan = class {
15
14
  name;
16
15
  type;
17
16
  attributes;
18
17
  parent;
19
- traceId;
20
18
  startTime;
21
19
  endTime;
22
20
  isEvent;
21
+ isInternal;
23
22
  aiTracing;
24
23
  input;
25
24
  output;
26
25
  errorInfo;
27
26
  metadata;
28
27
  constructor(options, aiTracing) {
29
- this.id = "no-op";
30
28
  this.name = options.name;
31
29
  this.type = options.type;
32
- this.attributes = options.attributes || {};
33
- this.metadata = options.metadata;
30
+ this.attributes = deepClean(options.attributes) || {};
31
+ this.metadata = deepClean(options.metadata);
34
32
  this.parent = options.parent;
35
- this.traceId = "no-op-trace";
36
33
  this.startTime = /* @__PURE__ */ new Date();
37
34
  this.aiTracing = aiTracing;
38
- this.input = options.input;
39
- this.output = options.isEvent ? options.output : void 0;
40
- this.isEvent = options.isEvent;
41
- }
42
- end(_options) {
43
- }
44
- error(_options) {
35
+ this.isEvent = options.isEvent ?? false;
36
+ this.isInternal = options.isInternal ?? false;
37
+ if (this.isEvent) {
38
+ this.output = deepClean(options.output);
39
+ } else {
40
+ this.input = deepClean(options.input);
41
+ }
45
42
  }
46
43
  createChildSpan(options) {
47
- return new _NoOpAISpan({ ...options, parent: this, isEvent: false }, this.aiTracing);
44
+ return this.aiTracing.startSpan({ ...options, parent: this, isEvent: false });
48
45
  }
49
46
  createEventSpan(options) {
50
- return new _NoOpAISpan({ ...options, parent: this, isEvent: true }, this.aiTracing);
51
- }
52
- update(_options) {
47
+ return this.aiTracing.startSpan({ ...options, parent: this, isEvent: true });
53
48
  }
49
+ /** Returns `TRUE` if the span is the root span of a trace */
54
50
  get isRootSpan() {
55
51
  return !this.parent;
56
52
  }
53
+ /** Get the closest parent spanId that isn't an internal span */
54
+ getParentSpanId(includeInternalSpans) {
55
+ if (!this.parent) return void 0;
56
+ if (includeInternalSpans) return this.parent.id;
57
+ if (this.parent.isInternal) return this.parent.getParentSpanId(includeInternalSpans);
58
+ return this.parent.id;
59
+ }
60
+ /** Returns a lightweight span ready for export */
61
+ exportSpan(includeInternalSpans) {
62
+ return {
63
+ id: this.id,
64
+ traceId: this.traceId,
65
+ name: this.name,
66
+ type: this.type,
67
+ attributes: this.attributes,
68
+ metadata: this.metadata,
69
+ startTime: this.startTime,
70
+ endTime: this.endTime,
71
+ input: this.input,
72
+ output: this.output,
73
+ errorInfo: this.errorInfo,
74
+ isEvent: this.isEvent,
75
+ isRootSpan: this.isRootSpan,
76
+ parentSpanId: this.getParentSpanId(includeInternalSpans)
77
+ };
78
+ }
79
+ };
80
+ var DEFAULT_KEYS_TO_STRIP = /* @__PURE__ */ new Set([
81
+ "logger",
82
+ "experimental_providerMetadata",
83
+ "providerMetadata",
84
+ "steps",
85
+ "tracingContext"
86
+ ]);
87
+ function deepClean(value, options = {}, _seen = /* @__PURE__ */ new WeakSet(), _depth = 0) {
88
+ const { keysToStrip = DEFAULT_KEYS_TO_STRIP, maxDepth = 10 } = options;
89
+ if (_depth > maxDepth) {
90
+ return "[MaxDepth]";
91
+ }
92
+ if (value === null || typeof value !== "object") {
93
+ try {
94
+ JSON.stringify(value);
95
+ return value;
96
+ } catch (error) {
97
+ return `[${error instanceof Error ? error.message : String(error)}]`;
98
+ }
99
+ }
100
+ if (_seen.has(value)) {
101
+ return "[Circular]";
102
+ }
103
+ _seen.add(value);
104
+ if (Array.isArray(value)) {
105
+ return value.map((item) => deepClean(item, options, _seen, _depth + 1));
106
+ }
107
+ const cleaned = {};
108
+ for (const [key, val] of Object.entries(value)) {
109
+ if (keysToStrip.has(key)) {
110
+ continue;
111
+ }
112
+ try {
113
+ cleaned[key] = deepClean(val, options, _seen, _depth + 1);
114
+ } catch (error) {
115
+ cleaned[key] = `[${error instanceof Error ? error.message : String(error)}]`;
116
+ }
117
+ }
118
+ return cleaned;
119
+ }
120
+
121
+ // src/ai-tracing/spans/default.ts
122
+ var DefaultAISpan = class extends BaseAISpan {
123
+ id;
124
+ traceId;
125
+ constructor(options, aiTracing) {
126
+ super(options, aiTracing);
127
+ this.id = generateSpanId();
128
+ if (!options.parent) {
129
+ this.traceId = generateTraceId();
130
+ } else {
131
+ this.traceId = options.parent.traceId;
132
+ }
133
+ }
134
+ end(options) {
135
+ if (this.isEvent) {
136
+ return;
137
+ }
138
+ this.endTime = /* @__PURE__ */ new Date();
139
+ if (options?.output !== void 0) {
140
+ this.output = deepClean(options.output);
141
+ }
142
+ if (options?.attributes) {
143
+ this.attributes = { ...this.attributes, ...deepClean(options.attributes) };
144
+ }
145
+ if (options?.metadata) {
146
+ this.metadata = { ...this.metadata, ...deepClean(options.metadata) };
147
+ }
148
+ }
149
+ error(options) {
150
+ if (this.isEvent) {
151
+ return;
152
+ }
153
+ const { error, endSpan = true, attributes, metadata } = options;
154
+ this.errorInfo = error instanceof MastraError ? {
155
+ id: error.id,
156
+ details: error.details,
157
+ category: error.category,
158
+ domain: error.domain,
159
+ message: error.message
160
+ } : {
161
+ message: error.message
162
+ };
163
+ if (attributes) {
164
+ this.attributes = { ...this.attributes, ...deepClean(attributes) };
165
+ }
166
+ if (metadata) {
167
+ this.metadata = { ...this.metadata, ...deepClean(metadata) };
168
+ }
169
+ if (endSpan) {
170
+ this.end();
171
+ } else {
172
+ this.update({});
173
+ }
174
+ }
175
+ update(options) {
176
+ if (this.isEvent) {
177
+ return;
178
+ }
179
+ if (options.input !== void 0) {
180
+ this.input = deepClean(options.input);
181
+ }
182
+ if (options.output !== void 0) {
183
+ this.output = deepClean(options.output);
184
+ }
185
+ if (options.attributes) {
186
+ this.attributes = { ...this.attributes, ...deepClean(options.attributes) };
187
+ }
188
+ if (options.metadata) {
189
+ this.metadata = { ...this.metadata, ...deepClean(options.metadata) };
190
+ }
191
+ }
192
+ get isValid() {
193
+ return true;
194
+ }
195
+ async export() {
196
+ return JSON.stringify({
197
+ spanId: this.id,
198
+ traceId: this.traceId,
199
+ startTime: this.startTime,
200
+ endTime: this.endTime,
201
+ attributes: this.attributes,
202
+ metadata: this.metadata
203
+ });
204
+ }
205
+ };
206
+ function generateSpanId() {
207
+ const bytes = new Uint8Array(8);
208
+ if (typeof crypto !== "undefined" && crypto.getRandomValues) {
209
+ crypto.getRandomValues(bytes);
210
+ } else {
211
+ for (let i = 0; i < 8; i++) {
212
+ bytes[i] = Math.floor(Math.random() * 256);
213
+ }
214
+ }
215
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
216
+ }
217
+ function generateTraceId() {
218
+ const bytes = new Uint8Array(16);
219
+ if (typeof crypto !== "undefined" && crypto.getRandomValues) {
220
+ crypto.getRandomValues(bytes);
221
+ } else {
222
+ for (let i = 0; i < 16; i++) {
223
+ bytes[i] = Math.floor(Math.random() * 256);
224
+ }
225
+ }
226
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
227
+ }
228
+
229
+ // src/ai-tracing/spans/no-op.ts
230
+ var NoOpAISpan = class extends BaseAISpan {
231
+ id;
232
+ traceId;
233
+ constructor(options, aiTracing) {
234
+ super(options, aiTracing);
235
+ this.id = "no-op";
236
+ this.traceId = "no-op-trace";
237
+ }
238
+ end(_options) {
239
+ }
240
+ error(_options) {
241
+ }
242
+ update(_options) {
243
+ }
57
244
  get isValid() {
58
245
  return false;
59
246
  }
@@ -91,8 +278,8 @@ var AITracingEventType = /* @__PURE__ */ ((AITracingEventType2) => {
91
278
  return AITracingEventType2;
92
279
  })(AITracingEventType || {});
93
280
 
94
- // src/ai-tracing/base.ts
95
- var MastraAITracing = class extends MastraBase {
281
+ // src/ai-tracing/tracers/base.ts
282
+ var BaseAITracing = class extends MastraBase {
96
283
  config;
97
284
  constructor(config) {
98
285
  super({ component: RegisteredLogger.AI_TRACING, name: config.serviceName });
@@ -101,7 +288,8 @@ var MastraAITracing = class extends MastraBase {
101
288
  name: config.name,
102
289
  sampling: config.sampling ?? { type: "always" /* ALWAYS */ },
103
290
  exporters: config.exporters ?? [],
104
- processors: config.processors ?? []
291
+ processors: config.processors ?? [],
292
+ includeInternalSpans: config.includeInternalSpans ?? false
105
293
  };
106
294
  }
107
295
  /**
@@ -129,25 +317,11 @@ var MastraAITracing = class extends MastraBase {
129
317
  * Start a new span of a specific AISpanType
130
318
  */
131
319
  startSpan(options) {
132
- const { type, name, input, output, attributes, metadata, parent, startOptions, isEvent } = options;
133
- const { runtimeContext } = startOptions || {};
134
- if (!this.shouldSample({ runtimeContext })) {
135
- return new NoOpAISpan(
136
- { type, name, input, output, attributes, metadata, parent, isEvent: isEvent === true },
137
- this
138
- );
320
+ const { customSamplerOptions, ...createSpanOptions } = options;
321
+ if (!this.shouldSample(customSamplerOptions)) {
322
+ return new NoOpAISpan(createSpanOptions, this);
139
323
  }
140
- const spanOptions = {
141
- type,
142
- name,
143
- input,
144
- output,
145
- attributes,
146
- metadata,
147
- parent,
148
- isEvent: isEvent === true
149
- };
150
- const span = this.createSpan(spanOptions);
324
+ const span = this.createSpan(createSpanOptions);
151
325
  if (span.isEvent) {
152
326
  this.emitSpanEnded(span);
153
327
  } else {
@@ -194,6 +368,9 @@ var MastraAITracing = class extends MastraBase {
194
368
  * This ensures all spans emit events regardless of implementation
195
369
  */
196
370
  wireSpanLifecycle(span) {
371
+ if (!this.config.includeInternalSpans && span.isInternal) {
372
+ return;
373
+ }
197
374
  const originalEnd = span.end.bind(span);
198
375
  const originalUpdate = span.update.bind(span);
199
376
  span.end = (options) => {
@@ -219,7 +396,7 @@ var MastraAITracing = class extends MastraBase {
219
396
  /**
220
397
  * Check if an AI trace should be sampled
221
398
  */
222
- shouldSample(traceContext) {
399
+ shouldSample(options) {
223
400
  const { sampling } = this.config;
224
401
  switch (sampling.type) {
225
402
  case "always" /* ALWAYS */:
@@ -235,7 +412,7 @@ var MastraAITracing = class extends MastraBase {
235
412
  }
236
413
  return Math.random() < sampling.probability;
237
414
  case "custom" /* CUSTOM */:
238
- return sampling.sampler(traceContext);
415
+ return sampling.sampler(options);
239
416
  default:
240
417
  throw new Error(`Sampling strategy type not implemented: ${sampling.type}`);
241
418
  }
@@ -244,29 +421,34 @@ var MastraAITracing = class extends MastraBase {
244
421
  * Process a span through all processors
245
422
  */
246
423
  processSpan(span) {
247
- let processedSpan = span;
248
424
  for (const processor of this.processors) {
249
- if (!processedSpan) {
425
+ if (!span) {
250
426
  break;
251
427
  }
252
428
  try {
253
- processedSpan = processor.process(processedSpan);
429
+ span = processor.process(span);
254
430
  } catch (error) {
255
431
  this.logger.error(`[AI Tracing] Processor error [name=${processor.name}]`, error);
256
432
  }
257
433
  }
258
- return processedSpan;
434
+ return span;
259
435
  }
260
436
  // ============================================================================
261
437
  // Event-driven Export Methods
262
438
  // ============================================================================
439
+ getSpanForExport(span) {
440
+ if (!span.isValid) return void 0;
441
+ if (span.isInternal && !this.config.includeInternalSpans) return void 0;
442
+ const processedSpan = this.processSpan(span);
443
+ return processedSpan?.exportSpan(this.config.includeInternalSpans);
444
+ }
263
445
  /**
264
446
  * Emit a span started event
265
447
  */
266
448
  emitSpanStarted(span) {
267
- const processedSpan = this.processSpan(span);
268
- if (processedSpan) {
269
- this.exportEvent({ type: "span_started" /* SPAN_STARTED */, span: processedSpan }).catch((error) => {
449
+ const exportedSpan = this.getSpanForExport(span);
450
+ if (exportedSpan) {
451
+ this.exportEvent({ type: "span_started" /* SPAN_STARTED */, exportedSpan }).catch((error) => {
270
452
  this.logger.error("[AI Tracing] Failed to export span_started event", error);
271
453
  });
272
454
  }
@@ -275,9 +457,9 @@ var MastraAITracing = class extends MastraBase {
275
457
  * Emit a span ended event (called automatically when spans end)
276
458
  */
277
459
  emitSpanEnded(span) {
278
- const processedSpan = this.processSpan(span);
279
- if (processedSpan) {
280
- this.exportEvent({ type: "span_ended" /* SPAN_ENDED */, span: processedSpan }).catch((error) => {
460
+ const exportedSpan = this.getSpanForExport(span);
461
+ if (exportedSpan) {
462
+ this.exportEvent({ type: "span_ended" /* SPAN_ENDED */, exportedSpan }).catch((error) => {
281
463
  this.logger.error("[AI Tracing] Failed to export span_ended event", error);
282
464
  });
283
465
  }
@@ -286,9 +468,9 @@ var MastraAITracing = class extends MastraBase {
286
468
  * Emit a span updated event
287
469
  */
288
470
  emitSpanUpdated(span) {
289
- const processedSpan = this.processSpan(span);
290
- if (processedSpan) {
291
- this.exportEvent({ type: "span_updated" /* SPAN_UPDATED */, span: processedSpan }).catch((error) => {
471
+ const exportedSpan = this.getSpanForExport(span);
472
+ if (exportedSpan) {
473
+ this.exportEvent({ type: "span_updated" /* SPAN_UPDATED */, exportedSpan }).catch((error) => {
292
474
  this.logger.error("[AI Tracing] Failed to export span_updated event", error);
293
475
  });
294
476
  }
@@ -329,6 +511,16 @@ var MastraAITracing = class extends MastraBase {
329
511
  this.logger.info(`[AI Tracing] Shutdown completed [name=${this.name}]`);
330
512
  }
331
513
  };
514
+
515
+ // src/ai-tracing/tracers/default.ts
516
+ var DefaultAITracing = class extends BaseAITracing {
517
+ constructor(config) {
518
+ super(config);
519
+ }
520
+ createSpan(options) {
521
+ return new DefaultAISpan(options, this);
522
+ }
523
+ };
332
524
  var CoreToolBuilder = class extends MastraBase {
333
525
  originalTool;
334
526
  options;
@@ -401,7 +593,8 @@ var CoreToolBuilder = class extends MastraBase {
401
593
  toolId: options.name,
402
594
  toolDescription: options.description,
403
595
  toolType: logType || "tool"
404
- }
596
+ },
597
+ isInternal: options.tracingContext?.isInternal
405
598
  });
406
599
  try {
407
600
  let result;
@@ -896,7 +1089,7 @@ var CloudExporter = class {
896
1089
  if (this.buffer.totalSize === 0) {
897
1090
  this.buffer.firstEventTime = /* @__PURE__ */ new Date();
898
1091
  }
899
- const spanRecord = this.formatSpan(event.span);
1092
+ const spanRecord = this.formatSpan(event.exportedSpan);
900
1093
  this.buffer.spans.push(spanRecord);
901
1094
  this.buffer.totalSize++;
902
1095
  }
@@ -904,7 +1097,7 @@ var CloudExporter = class {
904
1097
  const spanRecord = {
905
1098
  traceId: span.traceId,
906
1099
  spanId: span.id,
907
- parentSpanId: span.parent?.id ?? null,
1100
+ parentSpanId: span.parentSpanId ?? null,
908
1101
  name: span.name,
909
1102
  spanType: span.type,
910
1103
  attributes: span.attributes ?? null,
@@ -1054,7 +1247,7 @@ var ConsoleExporter = class {
1054
1247
  }
1055
1248
  }
1056
1249
  async exportEvent(event) {
1057
- const span = event.span;
1250
+ const span = event.exportedSpan;
1058
1251
  const formatAttributes = (attributes) => {
1059
1252
  try {
1060
1253
  return JSON.stringify(attributes, null, 2);
@@ -1233,8 +1426,8 @@ var DefaultExporter = class {
1233
1426
  */
1234
1427
  handleOutOfOrderUpdate(event) {
1235
1428
  this.logger.warn("Out-of-order span update detected - skipping event", {
1236
- spanId: event.span.id,
1237
- traceId: event.span.traceId,
1429
+ spanId: event.exportedSpan.id,
1430
+ traceId: event.exportedSpan.traceId,
1238
1431
  eventType: event.type
1239
1432
  });
1240
1433
  }
@@ -1242,7 +1435,7 @@ var DefaultExporter = class {
1242
1435
  * Adds an event to the appropriate buffer based on strategy
1243
1436
  */
1244
1437
  addToBuffer(event) {
1245
- const spanKey = this.buildSpanKey(event.span.traceId, event.span.id);
1438
+ const spanKey = this.buildSpanKey(event.exportedSpan.traceId, event.exportedSpan.id);
1246
1439
  if (this.buffer.totalSize === 0) {
1247
1440
  this.buffer.firstEventTime = /* @__PURE__ */ new Date();
1248
1441
  }
@@ -1250,9 +1443,9 @@ var DefaultExporter = class {
1250
1443
  case "span_started" /* SPAN_STARTED */:
1251
1444
  if (this.resolvedStrategy === "batch-with-updates") {
1252
1445
  const createRecord = {
1253
- traceId: event.span.traceId,
1254
- spanId: event.span.id,
1255
- ...this.buildCreateRecord(event.span),
1446
+ traceId: event.exportedSpan.traceId,
1447
+ spanId: event.exportedSpan.id,
1448
+ ...this.buildCreateRecord(event.exportedSpan),
1256
1449
  createdAt: /* @__PURE__ */ new Date(),
1257
1450
  updatedAt: null
1258
1451
  };
@@ -1264,10 +1457,10 @@ var DefaultExporter = class {
1264
1457
  if (this.resolvedStrategy === "batch-with-updates") {
1265
1458
  if (this.buffer.seenSpans.has(spanKey)) {
1266
1459
  this.buffer.updates.push({
1267
- traceId: event.span.traceId,
1268
- spanId: event.span.id,
1460
+ traceId: event.exportedSpan.traceId,
1461
+ spanId: event.exportedSpan.id,
1269
1462
  updates: {
1270
- ...this.buildUpdateRecord(event.span),
1463
+ ...this.buildUpdateRecord(event.exportedSpan),
1271
1464
  updatedAt: /* @__PURE__ */ new Date()
1272
1465
  },
1273
1466
  sequenceNumber: this.getNextSequence(spanKey)
@@ -1282,19 +1475,19 @@ var DefaultExporter = class {
1282
1475
  if (this.resolvedStrategy === "batch-with-updates") {
1283
1476
  if (this.buffer.seenSpans.has(spanKey)) {
1284
1477
  this.buffer.updates.push({
1285
- traceId: event.span.traceId,
1286
- spanId: event.span.id,
1478
+ traceId: event.exportedSpan.traceId,
1479
+ spanId: event.exportedSpan.id,
1287
1480
  updates: {
1288
- ...this.buildUpdateRecord(event.span),
1481
+ ...this.buildUpdateRecord(event.exportedSpan),
1289
1482
  updatedAt: /* @__PURE__ */ new Date()
1290
1483
  },
1291
1484
  sequenceNumber: this.getNextSequence(spanKey)
1292
1485
  });
1293
- } else if (event.span.isEvent) {
1486
+ } else if (event.exportedSpan.isEvent) {
1294
1487
  const createRecord = {
1295
- traceId: event.span.traceId,
1296
- spanId: event.span.id,
1297
- ...this.buildCreateRecord(event.span),
1488
+ traceId: event.exportedSpan.traceId,
1489
+ spanId: event.exportedSpan.id,
1490
+ ...this.buildCreateRecord(event.exportedSpan),
1298
1491
  createdAt: /* @__PURE__ */ new Date(),
1299
1492
  updatedAt: null
1300
1493
  };
@@ -1306,9 +1499,9 @@ var DefaultExporter = class {
1306
1499
  }
1307
1500
  } else if (this.resolvedStrategy === "insert-only") {
1308
1501
  const createRecord = {
1309
- traceId: event.span.traceId,
1310
- spanId: event.span.id,
1311
- ...this.buildCreateRecord(event.span),
1502
+ traceId: event.exportedSpan.traceId,
1503
+ spanId: event.exportedSpan.id,
1504
+ ...this.buildCreateRecord(event.exportedSpan),
1312
1505
  createdAt: /* @__PURE__ */ new Date(),
1313
1506
  updatedAt: null
1314
1507
  };
@@ -1395,7 +1588,7 @@ var DefaultExporter = class {
1395
1588
  }
1396
1589
  buildCreateRecord(span) {
1397
1590
  return {
1398
- parentSpanId: span.parent?.id ?? null,
1591
+ parentSpanId: span.parentSpanId ?? null,
1399
1592
  name: span.name,
1400
1593
  scope: null,
1401
1594
  spanType: span.type,
@@ -1427,7 +1620,7 @@ var DefaultExporter = class {
1427
1620
  * Handles realtime strategy - processes each event immediately
1428
1621
  */
1429
1622
  async handleRealtimeEvent(event, storage) {
1430
- const span = event.span;
1623
+ const span = event.exportedSpan;
1431
1624
  if (span.isEvent) {
1432
1625
  if (event.type === "span_ended" /* SPAN_ENDED */) {
1433
1626
  await storage.createAISpan({
@@ -1639,11 +1832,125 @@ var DefaultExporter = class {
1639
1832
  }
1640
1833
  };
1641
1834
 
1835
+ // src/ai-tracing/span_processors/sensitive-data-filter.ts
1836
+ var SensitiveDataFilter = class {
1837
+ name = "sensitive-data-filter";
1838
+ sensitiveFields;
1839
+ redactionToken;
1840
+ redactionStyle;
1841
+ constructor(options = {}) {
1842
+ this.sensitiveFields = (options.sensitiveFields || [
1843
+ "password",
1844
+ "token",
1845
+ "secret",
1846
+ "key",
1847
+ "apikey",
1848
+ "auth",
1849
+ "authorization",
1850
+ "bearer",
1851
+ "bearertoken",
1852
+ "jwt",
1853
+ "credential",
1854
+ "clientsecret",
1855
+ "privatekey",
1856
+ "refresh",
1857
+ "ssn"
1858
+ ]).map((f) => this.normalizeKey(f));
1859
+ this.redactionToken = options.redactionToken ?? "[REDACTED]";
1860
+ this.redactionStyle = options.redactionStyle ?? "full";
1861
+ }
1862
+ /**
1863
+ * Process a span by filtering sensitive data across its key fields.
1864
+ * Fields processed: attributes, metadata, input, output, errorInfo.
1865
+ *
1866
+ * @param span - The input span to filter
1867
+ * @returns A new span with sensitive values redacted
1868
+ */
1869
+ process(span) {
1870
+ span.attributes = this.tryFilter(span.attributes);
1871
+ span.metadata = this.tryFilter(span.metadata);
1872
+ span.input = this.tryFilter(span.input);
1873
+ span.output = this.tryFilter(span.output);
1874
+ span.errorInfo = this.tryFilter(span.errorInfo);
1875
+ return span;
1876
+ }
1877
+ /**
1878
+ * Recursively filter objects/arrays for sensitive keys.
1879
+ * Handles circular references by replacing with a marker.
1880
+ */
1881
+ deepFilter(obj, seen = /* @__PURE__ */ new WeakSet()) {
1882
+ if (obj === null || typeof obj !== "object") {
1883
+ return obj;
1884
+ }
1885
+ if (seen.has(obj)) {
1886
+ return "[Circular Reference]";
1887
+ }
1888
+ seen.add(obj);
1889
+ if (Array.isArray(obj)) {
1890
+ return obj.map((item) => this.deepFilter(item, seen));
1891
+ }
1892
+ const filtered = {};
1893
+ for (const key of Object.keys(obj)) {
1894
+ const normKey = this.normalizeKey(key);
1895
+ if (this.isSensitive(normKey)) {
1896
+ if (obj[key] && typeof obj[key] === "object") {
1897
+ filtered[key] = this.deepFilter(obj[key], seen);
1898
+ } else {
1899
+ filtered[key] = this.redactValue(obj[key]);
1900
+ }
1901
+ } else {
1902
+ filtered[key] = this.deepFilter(obj[key], seen);
1903
+ }
1904
+ }
1905
+ return filtered;
1906
+ }
1907
+ tryFilter(value) {
1908
+ try {
1909
+ return this.deepFilter(value);
1910
+ } catch {
1911
+ return { error: { processor: this.name } };
1912
+ }
1913
+ }
1914
+ /**
1915
+ * Normalize keys by lowercasing and stripping non-alphanumeric characters.
1916
+ * Ensures consistent matching for variants like "api-key", "api_key", "Api Key".
1917
+ */
1918
+ normalizeKey(key) {
1919
+ return key.toLowerCase().replace(/[^a-z0-9]/g, "");
1920
+ }
1921
+ /**
1922
+ * Check whether a normalized key matches any sensitive field substring.
1923
+ */
1924
+ isSensitive(normalizedKey) {
1925
+ return this.sensitiveFields.some((f) => normalizedKey.includes(f));
1926
+ }
1927
+ /**
1928
+ * Redact a sensitive value.
1929
+ * - Full style: replaces with a fixed token.
1930
+ * - Partial style: shows 3 chars at start and end, hides the middle.
1931
+ *
1932
+ * Non-string values are converted to strings before partial redaction.
1933
+ */
1934
+ redactValue(value) {
1935
+ if (this.redactionStyle === "full") {
1936
+ return this.redactionToken;
1937
+ }
1938
+ const str = String(value);
1939
+ const len = str.length;
1940
+ if (len <= 6) {
1941
+ return this.redactionToken;
1942
+ }
1943
+ return str.slice(0, 3) + "\u2026" + str.slice(len - 3);
1944
+ }
1945
+ async shutdown() {
1946
+ }
1947
+ };
1948
+
1642
1949
  // src/ai-tracing/registry.ts
1643
1950
  var AITracingRegistry = class {
1644
1951
  instances = /* @__PURE__ */ new Map();
1645
1952
  defaultInstance;
1646
- selector;
1953
+ configSelector;
1647
1954
  /**
1648
1955
  * Register a tracing instance
1649
1956
  */
@@ -1672,14 +1979,14 @@ var AITracingRegistry = class {
1672
1979
  * Set the tracing selector function
1673
1980
  */
1674
1981
  setSelector(selector) {
1675
- this.selector = selector;
1982
+ this.configSelector = selector;
1676
1983
  }
1677
1984
  /**
1678
1985
  * Get the selected tracing instance based on context
1679
1986
  */
1680
- getSelected(context) {
1681
- if (this.selector) {
1682
- const selected = this.selector(context, this.instances);
1987
+ getSelected(options) {
1988
+ if (this.configSelector) {
1989
+ const selected = this.configSelector(options, this.instances);
1683
1990
  if (selected && this.instances.has(selected)) {
1684
1991
  return this.instances.get(selected);
1685
1992
  }
@@ -1706,7 +2013,7 @@ var AITracingRegistry = class {
1706
2013
  clear() {
1707
2014
  this.instances.clear();
1708
2015
  this.defaultInstance = void 0;
1709
- this.selector = void 0;
2016
+ this.configSelector = void 0;
1710
2017
  }
1711
2018
  /**
1712
2019
  * Get all registered instances
@@ -1725,11 +2032,11 @@ function getAITracing(name) {
1725
2032
  function getDefaultAITracing() {
1726
2033
  return aiTracingRegistry.getDefault();
1727
2034
  }
1728
- function setAITracingSelector(selector) {
2035
+ function setSelector(selector) {
1729
2036
  aiTracingRegistry.setSelector(selector);
1730
2037
  }
1731
- function getSelectedAITracing(context) {
1732
- return aiTracingRegistry.getSelected(context);
2038
+ function getSelectedAITracing(options) {
2039
+ return aiTracingRegistry.getSelected(options);
1733
2040
  }
1734
2041
  function unregisterAITracing(name) {
1735
2042
  return aiTracingRegistry.unregister(name);
@@ -1751,7 +2058,7 @@ function hasAITracing(name) {
1751
2058
  return sampling.type !== "never" /* NEVER */;
1752
2059
  }
1753
2060
  function isAITracingInstance(obj) {
1754
- return obj instanceof MastraAITracing;
2061
+ return obj instanceof BaseAITracing;
1755
2062
  }
1756
2063
  function setupAITracing(config) {
1757
2064
  if (!config) {
@@ -1781,51 +2088,11 @@ function setupAITracing(config) {
1781
2088
  });
1782
2089
  }
1783
2090
  if (config.configSelector) {
1784
- setAITracingSelector(config.configSelector);
2091
+ setSelector(config.configSelector);
1785
2092
  }
1786
2093
  }
1787
2094
 
1788
2095
  // src/ai-tracing/utils.ts
1789
- var DEFAULT_KEYS_TO_STRIP = /* @__PURE__ */ new Set([
1790
- "logger",
1791
- "experimental_providerMetadata",
1792
- "providerMetadata",
1793
- "steps",
1794
- "tracingContext"
1795
- ]);
1796
- function deepClean(value, options = {}, _seen = /* @__PURE__ */ new WeakSet(), _depth = 0) {
1797
- const { keysToStrip = DEFAULT_KEYS_TO_STRIP, maxDepth = 10 } = options;
1798
- if (_depth > maxDepth) {
1799
- return "[MaxDepth]";
1800
- }
1801
- if (value === null || typeof value !== "object") {
1802
- try {
1803
- JSON.stringify(value);
1804
- return value;
1805
- } catch (error) {
1806
- return `[${error instanceof Error ? error.message : String(error)}]`;
1807
- }
1808
- }
1809
- if (_seen.has(value)) {
1810
- return "[Circular]";
1811
- }
1812
- _seen.add(value);
1813
- if (Array.isArray(value)) {
1814
- return value.map((item) => deepClean(item, options, _seen, _depth + 1));
1815
- }
1816
- const cleaned = {};
1817
- for (const [key, val] of Object.entries(value)) {
1818
- if (keysToStrip.has(key)) {
1819
- continue;
1820
- }
1821
- try {
1822
- cleaned[key] = deepClean(val, options, _seen, _depth + 1);
1823
- } catch (error) {
1824
- cleaned[key] = `[${error instanceof Error ? error.message : String(error)}]`;
1825
- }
1826
- }
1827
- return cleaned;
1828
- }
1829
2096
  function omitKeys(obj, keysToOmit) {
1830
2097
  return Object.fromEntries(Object.entries(obj).filter(([key]) => !keysToOmit.includes(key)));
1831
2098
  }
@@ -1861,6 +2128,9 @@ function setNestedValue(obj, path, value) {
1861
2128
  }, obj);
1862
2129
  target[lastKey] = value;
1863
2130
  }
2131
+ function getValidTraceId(span) {
2132
+ return span?.isValid ? span.traceId : void 0;
2133
+ }
1864
2134
  function getOrCreateSpan(options) {
1865
2135
  const { type, attributes, tracingContext, tracingOptions, runtimeContext, ...rest } = options;
1866
2136
  const metadata = {
@@ -1872,7 +2142,8 @@ function getOrCreateSpan(options) {
1872
2142
  type,
1873
2143
  attributes,
1874
2144
  ...rest,
1875
- metadata
2145
+ metadata,
2146
+ isInternal: tracingContext?.isInternal
1876
2147
  });
1877
2148
  }
1878
2149
  const aiTracing = getSelectedAITracing({
@@ -1881,244 +2152,14 @@ function getOrCreateSpan(options) {
1881
2152
  return aiTracing?.startSpan({
1882
2153
  type,
1883
2154
  attributes,
1884
- startOptions: {
1885
- runtimeContext
2155
+ customSamplerOptions: {
2156
+ runtimeContext,
2157
+ metadata
1886
2158
  },
1887
2159
  ...rest,
1888
2160
  metadata
1889
2161
  });
1890
2162
  }
1891
- function getValidTraceId(span) {
1892
- return span?.isValid ? span.traceId : void 0;
1893
- }
1894
-
1895
- // src/ai-tracing/default.ts
1896
- function generateSpanId() {
1897
- const bytes = new Uint8Array(8);
1898
- if (typeof crypto !== "undefined" && crypto.getRandomValues) {
1899
- crypto.getRandomValues(bytes);
1900
- } else {
1901
- for (let i = 0; i < 8; i++) {
1902
- bytes[i] = Math.floor(Math.random() * 256);
1903
- }
1904
- }
1905
- return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
1906
- }
1907
- function generateTraceId() {
1908
- const bytes = new Uint8Array(16);
1909
- if (typeof crypto !== "undefined" && crypto.getRandomValues) {
1910
- crypto.getRandomValues(bytes);
1911
- } else {
1912
- for (let i = 0; i < 16; i++) {
1913
- bytes[i] = Math.floor(Math.random() * 256);
1914
- }
1915
- }
1916
- return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
1917
- }
1918
- var DefaultAISpan = class {
1919
- id;
1920
- name;
1921
- type;
1922
- attributes;
1923
- parent;
1924
- traceId;
1925
- startTime;
1926
- endTime;
1927
- isEvent;
1928
- aiTracing;
1929
- input;
1930
- output;
1931
- errorInfo;
1932
- metadata;
1933
- constructor(options, aiTracing) {
1934
- this.id = generateSpanId();
1935
- this.name = options.name;
1936
- this.type = options.type;
1937
- this.attributes = deepClean(options.attributes) || {};
1938
- this.metadata = deepClean(options.metadata);
1939
- this.parent = options.parent;
1940
- this.startTime = /* @__PURE__ */ new Date();
1941
- this.aiTracing = aiTracing;
1942
- this.input = deepClean(options.input);
1943
- this.isEvent = options.isEvent;
1944
- if (!options.parent) {
1945
- this.traceId = generateTraceId();
1946
- } else {
1947
- this.traceId = options.parent.traceId;
1948
- }
1949
- if (this.isEvent) {
1950
- this.output = deepClean(options.output);
1951
- }
1952
- }
1953
- end(options) {
1954
- if (this.isEvent) {
1955
- return;
1956
- }
1957
- this.endTime = /* @__PURE__ */ new Date();
1958
- if (options?.output !== void 0) {
1959
- this.output = deepClean(options.output);
1960
- }
1961
- if (options?.attributes) {
1962
- this.attributes = { ...this.attributes, ...deepClean(options.attributes) };
1963
- }
1964
- if (options?.metadata) {
1965
- this.metadata = { ...this.metadata, ...deepClean(options.metadata) };
1966
- }
1967
- }
1968
- error(options) {
1969
- if (this.isEvent) {
1970
- return;
1971
- }
1972
- const { error, endSpan = true, attributes, metadata } = options;
1973
- this.errorInfo = error instanceof MastraError ? {
1974
- id: error.id,
1975
- details: error.details,
1976
- category: error.category,
1977
- domain: error.domain,
1978
- message: error.message
1979
- } : {
1980
- message: error.message
1981
- };
1982
- if (attributes) {
1983
- this.attributes = { ...this.attributes, ...deepClean(attributes) };
1984
- }
1985
- if (metadata) {
1986
- this.metadata = { ...this.metadata, ...deepClean(metadata) };
1987
- }
1988
- if (endSpan) {
1989
- this.end();
1990
- } else {
1991
- this.update({});
1992
- }
1993
- }
1994
- createChildSpan(options) {
1995
- return this.aiTracing.startSpan({
1996
- ...options,
1997
- parent: this,
1998
- isEvent: false
1999
- });
2000
- }
2001
- createEventSpan(options) {
2002
- return this.aiTracing.startSpan({
2003
- ...options,
2004
- parent: this,
2005
- isEvent: true
2006
- });
2007
- }
2008
- update(options) {
2009
- if (this.isEvent) {
2010
- return;
2011
- }
2012
- if (options?.input !== void 0) {
2013
- this.input = deepClean(options.input);
2014
- }
2015
- if (options?.output !== void 0) {
2016
- this.output = deepClean(options.output);
2017
- }
2018
- if (options?.attributes) {
2019
- this.attributes = { ...this.attributes, ...deepClean(options.attributes) };
2020
- }
2021
- if (options?.metadata) {
2022
- this.metadata = { ...this.metadata, ...deepClean(options.metadata) };
2023
- }
2024
- }
2025
- get isRootSpan() {
2026
- return !this.parent;
2027
- }
2028
- get isValid() {
2029
- return true;
2030
- }
2031
- async export() {
2032
- return JSON.stringify({
2033
- id: this.id,
2034
- attributes: this.attributes,
2035
- metadata: this.metadata,
2036
- startTime: this.startTime,
2037
- endTime: this.endTime,
2038
- traceId: this.traceId
2039
- // OpenTelemetry trace ID
2040
- });
2041
- }
2042
- };
2043
- var SensitiveDataFilter = class {
2044
- name = "sensitive-data-filter";
2045
- sensitiveFields;
2046
- constructor(sensitiveFields) {
2047
- this.sensitiveFields = (sensitiveFields || [
2048
- "password",
2049
- "token",
2050
- "secret",
2051
- "key",
2052
- "apiKey",
2053
- "auth",
2054
- "authorization",
2055
- "bearer",
2056
- "jwt",
2057
- "credential",
2058
- "sessionId"
2059
- ]).map((field) => field.toLowerCase());
2060
- }
2061
- process(span) {
2062
- const deepFilter = (obj, seen = /* @__PURE__ */ new WeakSet()) => {
2063
- if (obj === null || typeof obj !== "object") {
2064
- return obj;
2065
- }
2066
- if (seen.has(obj)) {
2067
- return "[Circular Reference]";
2068
- }
2069
- seen.add(obj);
2070
- if (Array.isArray(obj)) {
2071
- return obj.map((item) => deepFilter(item, seen));
2072
- }
2073
- const filtered = {};
2074
- Object.keys(obj).forEach((key) => {
2075
- if (this.sensitiveFields.includes(key.toLowerCase())) {
2076
- if (obj[key] && typeof obj[key] === "object") {
2077
- filtered[key] = deepFilter(obj[key], seen);
2078
- } else {
2079
- filtered[key] = "[REDACTED]";
2080
- }
2081
- } else {
2082
- filtered[key] = deepFilter(obj[key], seen);
2083
- }
2084
- });
2085
- return filtered;
2086
- };
2087
- try {
2088
- const filteredSpan = { ...span };
2089
- filteredSpan.attributes = deepFilter(span.attributes);
2090
- filteredSpan.metadata = deepFilter(span.metadata);
2091
- filteredSpan.input = deepFilter(span.input);
2092
- filteredSpan.output = deepFilter(span.output);
2093
- filteredSpan.errorInfo = deepFilter(span.errorInfo);
2094
- return filteredSpan;
2095
- } catch (error) {
2096
- const safeSpan = { ...span };
2097
- safeSpan.attributes = {
2098
- "[FILTERING_ERROR]": "Attributes were completely redacted due to filtering error",
2099
- "[ERROR_MESSAGE]": error instanceof Error ? error.message : "Unknown filtering error"
2100
- };
2101
- return safeSpan;
2102
- }
2103
- }
2104
- async shutdown() {
2105
- }
2106
- };
2107
- var DefaultAITracing = class extends MastraAITracing {
2108
- constructor(config) {
2109
- const configWithDefaults = {
2110
- ...config,
2111
- exporters: config.exporters?.length ? config.exporters : [new ConsoleExporter()]
2112
- };
2113
- super(configWithDefaults);
2114
- }
2115
- // ============================================================================
2116
- // Abstract Method Implementations
2117
- // ============================================================================
2118
- createSpan(options) {
2119
- return new DefaultAISpan(options, this);
2120
- }
2121
- };
2122
2163
 
2123
2164
  // src/ai-tracing/context.ts
2124
2165
  var AGENT_GETTERS = ["getAgent", "getAgentById"];
@@ -2267,6 +2308,6 @@ function wrapRun(run, tracingContext) {
2267
2308
  }
2268
2309
  }
2269
2310
 
2270
- export { AISpanType, AITracingEventType, CloudExporter, ConsoleExporter, DefaultAITracing, DefaultExporter, MastraAITracing, SamplingStrategyType, SensitiveDataFilter, checkEvalStorageFields, clearAITracingRegistry, createMastraProxy, deepClean, deepMerge, delay, ensureToolProperties, fetchWithRetry, generateEmptyFromSchema, getAITracing, getAllAITracing, getDefaultAITracing, getOrCreateSpan, getSelectedAITracing, getValidTraceId, hasAITracing, isCoreMessage, isMastra, isUiMessage, isZodType, makeCoreTool, makeCoreToolV5, maskStreamTags, omitKeys, parseFieldKey, parseSqlIdentifier, registerAITracing, resolveSerializedZodOutput, selectFields, setAITracingSelector, setupAITracing, shutdownAITracingRegistry, unregisterAITracing, wrapMastra };
2271
- //# sourceMappingURL=chunk-W5K2KOZX.js.map
2272
- //# sourceMappingURL=chunk-W5K2KOZX.js.map
2311
+ export { AISpanType, AITracingEventType, BaseAISpan, BaseAITracing, CloudExporter, ConsoleExporter, DefaultAISpan, DefaultAITracing, DefaultExporter, NoOpAISpan, SamplingStrategyType, SensitiveDataFilter, checkEvalStorageFields, clearAITracingRegistry, createMastraProxy, deepClean, deepMerge, delay, ensureToolProperties, fetchWithRetry, generateEmptyFromSchema, getAITracing, getAllAITracing, getDefaultAITracing, getOrCreateSpan, getSelectedAITracing, getValidTraceId, hasAITracing, isCoreMessage, isMastra, isUiMessage, isZodType, makeCoreTool, makeCoreToolV5, maskStreamTags, omitKeys, parseFieldKey, parseSqlIdentifier, registerAITracing, resolveSerializedZodOutput, selectFields, setSelector, setupAITracing, shutdownAITracingRegistry, unregisterAITracing, wrapMastra };
2312
+ //# sourceMappingURL=chunk-ODLGLX2R.js.map
2313
+ //# sourceMappingURL=chunk-ODLGLX2R.js.map