@mastra/observability 1.24.0 → 1.24.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,6 +19,8 @@ import type { AnyExportedSpan, EntityType, ExportedLog, LogLevel } from '@mastra
19
19
  * it through the bus.
20
20
  */
21
21
  export interface DecodedOtlpSpan {
22
+ /** Preserve reversed sub-millisecond timestamps before Date truncation. */
23
+ hasReversedTimestamps?: boolean;
22
24
  traceId: string;
23
25
  spanId: string;
24
26
  parentSpanId?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"otlp.d.ts","sourceRoot":"","sources":["../../src/client/otlp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAoDrG;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,8CAA8C;IAC9C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gCAAgC;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CA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3
  description: Documentation for @mastra/observability. Use when working with @mastra/observability APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/observability"
6
- version: "1.24.0"
6
+ version: "1.24.1-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,11 +1,11 @@
1
1
  {
2
- "version": "1.24.0",
2
+ "version": "1.24.1-alpha.0",
3
3
  "package": "@mastra/observability",
4
4
  "exports": {
5
5
  "BaseExporter": {
6
6
  "types": "dist/exporters/base.d.ts",
7
7
  "implementation": "dist/index.js",
8
- "line": 4314
8
+ "line": 4315
9
9
  },
10
10
  "BaseObservabilityEventBus": {
11
11
  "types": "dist/bus/base.d.ts",
@@ -15,7 +15,7 @@
15
15
  "BaseObservabilityInstance": {
16
16
  "types": "dist/instances/base.d.ts",
17
17
  "implementation": "dist/index.js",
18
- "line": 6252
18
+ "line": 6253
19
19
  },
20
20
  "BaseSpan": {
21
21
  "types": "dist/spans/base.d.ts",
@@ -30,12 +30,12 @@
30
30
  "CloudExporter": {
31
31
  "types": "dist/exporters/cloud.d.ts",
32
32
  "implementation": "dist/index.js",
33
- "line": 8675
33
+ "line": 8693
34
34
  },
35
35
  "ConsoleExporter": {
36
36
  "types": "dist/exporters/console.d.ts",
37
37
  "implementation": "dist/index.js",
38
- "line": 8998
38
+ "line": 9016
39
39
  },
40
40
  "DEFAULT_DEEP_CLEAN_OPTIONS": {
41
41
  "types": "dist/spans/serialization.d.ts",
@@ -45,17 +45,17 @@
45
45
  "DEFAULT_LIMITS": {
46
46
  "types": "dist/client/proxy.d.ts",
47
47
  "implementation": "dist/index.js",
48
- "line": 7241
48
+ "line": 7251
49
49
  },
50
50
  "DefaultExporter": {
51
51
  "types": "dist/exporters/default.d.ts",
52
52
  "implementation": "dist/index.js",
53
- "line": 5074
53
+ "line": 5075
54
54
  },
55
55
  "DefaultObservabilityInstance": {
56
56
  "types": "dist/instances/default.d.ts",
57
57
  "implementation": "dist/index.js",
58
- "line": 10926
58
+ "line": 10944
59
59
  },
60
60
  "DefaultSpan": {
61
61
  "types": "dist/spans/default.d.ts",
@@ -65,7 +65,7 @@
65
65
  "JsonExporter": {
66
66
  "types": "dist/exporters/test.d.ts",
67
67
  "implementation": "dist/index.js",
68
- "line": 10924
68
+ "line": 10942
69
69
  },
70
70
  "LoggerContextImpl": {
71
71
  "types": "dist/context/logger.d.ts",
@@ -75,12 +75,12 @@
75
75
  "MastraPlatformExporter": {
76
76
  "types": "dist/exporters/mastra-platform.d.ts",
77
77
  "implementation": "dist/index.js",
78
- "line": 9328
78
+ "line": 9346
79
79
  },
80
80
  "MastraStorageExporter": {
81
81
  "types": "dist/exporters/mastra-storage.d.ts",
82
82
  "implementation": "dist/index.js",
83
- "line": 5635
83
+ "line": 5636
84
84
  },
85
85
  "MetricsContextImpl": {
86
86
  "types": "dist/context/metrics.d.ts",
@@ -95,17 +95,17 @@
95
95
  "NoOpSpan": {
96
96
  "types": "dist/spans/no-op.d.ts",
97
97
  "implementation": "dist/index.js",
98
- "line": 4257
98
+ "line": 4258
99
99
  },
100
100
  "OBSERVABILITY_CAPABILITIES_HEADER": {
101
101
  "types": "dist/exporters/mastra-platform.d.ts",
102
102
  "implementation": "dist/index.js",
103
- "line": 9229
103
+ "line": 9247
104
104
  },
105
105
  "Observability": {
106
106
  "types": "dist/default.d.ts",
107
107
  "implementation": "dist/index.js",
108
- "line": 11262
108
+ "line": 11280
109
109
  },
110
110
  "ObservabilityBus": {
111
111
  "types": "dist/bus/observability-bus.d.ts",
@@ -115,7 +115,7 @@
115
115
  "QUOTA_PAUSE_CAPABILITY": {
116
116
  "types": "dist/exporters/mastra-platform.d.ts",
117
117
  "implementation": "dist/index.js",
118
- "line": 9230
118
+ "line": 9248
119
119
  },
120
120
  "REDACTED_ERROR_MESSAGE": {
121
121
  "types": "dist/spans/base.d.ts",
@@ -130,57 +130,57 @@
130
130
  "SensitiveDataFilter": {
131
131
  "types": "dist/span_processors/sensitive-data-filter.d.ts",
132
132
  "implementation": "dist/index.js",
133
- "line": 11049
133
+ "line": 11067
134
134
  },
135
135
  "TestExporter": {
136
136
  "types": "dist/exporters/test.d.ts",
137
137
  "implementation": "dist/index.js",
138
- "line": 9939
138
+ "line": 9957
139
139
  },
140
140
  "TraceData": {
141
141
  "types": "dist/exporters/tracking.d.ts",
142
142
  "implementation": "dist/index.js",
143
- "line": 7394
143
+ "line": 7412
144
144
  },
145
145
  "TrackingExporter": {
146
146
  "types": "dist/exporters/tracking.d.ts",
147
147
  "implementation": "dist/index.js",
148
- "line": 7723
148
+ "line": 7741
149
149
  },
150
150
  "buildExportedLog": {
151
151
  "types": "dist/client/otlp.d.ts",
152
152
  "implementation": "dist/index.js",
153
- "line": 7158
153
+ "line": 7168
154
154
  },
155
155
  "buildExportedSpan": {
156
156
  "types": "dist/client/otlp.d.ts",
157
157
  "implementation": "dist/index.js",
158
- "line": 7140
158
+ "line": 7150
159
159
  },
160
160
  "buildTracingOptions": {
161
161
  "types": "dist/tracing-options.d.ts",
162
162
  "implementation": "dist/index.js",
163
- "line": 11603
163
+ "line": 11621
164
164
  },
165
165
  "chainFormatters": {
166
166
  "types": "dist/exporters/span-formatters.d.ts",
167
167
  "implementation": "dist/index.js",
168
- "line": 8489
168
+ "line": 8507
169
169
  },
170
170
  "createClientObservabilityProxy": {
171
171
  "types": "dist/client/proxy.d.ts",
172
172
  "implementation": "dist/index.js",
173
- "line": 7375
173
+ "line": 7393
174
174
  },
175
175
  "decodeResourceLogs": {
176
176
  "types": "dist/client/otlp.d.ts",
177
177
  "implementation": "dist/index.js",
178
- "line": 7077
178
+ "line": 7087
179
179
  },
180
180
  "decodeResourceSpans": {
181
181
  "types": "dist/client/otlp.d.ts",
182
182
  "implementation": "dist/index.js",
183
- "line": 7040
183
+ "line": 7049
184
184
  },
185
185
  "deepClean": {
186
186
  "types": "dist/spans/serialization.d.ts",
@@ -190,12 +190,12 @@
190
190
  "formatBaggage": {
191
191
  "types": "dist/client/w3c.d.ts",
192
192
  "implementation": "dist/index.js",
193
- "line": 7231
193
+ "line": 7241
194
194
  },
195
195
  "formatTraceparent": {
196
196
  "types": "dist/client/w3c.d.ts",
197
197
  "implementation": "dist/index.js",
198
- "line": 7194
198
+ "line": 7204
199
199
  },
200
200
  "getExternalParentId": {
201
201
  "types": "dist/spans/base.d.ts",
@@ -220,7 +220,7 @@
220
220
  "observabilityFeatures": {
221
221
  "types": "dist/features.d.ts",
222
222
  "implementation": "dist/index.js",
223
- "line": 11584
223
+ "line": 11602
224
224
  },
225
225
  "observabilityInstanceConfigSchema": {
226
226
  "types": "dist/config.d.ts",
@@ -235,17 +235,17 @@
235
235
  "otlpSeverityToLogLevel": {
236
236
  "types": "dist/client/otlp.d.ts",
237
237
  "implementation": "dist/index.js",
238
- "line": 7114
238
+ "line": 7124
239
239
  },
240
240
  "parseBaggage": {
241
241
  "types": "dist/client/w3c.d.ts",
242
242
  "implementation": "dist/index.js",
243
- "line": 7204
243
+ "line": 7214
244
244
  },
245
245
  "parseTraceparent": {
246
246
  "types": "dist/client/w3c.d.ts",
247
247
  "implementation": "dist/index.js",
248
- "line": 7180
248
+ "line": 7190
249
249
  },
250
250
  "reconstructSerializedMap": {
251
251
  "types": "dist/spans/serialization.d.ts",
package/dist/index.cjs CHANGED
@@ -4151,7 +4151,8 @@ var DefaultSpan = class extends BaseSpan {
4151
4151
  if (options) this.applyOutcome(options);
4152
4152
  if (this.outcome === null) this.outcome = "unknown";
4153
4153
  const endTime = options?.endTime;
4154
- this.endTime = endTime instanceof Date && endTime >= this.startTime ? endTime : /* @__PURE__ */ new Date();
4154
+ const candidate = endTime instanceof Date ? endTime : /* @__PURE__ */ new Date();
4155
+ this.endTime = candidate < this.startTime ? this.startTime : candidate;
4155
4156
  this.detachFromParent();
4156
4157
  if (options?.metadata) this.metadata = {
4157
4158
  ...this.metadata,
@@ -7018,6 +7019,14 @@ function generateClientSignalId() {
7018
7019
  * Using `@opentelemetry/otlp-transformer` would pull in the full proto
7019
7020
  * dependency tree (~hundreds of KB) for what amounts to a 100-line walker.
7020
7021
  */
7022
+ function hasReversedTimestamps(start, end) {
7023
+ if (typeof start !== "string" && typeof start !== "number" || typeof end !== "string" && typeof end !== "number") return false;
7024
+ try {
7025
+ return BigInt(end) < BigInt(start);
7026
+ } catch {
7027
+ return false;
7028
+ }
7029
+ }
7021
7030
  /**
7022
7031
  * Convert an OTLP nanosecond timestamp (string or number) to a JS Date.
7023
7032
  *
@@ -7026,7 +7035,7 @@ function generateClientSignalId() {
7026
7035
  * uint64 to avoid JS number precision loss) or numbers.
7027
7036
  */
7028
7037
  function nanosToDate(value) {
7029
- if (typeof value === "number") return new Date(Math.round(value / 1e6));
7038
+ if (typeof value === "number") return new Date(Math.trunc(value / 1e6));
7030
7039
  if (typeof value === "string") {
7031
7040
  if (value.length <= 6) return /* @__PURE__ */ new Date(0);
7032
7041
  const ms = Number(value.slice(0, -6));
@@ -7084,6 +7093,7 @@ function decodeResourceSpans(payload) {
7084
7093
  spanId,
7085
7094
  parentSpanId: typeof s.parentSpanId === "string" && s.parentSpanId ? s.parentSpanId : void 0,
7086
7095
  name,
7096
+ ...hasReversedTimestamps(s.startTimeUnixNano, s.endTimeUnixNano) ? { hasReversedTimestamps: true } : {},
7087
7097
  startTime: nanosToDate(s.startTimeUnixNano),
7088
7098
  endTime: s.endTimeUnixNano !== void 0 ? nanosToDate(s.endTimeUnixNano) : void 0,
7089
7099
  attributes: flattenAttributes(s.attributes)
@@ -7330,6 +7340,14 @@ var ClientObservabilityProxyImpl = class {
7330
7340
  this.#warn("Client observability payload contains spans with orphan parents; dropping.");
7331
7341
  return;
7332
7342
  }
7343
+ if (decodedSpans.some((span) => span.hasReversedTimestamps || span.endTime && span.endTime < span.startTime)) {
7344
+ this.#warn("Client observability payload contains a span whose end precedes its start; dropping.");
7345
+ return;
7346
+ }
7347
+ if (typeof payload.executionDurationMs === "number" && payload.executionDurationMs < 0) {
7348
+ this.#warn("Client observability payload contains a negative execution duration; dropping.");
7349
+ return;
7350
+ }
7333
7351
  for (const decoded of decodedSpans) {
7334
7352
  const exported = buildExportedSpan(decoded);
7335
7353
  const startedEvent = {