@mastra/observability 0.0.0-fix-thread-list-20251105222841 → 0.0.0-fix-ai-sdk-dependency-20251124104209
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 +71 -3
- package/README.md +18 -20
- package/dist/config.d.ts +268 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/default.d.ts.map +1 -1
- package/dist/index.cjs +101 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +98 -11
- package/dist/index.js.map +1 -1
- package/dist/instances/base.d.ts +1 -1
- package/dist/instances/index.d.ts +1 -1
- package/package.json +13 -11
package/dist/index.cjs
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var base = require('@mastra/core/base');
|
|
4
|
-
var logger = require('@mastra/core/logger');
|
|
5
4
|
var error = require('@mastra/core/error');
|
|
5
|
+
var logger = require('@mastra/core/logger');
|
|
6
|
+
var zod = require('zod');
|
|
6
7
|
var observability = require('@mastra/core/observability');
|
|
7
8
|
var utils = require('@mastra/core/utils');
|
|
8
9
|
var web = require('stream/web');
|
|
9
10
|
|
|
10
11
|
// src/default.ts
|
|
11
|
-
|
|
12
|
-
// src/config.ts
|
|
13
12
|
var SamplingStrategyType = /* @__PURE__ */ ((SamplingStrategyType2) => {
|
|
14
13
|
SamplingStrategyType2["ALWAYS"] = "always";
|
|
15
14
|
SamplingStrategyType2["NEVER"] = "never";
|
|
@@ -17,6 +16,66 @@ var SamplingStrategyType = /* @__PURE__ */ ((SamplingStrategyType2) => {
|
|
|
17
16
|
SamplingStrategyType2["CUSTOM"] = "custom";
|
|
18
17
|
return SamplingStrategyType2;
|
|
19
18
|
})(SamplingStrategyType || {});
|
|
19
|
+
var samplingStrategySchema = zod.z.discriminatedUnion("type", [
|
|
20
|
+
zod.z.object({
|
|
21
|
+
type: zod.z.literal("always" /* ALWAYS */)
|
|
22
|
+
}),
|
|
23
|
+
zod.z.object({
|
|
24
|
+
type: zod.z.literal("never" /* NEVER */)
|
|
25
|
+
}),
|
|
26
|
+
zod.z.object({
|
|
27
|
+
type: zod.z.literal("ratio" /* RATIO */),
|
|
28
|
+
probability: zod.z.number().min(0, "Probability must be between 0 and 1").max(1, "Probability must be between 0 and 1")
|
|
29
|
+
}),
|
|
30
|
+
zod.z.object({
|
|
31
|
+
type: zod.z.literal("custom" /* CUSTOM */),
|
|
32
|
+
sampler: zod.z.function().args(zod.z.any().optional()).returns(zod.z.boolean())
|
|
33
|
+
})
|
|
34
|
+
]);
|
|
35
|
+
var observabilityInstanceConfigSchema = zod.z.object({
|
|
36
|
+
name: zod.z.string().min(1, "Name is required"),
|
|
37
|
+
serviceName: zod.z.string().min(1, "Service name is required"),
|
|
38
|
+
sampling: samplingStrategySchema.optional(),
|
|
39
|
+
exporters: zod.z.array(zod.z.any()).optional(),
|
|
40
|
+
spanOutputProcessors: zod.z.array(zod.z.any()).optional(),
|
|
41
|
+
includeInternalSpans: zod.z.boolean().optional(),
|
|
42
|
+
requestContextKeys: zod.z.array(zod.z.string()).optional()
|
|
43
|
+
});
|
|
44
|
+
var observabilityConfigValueSchema = zod.z.object({
|
|
45
|
+
serviceName: zod.z.string().min(1, "Service name is required"),
|
|
46
|
+
sampling: samplingStrategySchema.optional(),
|
|
47
|
+
exporters: zod.z.array(zod.z.any()).optional(),
|
|
48
|
+
spanOutputProcessors: zod.z.array(zod.z.any()).optional(),
|
|
49
|
+
includeInternalSpans: zod.z.boolean().optional(),
|
|
50
|
+
requestContextKeys: zod.z.array(zod.z.string()).optional()
|
|
51
|
+
});
|
|
52
|
+
var observabilityRegistryConfigSchema = zod.z.object({
|
|
53
|
+
default: zod.z.object({
|
|
54
|
+
enabled: zod.z.boolean().optional()
|
|
55
|
+
}).optional().nullable(),
|
|
56
|
+
configs: zod.z.union([zod.z.record(zod.z.string(), zod.z.any()), zod.z.array(zod.z.any()), zod.z.null()]).optional(),
|
|
57
|
+
configSelector: zod.z.function().optional()
|
|
58
|
+
}).passthrough().refine(
|
|
59
|
+
(data) => {
|
|
60
|
+
const isDefaultEnabled = data.default?.enabled === true;
|
|
61
|
+
const hasConfigs = data.configs && typeof data.configs === "object" && !Array.isArray(data.configs) ? Object.keys(data.configs).length > 0 : false;
|
|
62
|
+
return !(isDefaultEnabled && hasConfigs);
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
message: 'Cannot specify both "default" (when enabled) and "configs". Use either default observability or custom configs, but not both.'
|
|
66
|
+
}
|
|
67
|
+
).refine(
|
|
68
|
+
(data) => {
|
|
69
|
+
const configCount = data.configs && typeof data.configs === "object" && !Array.isArray(data.configs) ? Object.keys(data.configs).length : 0;
|
|
70
|
+
if (configCount > 1 && !data.configSelector) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
message: 'A "configSelector" function is required when multiple configs are specified to determine which config to use.'
|
|
77
|
+
}
|
|
78
|
+
);
|
|
20
79
|
var BaseExporter = class {
|
|
21
80
|
/** Mastra logger instance */
|
|
22
81
|
logger;
|
|
@@ -94,10 +153,10 @@ var CloudExporter = class extends BaseExporter {
|
|
|
94
153
|
const accessToken = config.accessToken ?? process.env.MASTRA_CLOUD_ACCESS_TOKEN;
|
|
95
154
|
if (!accessToken) {
|
|
96
155
|
this.setDisabled(
|
|
97
|
-
"MASTRA_CLOUD_ACCESS_TOKEN environment variable not set
|
|
156
|
+
"MASTRA_CLOUD_ACCESS_TOKEN environment variable not set.\n\u{1F680} Sign up at https://cloud.mastra.ai to see your AI traces online and obtain your access token."
|
|
98
157
|
);
|
|
99
158
|
}
|
|
100
|
-
const endpoint = config.endpoint ?? process.env.
|
|
159
|
+
const endpoint = config.endpoint ?? process.env.MASTRA_CLOUD_TRACES_ENDPOINT ?? "https://api.mastra.ai/ai/spans/publish";
|
|
101
160
|
this.config = {
|
|
102
161
|
logger: this.logger,
|
|
103
162
|
logLevel: config.logLevel ?? logger.LogLevel.INFO,
|
|
@@ -1589,7 +1648,7 @@ var BaseObservabilityInstance = class extends base.MastraBase {
|
|
|
1589
1648
|
// Utility Methods
|
|
1590
1649
|
// ============================================================================
|
|
1591
1650
|
/**
|
|
1592
|
-
* Check if
|
|
1651
|
+
* Check if a trace should be sampled
|
|
1593
1652
|
*/
|
|
1594
1653
|
shouldSample(options) {
|
|
1595
1654
|
const { sampling } = this.config;
|
|
@@ -1996,10 +2055,38 @@ var Observability = class extends base.MastraBase {
|
|
|
1996
2055
|
if (config === void 0) {
|
|
1997
2056
|
config = {};
|
|
1998
2057
|
}
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2058
|
+
const validationResult = observabilityRegistryConfigSchema.safeParse(config);
|
|
2059
|
+
if (!validationResult.success) {
|
|
2060
|
+
const errorMessages = validationResult.error.errors.map((err) => `${err.path.join(".") || "config"}: ${err.message}`).join("; ");
|
|
2061
|
+
throw new error.MastraError({
|
|
2062
|
+
id: "OBSERVABILITY_INVALID_CONFIG",
|
|
2063
|
+
text: `Invalid observability configuration: ${errorMessages}`,
|
|
2064
|
+
domain: error.ErrorDomain.MASTRA_OBSERVABILITY,
|
|
2065
|
+
category: error.ErrorCategory.USER,
|
|
2066
|
+
details: {
|
|
2067
|
+
validationErrors: errorMessages
|
|
2068
|
+
}
|
|
2069
|
+
});
|
|
2070
|
+
}
|
|
2071
|
+
if (config.configs) {
|
|
2072
|
+
for (const [name, configValue] of Object.entries(config.configs)) {
|
|
2073
|
+
if (!isInstance(configValue)) {
|
|
2074
|
+
const configValidation = observabilityConfigValueSchema.safeParse(configValue);
|
|
2075
|
+
if (!configValidation.success) {
|
|
2076
|
+
const errorMessages = configValidation.error.errors.map((err) => `${err.path.join(".")}: ${err.message}`).join("; ");
|
|
2077
|
+
throw new error.MastraError({
|
|
2078
|
+
id: "OBSERVABILITY_INVALID_INSTANCE_CONFIG",
|
|
2079
|
+
text: `Invalid configuration for observability instance '${name}': ${errorMessages}`,
|
|
2080
|
+
domain: error.ErrorDomain.MASTRA_OBSERVABILITY,
|
|
2081
|
+
category: error.ErrorCategory.USER,
|
|
2082
|
+
details: {
|
|
2083
|
+
instanceName: name,
|
|
2084
|
+
validationErrors: errorMessages
|
|
2085
|
+
}
|
|
2086
|
+
});
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2003
2090
|
}
|
|
2004
2091
|
if (config.default?.enabled) {
|
|
2005
2092
|
const defaultInstance = new DefaultObservabilityInstance({
|
|
@@ -2098,5 +2185,9 @@ exports.Observability = Observability;
|
|
|
2098
2185
|
exports.SamplingStrategyType = SamplingStrategyType;
|
|
2099
2186
|
exports.SensitiveDataFilter = SensitiveDataFilter;
|
|
2100
2187
|
exports.deepClean = deepClean;
|
|
2188
|
+
exports.observabilityConfigValueSchema = observabilityConfigValueSchema;
|
|
2189
|
+
exports.observabilityInstanceConfigSchema = observabilityInstanceConfigSchema;
|
|
2190
|
+
exports.observabilityRegistryConfigSchema = observabilityRegistryConfigSchema;
|
|
2191
|
+
exports.samplingStrategySchema = samplingStrategySchema;
|
|
2101
2192
|
//# sourceMappingURL=index.cjs.map
|
|
2102
2193
|
//# sourceMappingURL=index.cjs.map
|