@mastra/observability 1.24.0-alpha.5 → 1.24.0-alpha.7
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/bus/observability-bus.d.ts.map +1 -1
- package/dist/bus/route-event.d.ts.map +1 -1
- package/dist/default.d.ts +3 -2
- package/dist/default.d.ts.map +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +63 -53
- package/dist/docs/references/reference-observability-feedback.md +14 -0
- package/dist/docs/references/reference-observability-tracing-exporters-langfuse.md +24 -1
- package/dist/exporters/default.d.ts +3 -1
- package/dist/exporters/default.d.ts.map +1 -1
- package/dist/exporters/event-buffer.d.ts +1 -1
- package/dist/exporters/event-buffer.d.ts.map +1 -1
- package/dist/exporters/keyed-queue.d.ts +6 -0
- package/dist/exporters/keyed-queue.d.ts.map +1 -0
- package/dist/exporters/mastra-platform.d.ts +4 -1
- package/dist/exporters/mastra-platform.d.ts.map +1 -1
- package/dist/exporters/mastra-storage.d.ts +3 -1
- package/dist/exporters/mastra-storage.d.ts.map +1 -1
- package/dist/exporters/platform-resolved-record.d.ts +1 -1
- package/dist/exporters/platform-resolved-record.d.ts.map +1 -1
- package/dist/exporters/storage-annotation.d.ts +4 -1
- package/dist/exporters/storage-annotation.d.ts.map +1 -1
- package/dist/index.cjs +146 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +145 -8
- package/dist/index.js.map +1 -1
- package/dist/instances/base.d.ts.map +1 -1
- package/dist/spans/base.d.ts +16 -0
- package/dist/spans/base.d.ts.map +1 -1
- package/dist/spans/default.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -77,6 +77,9 @@ function routeToHandler(handler, event, logger) {
|
|
|
77
77
|
}), handler.name, "score", logger);
|
|
78
78
|
}
|
|
79
79
|
break;
|
|
80
|
+
case "feedback_review_status":
|
|
81
|
+
if (handler.onFeedbackReviewStatusEvent) return catchAsyncResult(handler.onFeedbackReviewStatusEvent(event), handler.name, "feedback review status", logger);
|
|
82
|
+
break;
|
|
80
83
|
case "feedback_replacement":
|
|
81
84
|
if (handler.onFeedbackReplacementEvent) return catchAsyncResult(handler.onFeedbackReplacementEvent(event), handler.name, "feedback replacement", logger);
|
|
82
85
|
break;
|
|
@@ -580,6 +583,10 @@ function cleanEvent(event, options) {
|
|
|
580
583
|
type: "score",
|
|
581
584
|
score: deepClean(event.score, options)
|
|
582
585
|
};
|
|
586
|
+
case "feedback_review_status": return {
|
|
587
|
+
type: event.type,
|
|
588
|
+
feedback: deepClean(event.feedback, options)
|
|
589
|
+
};
|
|
583
590
|
case "feedback_replacement": return {
|
|
584
591
|
type: event.type,
|
|
585
592
|
feedback: deepClean(event.feedback, options)
|
|
@@ -3451,6 +3458,34 @@ function mergeMetadata$1(parentMetadata, metadata) {
|
|
|
3451
3458
|
}
|
|
3452
3459
|
}
|
|
3453
3460
|
// src/spans/base.ts
|
|
3461
|
+
/** Replaces error text exported from traces that hide input or output. */
|
|
3462
|
+
const REDACTED_ERROR_MESSAGE = "[REDACTED]";
|
|
3463
|
+
/**
|
|
3464
|
+
* The error as exported from a trace that hides input or output: keeps what
|
|
3465
|
+
* identifies the error (id, name, domain, category, stack frames) and drops
|
|
3466
|
+
* text and free-form details, which can quote the hidden data.
|
|
3467
|
+
*/
|
|
3468
|
+
function redactErrorInfo(errorInfo, stackMessage) {
|
|
3469
|
+
if (!errorInfo) return errorInfo;
|
|
3470
|
+
const { id, name, domain, category, stack } = errorInfo;
|
|
3471
|
+
return {
|
|
3472
|
+
...id !== void 0 ? { id } : {},
|
|
3473
|
+
...name !== void 0 ? { name } : {},
|
|
3474
|
+
...domain !== void 0 ? { domain } : {},
|
|
3475
|
+
...category !== void 0 ? { category } : {},
|
|
3476
|
+
message: REDACTED_ERROR_MESSAGE,
|
|
3477
|
+
...stack !== void 0 ? { stack: redactStackHeader(stack, stackMessage ?? errorInfo.message, errorInfo.name) } : {}
|
|
3478
|
+
};
|
|
3479
|
+
}
|
|
3480
|
+
/** Preserve stack frames only when they follow the complete captured message. */
|
|
3481
|
+
function redactStackHeader(stack, message, name = "Error") {
|
|
3482
|
+
const redactedHeader = `${name}: ${REDACTED_ERROR_MESSAGE}`;
|
|
3483
|
+
const separator = `: ${message}`;
|
|
3484
|
+
const separatorIndex = stack.indexOf(separator);
|
|
3485
|
+
if (separatorIndex <= 0 || stack.slice(0, separatorIndex).includes("\n")) return redactedHeader;
|
|
3486
|
+
const suffix = stack.slice(separatorIndex + separator.length);
|
|
3487
|
+
return suffix === "" || suffix.startsWith("\n") ? `${redactedHeader}${suffix}` : redactedHeader;
|
|
3488
|
+
}
|
|
3454
3489
|
const LINEAGE_KEYS = [
|
|
3455
3490
|
"parentEntityType",
|
|
3456
3491
|
"parentEntityId",
|
|
@@ -3580,11 +3615,29 @@ var BaseSpan = class BaseSpan {
|
|
|
3580
3615
|
stopReason;
|
|
3581
3616
|
stopReasonContext;
|
|
3582
3617
|
errorInfo;
|
|
3618
|
+
errorStackMessage;
|
|
3583
3619
|
metadata;
|
|
3584
3620
|
requestContext;
|
|
3585
3621
|
tags;
|
|
3586
3622
|
links;
|
|
3587
3623
|
traceState;
|
|
3624
|
+
localErrorCount = typeof _mastra_core_observability.claimSpanError === "function" ? 0 : void 0;
|
|
3625
|
+
errorOccurrenceIds;
|
|
3626
|
+
recordError(error, options) {
|
|
3627
|
+
if (this.isEvent || this.endTime) return;
|
|
3628
|
+
if (error === null || typeof error !== "object" && typeof error !== "function") {
|
|
3629
|
+
this.localErrorCount = void 0;
|
|
3630
|
+
return;
|
|
3631
|
+
}
|
|
3632
|
+
const id = _mastra_core_observability.claimSpanError?.(error, this.traceId, this.id, options);
|
|
3633
|
+
if (this.isExcluded || id === void 0 || this.errorOccurrenceIds?.has(id)) return;
|
|
3634
|
+
(this.errorOccurrenceIds ??= /* @__PURE__ */ new Set()).add(id);
|
|
3635
|
+
if (this.localErrorCount !== void 0) this.localErrorCount++;
|
|
3636
|
+
}
|
|
3637
|
+
restoreErrorCount(cached) {
|
|
3638
|
+
this.localErrorCount = typeof _mastra_core_observability.claimSpanError !== "function" || cached.errorCount && !cached.errorOccurrenceIds ? void 0 : cached.errorCount;
|
|
3639
|
+
this.errorOccurrenceIds = cached.errorOccurrenceIds?.length ? new Set(cached.errorOccurrenceIds) : void 0;
|
|
3640
|
+
}
|
|
3588
3641
|
/** Entity type that created the span (e.g., agent, workflow) */
|
|
3589
3642
|
entityType;
|
|
3590
3643
|
/** Entity ID that created the span */
|
|
@@ -3967,7 +4020,8 @@ var BaseSpan = class BaseSpan {
|
|
|
3967
4020
|
endTime: this.endTime,
|
|
3968
4021
|
input: hideInput ? void 0 : this.input,
|
|
3969
4022
|
output: hideOutput ? void 0 : this.output,
|
|
3970
|
-
errorInfo: this.errorInfo,
|
|
4023
|
+
errorInfo: hideInput || hideOutput ? redactErrorInfo(this.errorInfo, this.errorStackMessage) : this.errorInfo,
|
|
4024
|
+
...this.localErrorCount !== void 0 ? { errorCount: this.localErrorCount } : {},
|
|
3971
4025
|
...this.outcome !== void 0 ? { outcome: this.outcome } : {},
|
|
3972
4026
|
...this.stopReason !== void 0 ? { stopReason: this.stopReason } : {},
|
|
3973
4027
|
...this.stopReasonContext !== void 0 ? { stopReasonContext: this.stopReasonContext } : {},
|
|
@@ -3993,6 +4047,7 @@ var BaseSpan = class BaseSpan {
|
|
|
3993
4047
|
return {
|
|
3994
4048
|
...this.exportSpan(this.observabilityInstance.getConfig().includeInternalSpans),
|
|
3995
4049
|
ownEntityVersionId: this.ownEntityVersionId ?? null,
|
|
4050
|
+
...this.errorOccurrenceIds ? { errorOccurrenceIds: [...this.errorOccurrenceIds] } : {},
|
|
3996
4051
|
...this.traceState ? { traceState: this.traceState } : {}
|
|
3997
4052
|
};
|
|
3998
4053
|
}
|
|
@@ -4112,6 +4167,7 @@ var DefaultSpan = class extends BaseSpan {
|
|
|
4112
4167
|
error(options) {
|
|
4113
4168
|
if (this.isEvent || this.endTime) return;
|
|
4114
4169
|
const { error, endSpan = true, endTree, attributes, metadata } = options;
|
|
4170
|
+
this.recordError(error, { origin: options.origin });
|
|
4115
4171
|
this.applyOutcome(options);
|
|
4116
4172
|
if (metadata) this.metadata = {
|
|
4117
4173
|
...this.metadata,
|
|
@@ -4119,6 +4175,8 @@ var DefaultSpan = class extends BaseSpan {
|
|
|
4119
4175
|
};
|
|
4120
4176
|
if (!this.isExcluded) {
|
|
4121
4177
|
const apiDetails = apiCallErrorDetails(error);
|
|
4178
|
+
const stackError = error instanceof _mastra_core_error.MastraError && error.cause instanceof Error && error.cause.stack ? error.cause : error;
|
|
4179
|
+
this.errorStackMessage = stackError.message;
|
|
4122
4180
|
this.errorInfo = deepClean(error instanceof _mastra_core_error.MastraError ? {
|
|
4123
4181
|
id: error.id,
|
|
4124
4182
|
details: apiDetails ? {
|
|
@@ -4129,7 +4187,7 @@ var DefaultSpan = class extends BaseSpan {
|
|
|
4129
4187
|
domain: error.domain,
|
|
4130
4188
|
message: error.message,
|
|
4131
4189
|
name: error.name,
|
|
4132
|
-
stack:
|
|
4190
|
+
stack: stackError.stack
|
|
4133
4191
|
} : {
|
|
4134
4192
|
message: error.message,
|
|
4135
4193
|
name: error.name,
|
|
@@ -4631,6 +4689,20 @@ var EventBuffer = class {
|
|
|
4631
4689
|
});
|
|
4632
4690
|
}
|
|
4633
4691
|
};
|
|
4692
|
+
// src/exporters/keyed-queue.ts
|
|
4693
|
+
/** Keep writes to one record ordered without blocking unrelated records. */
|
|
4694
|
+
var KeyedQueue = class {
|
|
4695
|
+
pending = /* @__PURE__ */ new Map();
|
|
4696
|
+
enqueue(key, write) {
|
|
4697
|
+
const current = (this.pending.get(key) ?? Promise.resolve()).catch(() => {}).then(write);
|
|
4698
|
+
this.pending.set(key, current);
|
|
4699
|
+
const cleanup = () => {
|
|
4700
|
+
if (this.pending.get(key) === current) this.pending.delete(key);
|
|
4701
|
+
};
|
|
4702
|
+
current.then(cleanup, cleanup);
|
|
4703
|
+
return current;
|
|
4704
|
+
}
|
|
4705
|
+
};
|
|
4634
4706
|
// src/recorded.ts
|
|
4635
4707
|
function nullToUndefined(value) {
|
|
4636
4708
|
return value ?? void 0;
|
|
@@ -4957,6 +5029,16 @@ const LOOKUP_DELAYS_MS = [
|
|
|
4957
5029
|
2e3,
|
|
4958
5030
|
2e3
|
|
4959
5031
|
];
|
|
5032
|
+
/** Older stores may inherit a method that throws instead of omitting the hook. */
|
|
5033
|
+
async function updateStorageFeedbackReviewStatus(storage, feedback, logger) {
|
|
5034
|
+
if (typeof storage.updateFeedbackReviewStatus === "function") try {
|
|
5035
|
+
await storage.updateFeedbackReviewStatus(feedback);
|
|
5036
|
+
return;
|
|
5037
|
+
} catch (error) {
|
|
5038
|
+
if (typeof error !== "object" || error === null || !("id" in error) || error.id !== "OBSERVABILITY_STORAGE_UPDATE_FEEDBACK_REVIEW_STATUS_NOT_IMPLEMENTED") throw error;
|
|
5039
|
+
}
|
|
5040
|
+
logger.warn("Storage exporter skipped feedback review update: upgrade the storage adapter and @mastra/core");
|
|
5041
|
+
}
|
|
4960
5042
|
/**
|
|
4961
5043
|
* Resolve attached-storage context within a bounded retry window, including failed reads.
|
|
4962
5044
|
* Exhaustion returns null for missing anchors or throws the last read error for the exporter to report.
|
|
@@ -5027,6 +5109,7 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
5027
5109
|
/** Storage writes (timer, size trigger, or flush()) that haven't finished yet */
|
|
5028
5110
|
#inFlightFlushes = /* @__PURE__ */ new Set();
|
|
5029
5111
|
#pendingAnnotations = /* @__PURE__ */ new Set();
|
|
5112
|
+
#feedbackWrites = new KeyedQueue();
|
|
5030
5113
|
#emitDropEvent;
|
|
5031
5114
|
#unsupportedSignals = /* @__PURE__ */ new Set();
|
|
5032
5115
|
constructor(config = {}) {
|
|
@@ -5382,6 +5465,9 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
5382
5465
|
onScoreEvent(event) {
|
|
5383
5466
|
return this.enqueueAnnotation(event);
|
|
5384
5467
|
}
|
|
5468
|
+
onFeedbackReviewStatusEvent(event) {
|
|
5469
|
+
return this.enqueueAnnotation(event);
|
|
5470
|
+
}
|
|
5385
5471
|
onFeedbackReplacementEvent(event) {
|
|
5386
5472
|
return this.enqueueAnnotation(event);
|
|
5387
5473
|
}
|
|
@@ -5389,7 +5475,8 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
5389
5475
|
return this.enqueueAnnotation(event);
|
|
5390
5476
|
}
|
|
5391
5477
|
enqueueAnnotation(event) {
|
|
5392
|
-
const
|
|
5478
|
+
const feedbackId = event.type === "score" ? void 0 : event.feedback.feedbackId;
|
|
5479
|
+
const pending = feedbackId ? this.#feedbackWrites.enqueue(feedbackId, () => this.storeAnnotation(event)) : this.storeAnnotation(event);
|
|
5393
5480
|
this.#pendingAnnotations.add(pending);
|
|
5394
5481
|
pending.then(() => this.#pendingAnnotations.delete(pending), () => this.#pendingAnnotations.delete(pending));
|
|
5395
5482
|
return pending;
|
|
@@ -5397,6 +5484,11 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
5397
5484
|
async storeAnnotation(event) {
|
|
5398
5485
|
await this.waitForInit();
|
|
5399
5486
|
if (!this.#observabilityStorage) return;
|
|
5487
|
+
if (event.type === "feedback_review_status") {
|
|
5488
|
+
await this.flushBufferedEvents();
|
|
5489
|
+
await updateStorageFeedbackReviewStatus(this.#observabilityStorage, event.feedback, this.logger);
|
|
5490
|
+
return;
|
|
5491
|
+
}
|
|
5400
5492
|
const resolved = await resolveStorageAnnotation(event, this.#observabilityStorage, async () => {
|
|
5401
5493
|
await Promise.allSettled([...this.#inFlightFlushes]);
|
|
5402
5494
|
if (this.#eventBuffer.totalSize) await this.trackFlushBuffer();
|
|
@@ -5428,6 +5520,9 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
5428
5520
|
*/
|
|
5429
5521
|
async flush() {
|
|
5430
5522
|
await Promise.allSettled([...this.#pendingAnnotations]);
|
|
5523
|
+
await this.flushBufferedEvents();
|
|
5524
|
+
}
|
|
5525
|
+
async flushBufferedEvents() {
|
|
5431
5526
|
for (let round = 0; round < MAX_FLUSH_ROUNDS$1; round++) {
|
|
5432
5527
|
if (this.#inFlightFlushes.size > 0) await Promise.allSettled([...this.#inFlightFlushes]);
|
|
5433
5528
|
if (this.#eventBuffer.totalSize > 0) {
|
|
@@ -5578,6 +5673,7 @@ var MastraStorageExporter = class extends BaseExporter {
|
|
|
5578
5673
|
/** Storage writes (timer, size trigger, or flush()) that haven't finished yet */
|
|
5579
5674
|
#inFlightFlushes = /* @__PURE__ */ new Set();
|
|
5580
5675
|
#pendingAnnotations = /* @__PURE__ */ new Set();
|
|
5676
|
+
#feedbackWrites = new KeyedQueue();
|
|
5581
5677
|
#emitDropEvent;
|
|
5582
5678
|
#unsupportedSignals = /* @__PURE__ */ new Set();
|
|
5583
5679
|
constructor(config = {}) {
|
|
@@ -6035,6 +6131,9 @@ var MastraStorageExporter = class extends BaseExporter {
|
|
|
6035
6131
|
onScoreEvent(event) {
|
|
6036
6132
|
return this.enqueueAnnotation(event);
|
|
6037
6133
|
}
|
|
6134
|
+
onFeedbackReviewStatusEvent(event) {
|
|
6135
|
+
return this.enqueueAnnotation(event);
|
|
6136
|
+
}
|
|
6038
6137
|
onFeedbackReplacementEvent(event) {
|
|
6039
6138
|
return this.enqueueAnnotation(event);
|
|
6040
6139
|
}
|
|
@@ -6042,7 +6141,8 @@ var MastraStorageExporter = class extends BaseExporter {
|
|
|
6042
6141
|
return this.enqueueAnnotation(event);
|
|
6043
6142
|
}
|
|
6044
6143
|
enqueueAnnotation(event) {
|
|
6045
|
-
const
|
|
6144
|
+
const feedbackId = event.type === "score" ? void 0 : event.feedback.feedbackId;
|
|
6145
|
+
const pending = feedbackId ? this.#feedbackWrites.enqueue(feedbackId, () => this.storeAnnotation(event)) : this.storeAnnotation(event);
|
|
6046
6146
|
this.#pendingAnnotations.add(pending);
|
|
6047
6147
|
pending.then(() => this.#pendingAnnotations.delete(pending), () => this.#pendingAnnotations.delete(pending));
|
|
6048
6148
|
return pending;
|
|
@@ -6050,6 +6150,11 @@ var MastraStorageExporter = class extends BaseExporter {
|
|
|
6050
6150
|
async storeAnnotation(event) {
|
|
6051
6151
|
await this.ensureInitialized();
|
|
6052
6152
|
if (!this.#observabilityStorage) return;
|
|
6153
|
+
if (event.type === "feedback_review_status") {
|
|
6154
|
+
await this.flushBufferedEvents();
|
|
6155
|
+
await updateStorageFeedbackReviewStatus(this.#observabilityStorage, event.feedback, this.logger);
|
|
6156
|
+
return;
|
|
6157
|
+
}
|
|
6053
6158
|
const resolved = await resolveStorageAnnotation(event, this.#observabilityStorage, async () => {
|
|
6054
6159
|
await Promise.allSettled([...this.#inFlightFlushes]);
|
|
6055
6160
|
if (this.#eventBuffer.totalSize) await this.trackFlushBuffer();
|
|
@@ -6081,6 +6186,9 @@ var MastraStorageExporter = class extends BaseExporter {
|
|
|
6081
6186
|
*/
|
|
6082
6187
|
async flush() {
|
|
6083
6188
|
await Promise.allSettled([...this.#pendingAnnotations]);
|
|
6189
|
+
await this.flushBufferedEvents();
|
|
6190
|
+
}
|
|
6191
|
+
async flushBufferedEvents() {
|
|
6084
6192
|
if (this.#byteTracker) {
|
|
6085
6193
|
if (!this.#observabilityStorage) return;
|
|
6086
6194
|
this.#byteDrainers++;
|
|
@@ -6348,7 +6456,10 @@ var BaseObservabilityInstance = class extends _mastra_core_base.MastraBase {
|
|
|
6348
6456
|
tracingPolicy: cached.isInternal ? { internal: _mastra_core_observability.InternalSpans.ALL } : void 0,
|
|
6349
6457
|
traceState: this.rebuildTraceState(cached)
|
|
6350
6458
|
});
|
|
6351
|
-
if (span instanceof BaseSpan)
|
|
6459
|
+
if (span instanceof BaseSpan) {
|
|
6460
|
+
span.restoreEntityLineage(cached);
|
|
6461
|
+
span.restoreErrorCount(cached);
|
|
6462
|
+
}
|
|
6352
6463
|
if (cached.endTime) {
|
|
6353
6464
|
span.endTime = cached.endTime instanceof Date ? cached.endTime : new Date(cached.endTime);
|
|
6354
6465
|
span.output = cached.output;
|
|
@@ -9109,7 +9220,7 @@ async function publishResolvedRecord(url, body, headers, method = "POST") {
|
|
|
9109
9220
|
}
|
|
9110
9221
|
const error = await response.json().catch(() => null);
|
|
9111
9222
|
const code = error?.code ?? error?.error?.code;
|
|
9112
|
-
if (!(response.status === 404 && (code === "TRACE_NOT_FOUND" || code === "SPAN_NOT_FOUND") || response.status === 503 && code === "ANCHOR_LOOKUP_UNAVAILABLE") || attempt === 5) throw new Error(`Platform record delivery failed: HTTP ${response.status}${code ? ` (${code})` : ""}`);
|
|
9223
|
+
if (!(method === "PATCH" ? response.status === 404 && code === "FEEDBACK_NOT_FOUND" || response.status === 503 && code === "FEEDBACK_LOOKUP_UNAVAILABLE" : response.status === 404 && (code === "TRACE_NOT_FOUND" || code === "SPAN_NOT_FOUND") || response.status === 503 && code === "ANCHOR_LOOKUP_UNAVAILABLE") || attempt === 5) throw new Error(`Platform record delivery failed: HTTP ${response.status}${code ? ` (${code})` : ""}`);
|
|
9113
9224
|
const retryAfter = response.headers.get("retry-after");
|
|
9114
9225
|
const retryAfterMs = retryAfter ? /^\d+(?:\.\d+)?$/.test(retryAfter) ? Number(retryAfter) * 1e3 : Date.parse(retryAfter) - Date.now() : 0;
|
|
9115
9226
|
const delay = Math.max(Math.min(500 * 2 ** attempt, 4e3), Number.isFinite(retryAfterMs) ? retryAfterMs : 0);
|
|
@@ -9247,6 +9358,7 @@ var MastraPlatformExporter = class extends BaseExporter {
|
|
|
9247
9358
|
flushTimer = null;
|
|
9248
9359
|
inFlightFlushes = /* @__PURE__ */ new Set();
|
|
9249
9360
|
pendingRecords = /* @__PURE__ */ new Set();
|
|
9361
|
+
feedbackUpdates = new KeyedQueue();
|
|
9250
9362
|
quotaPaused = false;
|
|
9251
9363
|
quotaProbeTimer = null;
|
|
9252
9364
|
quotaProbeIntervalSeconds = DEFAULT_QUOTA_PROBE_INTERVAL_SECONDS;
|
|
@@ -9352,6 +9464,16 @@ var MastraPlatformExporter = class extends BaseExporter {
|
|
|
9352
9464
|
}
|
|
9353
9465
|
this.enqueueResolvedRecord("feedback", event.feedback, event.feedback.feedbackId);
|
|
9354
9466
|
}
|
|
9467
|
+
onFeedbackReviewStatusEvent(event) {
|
|
9468
|
+
if (this.isDisabled || this.shuttingDown) return;
|
|
9469
|
+
const { feedbackId, reviewStatus } = event.feedback;
|
|
9470
|
+
if (!feedbackId?.trim() || !["needs-review", "reviewed"].includes(reviewStatus)) {
|
|
9471
|
+
this.logger.warn("Dropping feedback review update: feedbackId and reviewStatus are required");
|
|
9472
|
+
return;
|
|
9473
|
+
}
|
|
9474
|
+
const url = new URL(`/api/observability/feedback/${encodeURIComponent(feedbackId)}/review-status`, this.platformConfig.feedbackEndpoint);
|
|
9475
|
+
this.enqueueInteractiveWrite("feedback", url, JSON.stringify({ reviewStatus }), "PATCH", feedbackId);
|
|
9476
|
+
}
|
|
9355
9477
|
enqueueResolvedRecord(kind, record, replacementId) {
|
|
9356
9478
|
if (!record.traceId?.trim()) {
|
|
9357
9479
|
this.logger.warn(`Dropping ${kind}: context resolution requires traceId`);
|
|
@@ -9367,6 +9489,10 @@ var MastraPlatformExporter = class extends BaseExporter {
|
|
|
9367
9489
|
const collectorEndpoint = kind === "score" ? this.platformConfig.scoresEndpoint : this.platformConfig.feedbackEndpoint;
|
|
9368
9490
|
const url = new URL(`/api/observability/${kind === "score" ? "scores" : "feedback"}`, collectorEndpoint);
|
|
9369
9491
|
if (replacementId !== void 0) url.pathname += `/${encodeURIComponent(replacementId)}`;
|
|
9492
|
+
this.enqueueInteractiveWrite(kind, url, body, replacementId !== void 0 ? "PUT" : "POST", replacementId);
|
|
9493
|
+
}
|
|
9494
|
+
enqueueInteractiveWrite(kind, url, body, method, feedbackId) {
|
|
9495
|
+
const collectorEndpoint = kind === "score" ? this.platformConfig.scoresEndpoint : this.platformConfig.feedbackEndpoint;
|
|
9370
9496
|
const projectId = new URL(collectorEndpoint).pathname.match(/\/projects\/([^/]+)\/ai\//)?.[1] ?? this.platformConfig.projectId;
|
|
9371
9497
|
const headers = {
|
|
9372
9498
|
Authorization: `Bearer ${this.platformConfig.accessToken}`,
|
|
@@ -9374,7 +9500,8 @@ var MastraPlatformExporter = class extends BaseExporter {
|
|
|
9374
9500
|
...projectId ? { "X-Mastra-Project-Id": projectId } : {}
|
|
9375
9501
|
};
|
|
9376
9502
|
this.flushBatches().catch((error) => this.logger.warn("Failed to flush buffered telemetry", { error }));
|
|
9377
|
-
const
|
|
9503
|
+
const send = () => publishResolvedRecord(url, body, headers, method);
|
|
9504
|
+
const pending = (feedbackId !== void 0 ? this.feedbackUpdates.enqueue(feedbackId, send) : send()).catch((error) => this.logger.warn(`Dropping ${kind} after Platform delivery failed`, { error })).finally(() => this.pendingRecords.delete(pending));
|
|
9378
9505
|
this.pendingRecords.add(pending);
|
|
9379
9506
|
}
|
|
9380
9507
|
addToBuffer(event) {
|
|
@@ -11331,6 +11458,16 @@ var Observability = class extends _mastra_core_base.MastraBase {
|
|
|
11331
11458
|
}
|
|
11332
11459
|
});
|
|
11333
11460
|
}
|
|
11461
|
+
async updateFeedbackReviewStatus(args) {
|
|
11462
|
+
if (!args.feedbackId?.trim() || !["needs-review", "reviewed"].includes(args.reviewStatus)) throw new Error("Feedback review update requires feedbackId and a valid reviewStatus");
|
|
11463
|
+
await this.#emitRecordedEvent({
|
|
11464
|
+
type: "feedback_review_status",
|
|
11465
|
+
feedback: {
|
|
11466
|
+
feedbackId: args.feedbackId,
|
|
11467
|
+
reviewStatus: args.reviewStatus
|
|
11468
|
+
}
|
|
11469
|
+
});
|
|
11470
|
+
}
|
|
11334
11471
|
/** @internal Queue an HTTP-created record; flush/shutdown await delivery without holding the HTTP response open. */
|
|
11335
11472
|
async __exportPersistedEvent(event) {
|
|
11336
11473
|
const storageExporters = new Set(this.#getRecordedTraceInstance()?.getExporters().filter(isMastraBuiltInStorageExporter));
|
|
@@ -11514,6 +11651,7 @@ exports.OBSERVABILITY_CAPABILITIES_HEADER = OBSERVABILITY_CAPABILITIES_HEADER;
|
|
|
11514
11651
|
exports.Observability = Observability;
|
|
11515
11652
|
exports.ObservabilityBus = ObservabilityBus;
|
|
11516
11653
|
exports.QUOTA_PAUSE_CAPABILITY = QUOTA_PAUSE_CAPABILITY;
|
|
11654
|
+
exports.REDACTED_ERROR_MESSAGE = REDACTED_ERROR_MESSAGE;
|
|
11517
11655
|
exports.SamplingStrategyType = SamplingStrategyType;
|
|
11518
11656
|
exports.SensitiveDataFilter = SensitiveDataFilter;
|
|
11519
11657
|
exports.TestExporter = TestExporter;
|
|
@@ -11540,6 +11678,7 @@ exports.otlpSeverityToLogLevel = otlpSeverityToLogLevel;
|
|
|
11540
11678
|
exports.parseBaggage = parseBaggage;
|
|
11541
11679
|
exports.parseTraceparent = parseTraceparent;
|
|
11542
11680
|
exports.reconstructSerializedMap = reconstructSerializedMap;
|
|
11681
|
+
exports.redactErrorInfo = redactErrorInfo;
|
|
11543
11682
|
exports.routeToHandler = routeToHandler;
|
|
11544
11683
|
exports.samplingStrategySchema = samplingStrategySchema;
|
|
11545
11684
|
exports.serializationOptionsSchema = serializationOptionsSchema;
|