@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.js
CHANGED
|
@@ -52,6 +52,9 @@ function routeToHandler(handler, event, logger) {
|
|
|
52
52
|
}), handler.name, "score", logger);
|
|
53
53
|
}
|
|
54
54
|
break;
|
|
55
|
+
case "feedback_review_status":
|
|
56
|
+
if (handler.onFeedbackReviewStatusEvent) return catchAsyncResult(handler.onFeedbackReviewStatusEvent(event), handler.name, "feedback review status", logger);
|
|
57
|
+
break;
|
|
55
58
|
case "feedback_replacement":
|
|
56
59
|
if (handler.onFeedbackReplacementEvent) return catchAsyncResult(handler.onFeedbackReplacementEvent(event), handler.name, "feedback replacement", logger);
|
|
57
60
|
break;
|
|
@@ -555,6 +558,10 @@ function cleanEvent(event, options) {
|
|
|
555
558
|
type: "score",
|
|
556
559
|
score: deepClean(event.score, options)
|
|
557
560
|
};
|
|
561
|
+
case "feedback_review_status": return {
|
|
562
|
+
type: event.type,
|
|
563
|
+
feedback: deepClean(event.feedback, options)
|
|
564
|
+
};
|
|
558
565
|
case "feedback_replacement": return {
|
|
559
566
|
type: event.type,
|
|
560
567
|
feedback: deepClean(event.feedback, options)
|
|
@@ -3426,6 +3433,34 @@ function mergeMetadata$1(parentMetadata, metadata) {
|
|
|
3426
3433
|
}
|
|
3427
3434
|
}
|
|
3428
3435
|
// src/spans/base.ts
|
|
3436
|
+
/** Replaces error text exported from traces that hide input or output. */
|
|
3437
|
+
const REDACTED_ERROR_MESSAGE = "[REDACTED]";
|
|
3438
|
+
/**
|
|
3439
|
+
* The error as exported from a trace that hides input or output: keeps what
|
|
3440
|
+
* identifies the error (id, name, domain, category, stack frames) and drops
|
|
3441
|
+
* text and free-form details, which can quote the hidden data.
|
|
3442
|
+
*/
|
|
3443
|
+
function redactErrorInfo(errorInfo, stackMessage) {
|
|
3444
|
+
if (!errorInfo) return errorInfo;
|
|
3445
|
+
const { id, name, domain, category, stack } = errorInfo;
|
|
3446
|
+
return {
|
|
3447
|
+
...id !== void 0 ? { id } : {},
|
|
3448
|
+
...name !== void 0 ? { name } : {},
|
|
3449
|
+
...domain !== void 0 ? { domain } : {},
|
|
3450
|
+
...category !== void 0 ? { category } : {},
|
|
3451
|
+
message: REDACTED_ERROR_MESSAGE,
|
|
3452
|
+
...stack !== void 0 ? { stack: redactStackHeader(stack, stackMessage ?? errorInfo.message, errorInfo.name) } : {}
|
|
3453
|
+
};
|
|
3454
|
+
}
|
|
3455
|
+
/** Preserve stack frames only when they follow the complete captured message. */
|
|
3456
|
+
function redactStackHeader(stack, message, name = "Error") {
|
|
3457
|
+
const redactedHeader = `${name}: ${REDACTED_ERROR_MESSAGE}`;
|
|
3458
|
+
const separator = `: ${message}`;
|
|
3459
|
+
const separatorIndex = stack.indexOf(separator);
|
|
3460
|
+
if (separatorIndex <= 0 || stack.slice(0, separatorIndex).includes("\n")) return redactedHeader;
|
|
3461
|
+
const suffix = stack.slice(separatorIndex + separator.length);
|
|
3462
|
+
return suffix === "" || suffix.startsWith("\n") ? `${redactedHeader}${suffix}` : redactedHeader;
|
|
3463
|
+
}
|
|
3429
3464
|
const LINEAGE_KEYS = [
|
|
3430
3465
|
"parentEntityType",
|
|
3431
3466
|
"parentEntityId",
|
|
@@ -3555,11 +3590,29 @@ var BaseSpan = class BaseSpan {
|
|
|
3555
3590
|
stopReason;
|
|
3556
3591
|
stopReasonContext;
|
|
3557
3592
|
errorInfo;
|
|
3593
|
+
errorStackMessage;
|
|
3558
3594
|
metadata;
|
|
3559
3595
|
requestContext;
|
|
3560
3596
|
tags;
|
|
3561
3597
|
links;
|
|
3562
3598
|
traceState;
|
|
3599
|
+
localErrorCount = typeof coreObservability.claimSpanError === "function" ? 0 : void 0;
|
|
3600
|
+
errorOccurrenceIds;
|
|
3601
|
+
recordError(error, options) {
|
|
3602
|
+
if (this.isEvent || this.endTime) return;
|
|
3603
|
+
if (error === null || typeof error !== "object" && typeof error !== "function") {
|
|
3604
|
+
this.localErrorCount = void 0;
|
|
3605
|
+
return;
|
|
3606
|
+
}
|
|
3607
|
+
const id = coreObservability.claimSpanError?.(error, this.traceId, this.id, options);
|
|
3608
|
+
if (this.isExcluded || id === void 0 || this.errorOccurrenceIds?.has(id)) return;
|
|
3609
|
+
(this.errorOccurrenceIds ??= /* @__PURE__ */ new Set()).add(id);
|
|
3610
|
+
if (this.localErrorCount !== void 0) this.localErrorCount++;
|
|
3611
|
+
}
|
|
3612
|
+
restoreErrorCount(cached) {
|
|
3613
|
+
this.localErrorCount = typeof coreObservability.claimSpanError !== "function" || cached.errorCount && !cached.errorOccurrenceIds ? void 0 : cached.errorCount;
|
|
3614
|
+
this.errorOccurrenceIds = cached.errorOccurrenceIds?.length ? new Set(cached.errorOccurrenceIds) : void 0;
|
|
3615
|
+
}
|
|
3563
3616
|
/** Entity type that created the span (e.g., agent, workflow) */
|
|
3564
3617
|
entityType;
|
|
3565
3618
|
/** Entity ID that created the span */
|
|
@@ -3942,7 +3995,8 @@ var BaseSpan = class BaseSpan {
|
|
|
3942
3995
|
endTime: this.endTime,
|
|
3943
3996
|
input: hideInput ? void 0 : this.input,
|
|
3944
3997
|
output: hideOutput ? void 0 : this.output,
|
|
3945
|
-
errorInfo: this.errorInfo,
|
|
3998
|
+
errorInfo: hideInput || hideOutput ? redactErrorInfo(this.errorInfo, this.errorStackMessage) : this.errorInfo,
|
|
3999
|
+
...this.localErrorCount !== void 0 ? { errorCount: this.localErrorCount } : {},
|
|
3946
4000
|
...this.outcome !== void 0 ? { outcome: this.outcome } : {},
|
|
3947
4001
|
...this.stopReason !== void 0 ? { stopReason: this.stopReason } : {},
|
|
3948
4002
|
...this.stopReasonContext !== void 0 ? { stopReasonContext: this.stopReasonContext } : {},
|
|
@@ -3968,6 +4022,7 @@ var BaseSpan = class BaseSpan {
|
|
|
3968
4022
|
return {
|
|
3969
4023
|
...this.exportSpan(this.observabilityInstance.getConfig().includeInternalSpans),
|
|
3970
4024
|
ownEntityVersionId: this.ownEntityVersionId ?? null,
|
|
4025
|
+
...this.errorOccurrenceIds ? { errorOccurrenceIds: [...this.errorOccurrenceIds] } : {},
|
|
3971
4026
|
...this.traceState ? { traceState: this.traceState } : {}
|
|
3972
4027
|
};
|
|
3973
4028
|
}
|
|
@@ -4087,6 +4142,7 @@ var DefaultSpan = class extends BaseSpan {
|
|
|
4087
4142
|
error(options) {
|
|
4088
4143
|
if (this.isEvent || this.endTime) return;
|
|
4089
4144
|
const { error, endSpan = true, endTree, attributes, metadata } = options;
|
|
4145
|
+
this.recordError(error, { origin: options.origin });
|
|
4090
4146
|
this.applyOutcome(options);
|
|
4091
4147
|
if (metadata) this.metadata = {
|
|
4092
4148
|
...this.metadata,
|
|
@@ -4094,6 +4150,8 @@ var DefaultSpan = class extends BaseSpan {
|
|
|
4094
4150
|
};
|
|
4095
4151
|
if (!this.isExcluded) {
|
|
4096
4152
|
const apiDetails = apiCallErrorDetails(error);
|
|
4153
|
+
const stackError = error instanceof MastraError && error.cause instanceof Error && error.cause.stack ? error.cause : error;
|
|
4154
|
+
this.errorStackMessage = stackError.message;
|
|
4097
4155
|
this.errorInfo = deepClean(error instanceof MastraError ? {
|
|
4098
4156
|
id: error.id,
|
|
4099
4157
|
details: apiDetails ? {
|
|
@@ -4104,7 +4162,7 @@ var DefaultSpan = class extends BaseSpan {
|
|
|
4104
4162
|
domain: error.domain,
|
|
4105
4163
|
message: error.message,
|
|
4106
4164
|
name: error.name,
|
|
4107
|
-
stack:
|
|
4165
|
+
stack: stackError.stack
|
|
4108
4166
|
} : {
|
|
4109
4167
|
message: error.message,
|
|
4110
4168
|
name: error.name,
|
|
@@ -4606,6 +4664,20 @@ var EventBuffer = class {
|
|
|
4606
4664
|
});
|
|
4607
4665
|
}
|
|
4608
4666
|
};
|
|
4667
|
+
// src/exporters/keyed-queue.ts
|
|
4668
|
+
/** Keep writes to one record ordered without blocking unrelated records. */
|
|
4669
|
+
var KeyedQueue = class {
|
|
4670
|
+
pending = /* @__PURE__ */ new Map();
|
|
4671
|
+
enqueue(key, write) {
|
|
4672
|
+
const current = (this.pending.get(key) ?? Promise.resolve()).catch(() => {}).then(write);
|
|
4673
|
+
this.pending.set(key, current);
|
|
4674
|
+
const cleanup = () => {
|
|
4675
|
+
if (this.pending.get(key) === current) this.pending.delete(key);
|
|
4676
|
+
};
|
|
4677
|
+
current.then(cleanup, cleanup);
|
|
4678
|
+
return current;
|
|
4679
|
+
}
|
|
4680
|
+
};
|
|
4609
4681
|
// src/recorded.ts
|
|
4610
4682
|
function nullToUndefined(value) {
|
|
4611
4683
|
return value ?? void 0;
|
|
@@ -4932,6 +5004,16 @@ const LOOKUP_DELAYS_MS = [
|
|
|
4932
5004
|
2e3,
|
|
4933
5005
|
2e3
|
|
4934
5006
|
];
|
|
5007
|
+
/** Older stores may inherit a method that throws instead of omitting the hook. */
|
|
5008
|
+
async function updateStorageFeedbackReviewStatus(storage, feedback, logger) {
|
|
5009
|
+
if (typeof storage.updateFeedbackReviewStatus === "function") try {
|
|
5010
|
+
await storage.updateFeedbackReviewStatus(feedback);
|
|
5011
|
+
return;
|
|
5012
|
+
} catch (error) {
|
|
5013
|
+
if (typeof error !== "object" || error === null || !("id" in error) || error.id !== "OBSERVABILITY_STORAGE_UPDATE_FEEDBACK_REVIEW_STATUS_NOT_IMPLEMENTED") throw error;
|
|
5014
|
+
}
|
|
5015
|
+
logger.warn("Storage exporter skipped feedback review update: upgrade the storage adapter and @mastra/core");
|
|
5016
|
+
}
|
|
4935
5017
|
/**
|
|
4936
5018
|
* Resolve attached-storage context within a bounded retry window, including failed reads.
|
|
4937
5019
|
* Exhaustion returns null for missing anchors or throws the last read error for the exporter to report.
|
|
@@ -5002,6 +5084,7 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
5002
5084
|
/** Storage writes (timer, size trigger, or flush()) that haven't finished yet */
|
|
5003
5085
|
#inFlightFlushes = /* @__PURE__ */ new Set();
|
|
5004
5086
|
#pendingAnnotations = /* @__PURE__ */ new Set();
|
|
5087
|
+
#feedbackWrites = new KeyedQueue();
|
|
5005
5088
|
#emitDropEvent;
|
|
5006
5089
|
#unsupportedSignals = /* @__PURE__ */ new Set();
|
|
5007
5090
|
constructor(config = {}) {
|
|
@@ -5357,6 +5440,9 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
5357
5440
|
onScoreEvent(event) {
|
|
5358
5441
|
return this.enqueueAnnotation(event);
|
|
5359
5442
|
}
|
|
5443
|
+
onFeedbackReviewStatusEvent(event) {
|
|
5444
|
+
return this.enqueueAnnotation(event);
|
|
5445
|
+
}
|
|
5360
5446
|
onFeedbackReplacementEvent(event) {
|
|
5361
5447
|
return this.enqueueAnnotation(event);
|
|
5362
5448
|
}
|
|
@@ -5364,7 +5450,8 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
5364
5450
|
return this.enqueueAnnotation(event);
|
|
5365
5451
|
}
|
|
5366
5452
|
enqueueAnnotation(event) {
|
|
5367
|
-
const
|
|
5453
|
+
const feedbackId = event.type === "score" ? void 0 : event.feedback.feedbackId;
|
|
5454
|
+
const pending = feedbackId ? this.#feedbackWrites.enqueue(feedbackId, () => this.storeAnnotation(event)) : this.storeAnnotation(event);
|
|
5368
5455
|
this.#pendingAnnotations.add(pending);
|
|
5369
5456
|
pending.then(() => this.#pendingAnnotations.delete(pending), () => this.#pendingAnnotations.delete(pending));
|
|
5370
5457
|
return pending;
|
|
@@ -5372,6 +5459,11 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
5372
5459
|
async storeAnnotation(event) {
|
|
5373
5460
|
await this.waitForInit();
|
|
5374
5461
|
if (!this.#observabilityStorage) return;
|
|
5462
|
+
if (event.type === "feedback_review_status") {
|
|
5463
|
+
await this.flushBufferedEvents();
|
|
5464
|
+
await updateStorageFeedbackReviewStatus(this.#observabilityStorage, event.feedback, this.logger);
|
|
5465
|
+
return;
|
|
5466
|
+
}
|
|
5375
5467
|
const resolved = await resolveStorageAnnotation(event, this.#observabilityStorage, async () => {
|
|
5376
5468
|
await Promise.allSettled([...this.#inFlightFlushes]);
|
|
5377
5469
|
if (this.#eventBuffer.totalSize) await this.trackFlushBuffer();
|
|
@@ -5403,6 +5495,9 @@ var DefaultExporter = class extends BaseExporter {
|
|
|
5403
5495
|
*/
|
|
5404
5496
|
async flush() {
|
|
5405
5497
|
await Promise.allSettled([...this.#pendingAnnotations]);
|
|
5498
|
+
await this.flushBufferedEvents();
|
|
5499
|
+
}
|
|
5500
|
+
async flushBufferedEvents() {
|
|
5406
5501
|
for (let round = 0; round < MAX_FLUSH_ROUNDS$1; round++) {
|
|
5407
5502
|
if (this.#inFlightFlushes.size > 0) await Promise.allSettled([...this.#inFlightFlushes]);
|
|
5408
5503
|
if (this.#eventBuffer.totalSize > 0) {
|
|
@@ -5553,6 +5648,7 @@ var MastraStorageExporter = class extends BaseExporter {
|
|
|
5553
5648
|
/** Storage writes (timer, size trigger, or flush()) that haven't finished yet */
|
|
5554
5649
|
#inFlightFlushes = /* @__PURE__ */ new Set();
|
|
5555
5650
|
#pendingAnnotations = /* @__PURE__ */ new Set();
|
|
5651
|
+
#feedbackWrites = new KeyedQueue();
|
|
5556
5652
|
#emitDropEvent;
|
|
5557
5653
|
#unsupportedSignals = /* @__PURE__ */ new Set();
|
|
5558
5654
|
constructor(config = {}) {
|
|
@@ -6010,6 +6106,9 @@ var MastraStorageExporter = class extends BaseExporter {
|
|
|
6010
6106
|
onScoreEvent(event) {
|
|
6011
6107
|
return this.enqueueAnnotation(event);
|
|
6012
6108
|
}
|
|
6109
|
+
onFeedbackReviewStatusEvent(event) {
|
|
6110
|
+
return this.enqueueAnnotation(event);
|
|
6111
|
+
}
|
|
6013
6112
|
onFeedbackReplacementEvent(event) {
|
|
6014
6113
|
return this.enqueueAnnotation(event);
|
|
6015
6114
|
}
|
|
@@ -6017,7 +6116,8 @@ var MastraStorageExporter = class extends BaseExporter {
|
|
|
6017
6116
|
return this.enqueueAnnotation(event);
|
|
6018
6117
|
}
|
|
6019
6118
|
enqueueAnnotation(event) {
|
|
6020
|
-
const
|
|
6119
|
+
const feedbackId = event.type === "score" ? void 0 : event.feedback.feedbackId;
|
|
6120
|
+
const pending = feedbackId ? this.#feedbackWrites.enqueue(feedbackId, () => this.storeAnnotation(event)) : this.storeAnnotation(event);
|
|
6021
6121
|
this.#pendingAnnotations.add(pending);
|
|
6022
6122
|
pending.then(() => this.#pendingAnnotations.delete(pending), () => this.#pendingAnnotations.delete(pending));
|
|
6023
6123
|
return pending;
|
|
@@ -6025,6 +6125,11 @@ var MastraStorageExporter = class extends BaseExporter {
|
|
|
6025
6125
|
async storeAnnotation(event) {
|
|
6026
6126
|
await this.ensureInitialized();
|
|
6027
6127
|
if (!this.#observabilityStorage) return;
|
|
6128
|
+
if (event.type === "feedback_review_status") {
|
|
6129
|
+
await this.flushBufferedEvents();
|
|
6130
|
+
await updateStorageFeedbackReviewStatus(this.#observabilityStorage, event.feedback, this.logger);
|
|
6131
|
+
return;
|
|
6132
|
+
}
|
|
6028
6133
|
const resolved = await resolveStorageAnnotation(event, this.#observabilityStorage, async () => {
|
|
6029
6134
|
await Promise.allSettled([...this.#inFlightFlushes]);
|
|
6030
6135
|
if (this.#eventBuffer.totalSize) await this.trackFlushBuffer();
|
|
@@ -6056,6 +6161,9 @@ var MastraStorageExporter = class extends BaseExporter {
|
|
|
6056
6161
|
*/
|
|
6057
6162
|
async flush() {
|
|
6058
6163
|
await Promise.allSettled([...this.#pendingAnnotations]);
|
|
6164
|
+
await this.flushBufferedEvents();
|
|
6165
|
+
}
|
|
6166
|
+
async flushBufferedEvents() {
|
|
6059
6167
|
if (this.#byteTracker) {
|
|
6060
6168
|
if (!this.#observabilityStorage) return;
|
|
6061
6169
|
this.#byteDrainers++;
|
|
@@ -6323,7 +6431,10 @@ var BaseObservabilityInstance = class extends MastraBase {
|
|
|
6323
6431
|
tracingPolicy: cached.isInternal ? { internal: InternalSpans.ALL } : void 0,
|
|
6324
6432
|
traceState: this.rebuildTraceState(cached)
|
|
6325
6433
|
});
|
|
6326
|
-
if (span instanceof BaseSpan)
|
|
6434
|
+
if (span instanceof BaseSpan) {
|
|
6435
|
+
span.restoreEntityLineage(cached);
|
|
6436
|
+
span.restoreErrorCount(cached);
|
|
6437
|
+
}
|
|
6327
6438
|
if (cached.endTime) {
|
|
6328
6439
|
span.endTime = cached.endTime instanceof Date ? cached.endTime : new Date(cached.endTime);
|
|
6329
6440
|
span.output = cached.output;
|
|
@@ -9084,7 +9195,7 @@ async function publishResolvedRecord(url, body, headers, method = "POST") {
|
|
|
9084
9195
|
}
|
|
9085
9196
|
const error = await response.json().catch(() => null);
|
|
9086
9197
|
const code = error?.code ?? error?.error?.code;
|
|
9087
|
-
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})` : ""}`);
|
|
9198
|
+
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})` : ""}`);
|
|
9088
9199
|
const retryAfter = response.headers.get("retry-after");
|
|
9089
9200
|
const retryAfterMs = retryAfter ? /^\d+(?:\.\d+)?$/.test(retryAfter) ? Number(retryAfter) * 1e3 : Date.parse(retryAfter) - Date.now() : 0;
|
|
9090
9201
|
const delay = Math.max(Math.min(500 * 2 ** attempt, 4e3), Number.isFinite(retryAfterMs) ? retryAfterMs : 0);
|
|
@@ -9222,6 +9333,7 @@ var MastraPlatformExporter = class extends BaseExporter {
|
|
|
9222
9333
|
flushTimer = null;
|
|
9223
9334
|
inFlightFlushes = /* @__PURE__ */ new Set();
|
|
9224
9335
|
pendingRecords = /* @__PURE__ */ new Set();
|
|
9336
|
+
feedbackUpdates = new KeyedQueue();
|
|
9225
9337
|
quotaPaused = false;
|
|
9226
9338
|
quotaProbeTimer = null;
|
|
9227
9339
|
quotaProbeIntervalSeconds = DEFAULT_QUOTA_PROBE_INTERVAL_SECONDS;
|
|
@@ -9327,6 +9439,16 @@ var MastraPlatformExporter = class extends BaseExporter {
|
|
|
9327
9439
|
}
|
|
9328
9440
|
this.enqueueResolvedRecord("feedback", event.feedback, event.feedback.feedbackId);
|
|
9329
9441
|
}
|
|
9442
|
+
onFeedbackReviewStatusEvent(event) {
|
|
9443
|
+
if (this.isDisabled || this.shuttingDown) return;
|
|
9444
|
+
const { feedbackId, reviewStatus } = event.feedback;
|
|
9445
|
+
if (!feedbackId?.trim() || !["needs-review", "reviewed"].includes(reviewStatus)) {
|
|
9446
|
+
this.logger.warn("Dropping feedback review update: feedbackId and reviewStatus are required");
|
|
9447
|
+
return;
|
|
9448
|
+
}
|
|
9449
|
+
const url = new URL(`/api/observability/feedback/${encodeURIComponent(feedbackId)}/review-status`, this.platformConfig.feedbackEndpoint);
|
|
9450
|
+
this.enqueueInteractiveWrite("feedback", url, JSON.stringify({ reviewStatus }), "PATCH", feedbackId);
|
|
9451
|
+
}
|
|
9330
9452
|
enqueueResolvedRecord(kind, record, replacementId) {
|
|
9331
9453
|
if (!record.traceId?.trim()) {
|
|
9332
9454
|
this.logger.warn(`Dropping ${kind}: context resolution requires traceId`);
|
|
@@ -9342,6 +9464,10 @@ var MastraPlatformExporter = class extends BaseExporter {
|
|
|
9342
9464
|
const collectorEndpoint = kind === "score" ? this.platformConfig.scoresEndpoint : this.platformConfig.feedbackEndpoint;
|
|
9343
9465
|
const url = new URL(`/api/observability/${kind === "score" ? "scores" : "feedback"}`, collectorEndpoint);
|
|
9344
9466
|
if (replacementId !== void 0) url.pathname += `/${encodeURIComponent(replacementId)}`;
|
|
9467
|
+
this.enqueueInteractiveWrite(kind, url, body, replacementId !== void 0 ? "PUT" : "POST", replacementId);
|
|
9468
|
+
}
|
|
9469
|
+
enqueueInteractiveWrite(kind, url, body, method, feedbackId) {
|
|
9470
|
+
const collectorEndpoint = kind === "score" ? this.platformConfig.scoresEndpoint : this.platformConfig.feedbackEndpoint;
|
|
9345
9471
|
const projectId = new URL(collectorEndpoint).pathname.match(/\/projects\/([^/]+)\/ai\//)?.[1] ?? this.platformConfig.projectId;
|
|
9346
9472
|
const headers = {
|
|
9347
9473
|
Authorization: `Bearer ${this.platformConfig.accessToken}`,
|
|
@@ -9349,7 +9475,8 @@ var MastraPlatformExporter = class extends BaseExporter {
|
|
|
9349
9475
|
...projectId ? { "X-Mastra-Project-Id": projectId } : {}
|
|
9350
9476
|
};
|
|
9351
9477
|
this.flushBatches().catch((error) => this.logger.warn("Failed to flush buffered telemetry", { error }));
|
|
9352
|
-
const
|
|
9478
|
+
const send = () => publishResolvedRecord(url, body, headers, method);
|
|
9479
|
+
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));
|
|
9353
9480
|
this.pendingRecords.add(pending);
|
|
9354
9481
|
}
|
|
9355
9482
|
addToBuffer(event) {
|
|
@@ -11306,6 +11433,16 @@ var Observability = class extends MastraBase {
|
|
|
11306
11433
|
}
|
|
11307
11434
|
});
|
|
11308
11435
|
}
|
|
11436
|
+
async updateFeedbackReviewStatus(args) {
|
|
11437
|
+
if (!args.feedbackId?.trim() || !["needs-review", "reviewed"].includes(args.reviewStatus)) throw new Error("Feedback review update requires feedbackId and a valid reviewStatus");
|
|
11438
|
+
await this.#emitRecordedEvent({
|
|
11439
|
+
type: "feedback_review_status",
|
|
11440
|
+
feedback: {
|
|
11441
|
+
feedbackId: args.feedbackId,
|
|
11442
|
+
reviewStatus: args.reviewStatus
|
|
11443
|
+
}
|
|
11444
|
+
});
|
|
11445
|
+
}
|
|
11309
11446
|
/** @internal Queue an HTTP-created record; flush/shutdown await delivery without holding the HTTP response open. */
|
|
11310
11447
|
async __exportPersistedEvent(event) {
|
|
11311
11448
|
const storageExporters = new Set(this.#getRecordedTraceInstance()?.getExporters().filter(isMastraBuiltInStorageExporter));
|
|
@@ -11466,6 +11603,6 @@ const observabilityFeatures = /* @__PURE__ */ new Set(["model-inference-span", "
|
|
|
11466
11603
|
function buildTracingOptions(...updaters) {
|
|
11467
11604
|
return updaters.reduce((opts, updater) => updater(opts), {});
|
|
11468
11605
|
}
|
|
11469
|
-
export { BaseExporter, BaseObservabilityEventBus, BaseObservabilityInstance, BaseSpan, CardinalityFilter, CloudExporter, ConsoleExporter, DEFAULT_DEEP_CLEAN_OPTIONS, DEFAULT_LIMITS, DefaultExporter, DefaultObservabilityInstance, DefaultSpan, JsonExporter, LoggerContextImpl, MastraPlatformExporter, MastraStorageExporter, MetricsContextImpl, ModelSpanTracker, NoOpSpan, OBSERVABILITY_CAPABILITIES_HEADER, Observability, ObservabilityBus, QUOTA_PAUSE_CAPABILITY, SamplingStrategyType, SensitiveDataFilter, TestExporter, TraceData, TrackingExporter, buildExportedLog, buildExportedSpan, buildTracingOptions, chainFormatters, createClientObservabilityProxy, decodeResourceLogs, decodeResourceSpans, deepClean, formatBaggage, formatTraceparent, getExternalParentId, isSerializedMap, mergeSerializationOptions, observabilityConfigValueSchema, observabilityFeatures, observabilityInstanceConfigSchema, observabilityRegistryConfigSchema, otlpSeverityToLogLevel, parseBaggage, parseTraceparent, reconstructSerializedMap, routeToHandler, samplingStrategySchema, serializationOptionsSchema, truncateString };
|
|
11606
|
+
export { BaseExporter, BaseObservabilityEventBus, BaseObservabilityInstance, BaseSpan, CardinalityFilter, CloudExporter, ConsoleExporter, DEFAULT_DEEP_CLEAN_OPTIONS, DEFAULT_LIMITS, DefaultExporter, DefaultObservabilityInstance, DefaultSpan, JsonExporter, LoggerContextImpl, MastraPlatformExporter, MastraStorageExporter, MetricsContextImpl, ModelSpanTracker, NoOpSpan, OBSERVABILITY_CAPABILITIES_HEADER, Observability, ObservabilityBus, QUOTA_PAUSE_CAPABILITY, REDACTED_ERROR_MESSAGE, SamplingStrategyType, SensitiveDataFilter, TestExporter, TraceData, TrackingExporter, buildExportedLog, buildExportedSpan, buildTracingOptions, chainFormatters, createClientObservabilityProxy, decodeResourceLogs, decodeResourceSpans, deepClean, formatBaggage, formatTraceparent, getExternalParentId, isSerializedMap, mergeSerializationOptions, observabilityConfigValueSchema, observabilityFeatures, observabilityInstanceConfigSchema, observabilityRegistryConfigSchema, otlpSeverityToLogLevel, parseBaggage, parseTraceparent, reconstructSerializedMap, redactErrorInfo, routeToHandler, samplingStrategySchema, serializationOptionsSchema, truncateString };
|
|
11470
11607
|
|
|
11471
11608
|
//# sourceMappingURL=index.js.map
|