@mastra/observability 1.8.0-alpha.1 → 1.9.0-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.
- package/CHANGELOG.md +85 -0
- package/dist/exporters/cloud.d.ts +2 -1
- package/dist/exporters/cloud.d.ts.map +1 -1
- package/dist/index.cjs +34 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -17
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -15043,14 +15043,7 @@ var SIGNAL_PUBLISH_SUFFIXES = {
|
|
|
15043
15043
|
scores: "/scores/publish",
|
|
15044
15044
|
feedback: "/feedback/publish"
|
|
15045
15045
|
};
|
|
15046
|
-
var
|
|
15047
|
-
traces: "/ai/spans/publish",
|
|
15048
|
-
logs: "/ai/logs/publish",
|
|
15049
|
-
metrics: "/ai/metrics/publish",
|
|
15050
|
-
scores: "/ai/scores/publish",
|
|
15051
|
-
feedback: "/ai/feedback/publish"
|
|
15052
|
-
};
|
|
15053
|
-
var SIGNAL_PAYLOAD_KEYS = {
|
|
15046
|
+
var SIGNAL_PUBLISH_SEGMENTS = {
|
|
15054
15047
|
traces: "spans",
|
|
15055
15048
|
logs: "logs",
|
|
15056
15049
|
metrics: "metrics",
|
|
@@ -15079,6 +15072,18 @@ function createInvalidEndpointError(endpoint, text, cause) {
|
|
|
15079
15072
|
cause
|
|
15080
15073
|
);
|
|
15081
15074
|
}
|
|
15075
|
+
var VALID_PROJECT_ID = /^[a-zA-Z0-9_-]+$/;
|
|
15076
|
+
function createInvalidProjectIdError(projectId) {
|
|
15077
|
+
return new MastraError({
|
|
15078
|
+
id: `CLOUD_EXPORTER_INVALID_PROJECT_ID`,
|
|
15079
|
+
text: "CloudExporter projectId must only contain letters, numbers, hyphens, and underscores.",
|
|
15080
|
+
domain: ErrorDomain.MASTRA_OBSERVABILITY,
|
|
15081
|
+
category: ErrorCategory.USER,
|
|
15082
|
+
details: {
|
|
15083
|
+
projectId
|
|
15084
|
+
}
|
|
15085
|
+
});
|
|
15086
|
+
}
|
|
15082
15087
|
function resolveBaseEndpoint(baseEndpoint) {
|
|
15083
15088
|
const normalizedEndpoint = trimTrailingSlashes(baseEndpoint);
|
|
15084
15089
|
const invalidText = 'CloudExporter endpoint must be a base origin like "https://collector.example.com" with no path, search, or hash.';
|
|
@@ -15095,10 +15100,17 @@ function resolveBaseEndpoint(baseEndpoint) {
|
|
|
15095
15100
|
throw createInvalidEndpointError(baseEndpoint, invalidText, error48);
|
|
15096
15101
|
}
|
|
15097
15102
|
}
|
|
15098
|
-
function
|
|
15099
|
-
|
|
15103
|
+
function buildSignalPath(signal, projectId) {
|
|
15104
|
+
const signalSegment = SIGNAL_PUBLISH_SEGMENTS[signal];
|
|
15105
|
+
if (!projectId) {
|
|
15106
|
+
return `/ai/${signalSegment}/publish`;
|
|
15107
|
+
}
|
|
15108
|
+
return `/projects/${projectId}/ai/${signalSegment}/publish`;
|
|
15109
|
+
}
|
|
15110
|
+
function buildSignalEndpoint(baseEndpoint, signal, projectId) {
|
|
15111
|
+
return `${baseEndpoint}${buildSignalPath(signal, projectId)}`;
|
|
15100
15112
|
}
|
|
15101
|
-
function resolveExplicitSignalEndpoint(signal, endpoint) {
|
|
15113
|
+
function resolveExplicitSignalEndpoint(signal, endpoint, projectId) {
|
|
15102
15114
|
const normalizedEndpoint = trimTrailingSlashes(endpoint);
|
|
15103
15115
|
const invalidText = `CloudExporter ${signal}Endpoint must be a base origin like "https://collector.example.com" or a full ${signal} publish URL ending in "${SIGNAL_PUBLISH_SUFFIXES[signal]}".`;
|
|
15104
15116
|
try {
|
|
@@ -15109,7 +15121,7 @@ function resolveExplicitSignalEndpoint(signal, endpoint) {
|
|
|
15109
15121
|
const normalizedOrigin = trimTrailingSlashes(parsedEndpoint.origin);
|
|
15110
15122
|
const normalizedPathname = trimTrailingSlashes(parsedEndpoint.pathname);
|
|
15111
15123
|
if (!normalizedPathname || normalizedPathname === "/") {
|
|
15112
|
-
return buildSignalEndpoint(normalizedOrigin, signal);
|
|
15124
|
+
return buildSignalEndpoint(normalizedOrigin, signal, projectId);
|
|
15113
15125
|
}
|
|
15114
15126
|
if (normalizedPathname.endsWith(SIGNAL_PUBLISH_SUFFIXES[signal])) {
|
|
15115
15127
|
return `${normalizedOrigin}${normalizedPathname}`;
|
|
@@ -15152,7 +15164,12 @@ var CloudExporter = class extends BaseExporter {
|
|
|
15152
15164
|
inFlightFlushes = /* @__PURE__ */ new Set();
|
|
15153
15165
|
constructor(config2 = {}) {
|
|
15154
15166
|
super(config2);
|
|
15167
|
+
if (config2.projectId !== void 0 && !VALID_PROJECT_ID.test(config2.projectId)) {
|
|
15168
|
+
throw createInvalidProjectIdError(config2.projectId);
|
|
15169
|
+
}
|
|
15155
15170
|
const accessToken = config2.accessToken ?? process.env.MASTRA_CLOUD_ACCESS_TOKEN;
|
|
15171
|
+
const rawProjectId = config2.projectId ?? process.env.MASTRA_PROJECT_ID;
|
|
15172
|
+
const projectId = rawProjectId && VALID_PROJECT_ID.test(rawProjectId) ? rawProjectId : void 0;
|
|
15156
15173
|
if (!accessToken) {
|
|
15157
15174
|
this.setDisabled("MASTRA_CLOUD_ACCESS_TOKEN environment variable not set.");
|
|
15158
15175
|
}
|
|
@@ -15160,19 +15177,19 @@ var CloudExporter = class extends BaseExporter {
|
|
|
15160
15177
|
let baseEndpoint;
|
|
15161
15178
|
let tracesEndpoint;
|
|
15162
15179
|
if (tracesEndpointOverride) {
|
|
15163
|
-
tracesEndpoint = resolveExplicitSignalEndpoint("traces", tracesEndpointOverride);
|
|
15180
|
+
tracesEndpoint = resolveExplicitSignalEndpoint("traces", tracesEndpointOverride, projectId);
|
|
15164
15181
|
} else {
|
|
15165
15182
|
baseEndpoint = resolveBaseEndpoint(config2.endpoint ?? DEFAULT_CLOUD_ENDPOINT);
|
|
15166
|
-
tracesEndpoint = buildSignalEndpoint(baseEndpoint, "traces");
|
|
15183
|
+
tracesEndpoint = buildSignalEndpoint(baseEndpoint, "traces", projectId);
|
|
15167
15184
|
}
|
|
15168
15185
|
const resolveConfiguredSignalEndpoint = (signal, explicitEndpoint) => {
|
|
15169
15186
|
if (explicitEndpoint) {
|
|
15170
|
-
return resolveExplicitSignalEndpoint(signal, explicitEndpoint);
|
|
15187
|
+
return resolveExplicitSignalEndpoint(signal, explicitEndpoint, projectId);
|
|
15171
15188
|
}
|
|
15172
15189
|
if (tracesEndpointOverride) {
|
|
15173
15190
|
return deriveSignalEndpointFromTracesEndpoint(signal, tracesEndpoint);
|
|
15174
15191
|
}
|
|
15175
|
-
return buildSignalEndpoint(baseEndpoint, signal);
|
|
15192
|
+
return buildSignalEndpoint(baseEndpoint, signal, projectId);
|
|
15176
15193
|
};
|
|
15177
15194
|
this.cloudConfig = {
|
|
15178
15195
|
logger: this.logger,
|
|
@@ -15396,7 +15413,7 @@ var CloudExporter = class extends BaseExporter {
|
|
|
15396
15413
|
const options = {
|
|
15397
15414
|
method: "POST",
|
|
15398
15415
|
headers,
|
|
15399
|
-
body: JSON.stringify({ [
|
|
15416
|
+
body: JSON.stringify({ [SIGNAL_PUBLISH_SEGMENTS[signal]]: records })
|
|
15400
15417
|
};
|
|
15401
15418
|
await fetchWithRetry(endpointMap[signal], options, this.cloudConfig.maxRetries);
|
|
15402
15419
|
}
|