@mastra/observability 0.0.0-main-test-05-11-2025-2-20251106022801 → 0.0.0-main-test-05-11-2025-2-20251106025330
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 +4 -2
- 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 +98 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +95 -8
- package/dist/index.js.map +1 -1
- package/package.json +8 -6
package/dist/index.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { MastraBase } from '@mastra/core/base';
|
|
2
|
-
import { ConsoleLogger, LogLevel, RegisteredLogger } from '@mastra/core/logger';
|
|
3
2
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
3
|
+
import { ConsoleLogger, LogLevel, RegisteredLogger } from '@mastra/core/logger';
|
|
4
|
+
import { z } from 'zod';
|
|
4
5
|
import { TracingEventType, SpanType, InternalSpans } from '@mastra/core/observability';
|
|
5
6
|
import { fetchWithRetry, getNestedValue, setNestedValue } from '@mastra/core/utils';
|
|
6
7
|
import { TransformStream } from 'stream/web';
|
|
7
8
|
|
|
8
9
|
// src/default.ts
|
|
9
|
-
|
|
10
|
-
// src/config.ts
|
|
11
10
|
var SamplingStrategyType = /* @__PURE__ */ ((SamplingStrategyType2) => {
|
|
12
11
|
SamplingStrategyType2["ALWAYS"] = "always";
|
|
13
12
|
SamplingStrategyType2["NEVER"] = "never";
|
|
@@ -15,6 +14,66 @@ var SamplingStrategyType = /* @__PURE__ */ ((SamplingStrategyType2) => {
|
|
|
15
14
|
SamplingStrategyType2["CUSTOM"] = "custom";
|
|
16
15
|
return SamplingStrategyType2;
|
|
17
16
|
})(SamplingStrategyType || {});
|
|
17
|
+
var samplingStrategySchema = z.discriminatedUnion("type", [
|
|
18
|
+
z.object({
|
|
19
|
+
type: z.literal("always" /* ALWAYS */)
|
|
20
|
+
}),
|
|
21
|
+
z.object({
|
|
22
|
+
type: z.literal("never" /* NEVER */)
|
|
23
|
+
}),
|
|
24
|
+
z.object({
|
|
25
|
+
type: z.literal("ratio" /* RATIO */),
|
|
26
|
+
probability: z.number().min(0, "Probability must be between 0 and 1").max(1, "Probability must be between 0 and 1")
|
|
27
|
+
}),
|
|
28
|
+
z.object({
|
|
29
|
+
type: z.literal("custom" /* CUSTOM */),
|
|
30
|
+
sampler: z.function().args(z.any().optional()).returns(z.boolean())
|
|
31
|
+
})
|
|
32
|
+
]);
|
|
33
|
+
var observabilityInstanceConfigSchema = z.object({
|
|
34
|
+
name: z.string().min(1, "Name is required"),
|
|
35
|
+
serviceName: z.string().min(1, "Service name is required"),
|
|
36
|
+
sampling: samplingStrategySchema.optional(),
|
|
37
|
+
exporters: z.array(z.any()).optional(),
|
|
38
|
+
spanOutputProcessors: z.array(z.any()).optional(),
|
|
39
|
+
includeInternalSpans: z.boolean().optional(),
|
|
40
|
+
requestContextKeys: z.array(z.string()).optional()
|
|
41
|
+
});
|
|
42
|
+
var observabilityConfigValueSchema = z.object({
|
|
43
|
+
serviceName: z.string().min(1, "Service name is required"),
|
|
44
|
+
sampling: samplingStrategySchema.optional(),
|
|
45
|
+
exporters: z.array(z.any()).optional(),
|
|
46
|
+
spanOutputProcessors: z.array(z.any()).optional(),
|
|
47
|
+
includeInternalSpans: z.boolean().optional(),
|
|
48
|
+
requestContextKeys: z.array(z.string()).optional()
|
|
49
|
+
});
|
|
50
|
+
var observabilityRegistryConfigSchema = z.object({
|
|
51
|
+
default: z.object({
|
|
52
|
+
enabled: z.boolean().optional()
|
|
53
|
+
}).optional().nullable(),
|
|
54
|
+
configs: z.union([z.record(z.string(), z.any()), z.array(z.any()), z.null()]).optional(),
|
|
55
|
+
configSelector: z.function().optional()
|
|
56
|
+
}).passthrough().refine(
|
|
57
|
+
(data) => {
|
|
58
|
+
const isDefaultEnabled = data.default?.enabled === true;
|
|
59
|
+
const hasConfigs = data.configs && typeof data.configs === "object" && !Array.isArray(data.configs) ? Object.keys(data.configs).length > 0 : false;
|
|
60
|
+
return !(isDefaultEnabled && hasConfigs);
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
message: 'Cannot specify both "default" (when enabled) and "configs". Use either default observability or custom configs, but not both.'
|
|
64
|
+
}
|
|
65
|
+
).refine(
|
|
66
|
+
(data) => {
|
|
67
|
+
const configCount = data.configs && typeof data.configs === "object" && !Array.isArray(data.configs) ? Object.keys(data.configs).length : 0;
|
|
68
|
+
if (configCount > 1 && !data.configSelector) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
message: 'A "configSelector" function is required when multiple configs are specified to determine which config to use.'
|
|
75
|
+
}
|
|
76
|
+
);
|
|
18
77
|
var BaseExporter = class {
|
|
19
78
|
/** Mastra logger instance */
|
|
20
79
|
logger;
|
|
@@ -1994,10 +2053,38 @@ var Observability = class extends MastraBase {
|
|
|
1994
2053
|
if (config === void 0) {
|
|
1995
2054
|
config = {};
|
|
1996
2055
|
}
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2056
|
+
const validationResult = observabilityRegistryConfigSchema.safeParse(config);
|
|
2057
|
+
if (!validationResult.success) {
|
|
2058
|
+
const errorMessages = validationResult.error.errors.map((err) => `${err.path.join(".") || "config"}: ${err.message}`).join("; ");
|
|
2059
|
+
throw new MastraError({
|
|
2060
|
+
id: "OBSERVABILITY_INVALID_CONFIG",
|
|
2061
|
+
text: `Invalid observability configuration: ${errorMessages}`,
|
|
2062
|
+
domain: ErrorDomain.MASTRA_OBSERVABILITY,
|
|
2063
|
+
category: ErrorCategory.USER,
|
|
2064
|
+
details: {
|
|
2065
|
+
validationErrors: errorMessages
|
|
2066
|
+
}
|
|
2067
|
+
});
|
|
2068
|
+
}
|
|
2069
|
+
if (config.configs) {
|
|
2070
|
+
for (const [name, configValue] of Object.entries(config.configs)) {
|
|
2071
|
+
if (!isInstance(configValue)) {
|
|
2072
|
+
const configValidation = observabilityConfigValueSchema.safeParse(configValue);
|
|
2073
|
+
if (!configValidation.success) {
|
|
2074
|
+
const errorMessages = configValidation.error.errors.map((err) => `${err.path.join(".")}: ${err.message}`).join("; ");
|
|
2075
|
+
throw new MastraError({
|
|
2076
|
+
id: "OBSERVABILITY_INVALID_INSTANCE_CONFIG",
|
|
2077
|
+
text: `Invalid configuration for observability instance '${name}': ${errorMessages}`,
|
|
2078
|
+
domain: ErrorDomain.MASTRA_OBSERVABILITY,
|
|
2079
|
+
category: ErrorCategory.USER,
|
|
2080
|
+
details: {
|
|
2081
|
+
instanceName: name,
|
|
2082
|
+
validationErrors: errorMessages
|
|
2083
|
+
}
|
|
2084
|
+
});
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2001
2088
|
}
|
|
2002
2089
|
if (config.default?.enabled) {
|
|
2003
2090
|
const defaultInstance = new DefaultObservabilityInstance({
|
|
@@ -2082,6 +2169,6 @@ var Observability = class extends MastraBase {
|
|
|
2082
2169
|
}
|
|
2083
2170
|
};
|
|
2084
2171
|
|
|
2085
|
-
export { BaseExporter, BaseObservabilityInstance, BaseSpan, CloudExporter, ConsoleExporter, DefaultExporter, DefaultObservabilityInstance, DefaultSpan, ModelSpanTracker, NoOpSpan, Observability, SamplingStrategyType, SensitiveDataFilter, deepClean };
|
|
2172
|
+
export { BaseExporter, BaseObservabilityInstance, BaseSpan, CloudExporter, ConsoleExporter, DefaultExporter, DefaultObservabilityInstance, DefaultSpan, ModelSpanTracker, NoOpSpan, Observability, SamplingStrategyType, SensitiveDataFilter, deepClean, observabilityConfigValueSchema, observabilityInstanceConfigSchema, observabilityRegistryConfigSchema, samplingStrategySchema };
|
|
2086
2173
|
//# sourceMappingURL=index.js.map
|
|
2087
2174
|
//# sourceMappingURL=index.js.map
|