@mastra/observability 0.0.0-studio-cli-20260504022012 → 0.0.0-sugared-octave-20261030170102
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/LICENSE.md +6 -4
- package/README.md +15 -83
- package/dist/bus/base.d.ts +1 -1
- package/dist/bus/base.d.ts.map +1 -1
- package/dist/bus/observability-bus.d.ts +21 -4
- package/dist/bus/observability-bus.d.ts.map +1 -1
- package/dist/bus/route-event.d.ts +8 -1
- package/dist/bus/route-event.d.ts.map +1 -1
- package/dist/client/id.d.ts +2 -0
- package/dist/client/id.d.ts.map +1 -0
- package/dist/client/index.d.ts +15 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/otlp.d.ts +72 -0
- package/dist/client/otlp.d.ts.map +1 -0
- package/dist/client/proxy.d.ts +44 -0
- package/dist/client/proxy.d.ts.map +1 -0
- package/dist/client/w3c.d.ts +35 -0
- package/dist/client/w3c.d.ts.map +1 -0
- package/dist/config.d.ts +40 -17
- package/dist/config.d.ts.map +1 -1
- package/dist/context/logger.d.ts.map +1 -1
- package/dist/context/metrics.d.ts.map +1 -1
- package/dist/default.d.ts +34 -3
- package/dist/default.d.ts.map +1 -1
- package/dist/exporters/auth-failure-cooldown.d.ts +25 -0
- package/dist/exporters/auth-failure-cooldown.d.ts.map +1 -0
- package/dist/exporters/base.d.ts.map +1 -1
- package/dist/exporters/cloud.d.ts +13 -0
- package/dist/exporters/cloud.d.ts.map +1 -1
- package/dist/exporters/console.d.ts.map +1 -1
- package/dist/exporters/default.d.ts +22 -1
- package/dist/exporters/default.d.ts.map +1 -1
- package/dist/exporters/event-buffer.d.ts +9 -4
- package/dist/exporters/event-buffer.d.ts.map +1 -1
- package/dist/exporters/index.d.ts +2 -0
- package/dist/exporters/index.d.ts.map +1 -1
- package/dist/exporters/mastra-platform.d.ts +92 -0
- package/dist/exporters/mastra-platform.d.ts.map +1 -0
- package/dist/exporters/mastra-storage.d.ts +111 -0
- package/dist/exporters/mastra-storage.d.ts.map +1 -0
- package/dist/exporters/span-previews.d.ts +4 -0
- package/dist/exporters/span-previews.d.ts.map +1 -0
- package/dist/exporters/test.d.ts.map +1 -1
- package/dist/exporters/tracking.d.ts +7 -0
- package/dist/exporters/tracking.d.ts.map +1 -1
- package/dist/features.d.ts +39 -0
- package/dist/features.d.ts.map +1 -0
- package/dist/ids.d.ts +66 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/index.cjs +10660 -20970
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10617 -20959
- package/dist/index.js.map +1 -1
- package/dist/instances/base.d.ts +77 -4
- package/dist/instances/base.d.ts.map +1 -1
- package/dist/instances/default.d.ts.map +1 -1
- package/dist/instances/platform-policy.d.ts +4 -0
- package/dist/instances/platform-policy.d.ts.map +1 -0
- package/dist/metrics/auto-extract.d.ts +12 -2
- package/dist/metrics/auto-extract.d.ts.map +1 -1
- package/dist/metrics/cardinality.d.ts.map +1 -1
- package/dist/metrics/estimator.d.ts.map +1 -1
- package/dist/metrics/models-dev.d.ts +26 -0
- package/dist/metrics/models-dev.d.ts.map +1 -0
- package/dist/metrics/pricing-data.json +74010 -0
- package/dist/metrics/pricing-model.d.ts +0 -2
- package/dist/metrics/pricing-model.d.ts.map +1 -1
- package/dist/metrics/pricing-registry.d.ts +24 -3
- package/dist/metrics/pricing-registry.d.ts.map +1 -1
- package/dist/metrics/types.d.ts +31 -20
- package/dist/metrics/types.d.ts.map +1 -1
- package/dist/metrics/usage-metrics.d.ts.map +1 -1
- package/dist/model-id.d.ts +3 -0
- package/dist/model-id.d.ts.map +1 -0
- package/dist/model-tracing.d.ts +67 -9
- package/dist/model-tracing.d.ts.map +1 -1
- package/dist/recorded.d.ts.map +1 -1
- package/dist/registry.d.ts +4 -0
- package/dist/registry.d.ts.map +1 -1
- package/dist/span_processors/sensitive-data-filter.d.ts +26 -5
- package/dist/span_processors/sensitive-data-filter.d.ts.map +1 -1
- package/dist/spans/base.d.ts +103 -11
- package/dist/spans/base.d.ts.map +1 -1
- package/dist/spans/default.d.ts.map +1 -1
- package/dist/spans/metadata.d.ts +30 -0
- package/dist/spans/metadata.d.ts.map +1 -0
- package/dist/spans/no-op.d.ts.map +1 -1
- package/dist/spans/serialization.d.ts +6 -5
- package/dist/spans/serialization.d.ts.map +1 -1
- package/dist/usage.d.ts +28 -0
- package/dist/usage.d.ts.map +1 -1
- package/package.json +20 -18
- package/CHANGELOG.md +0 -2177
- package/dist/metrics/pricing-data.jsonl +0 -4966
package/LICENSE.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
Portions of this software are licensed as follows:
|
|
2
2
|
|
|
3
|
-
- All content that resides under any directory named
|
|
3
|
+
- All content that resides under any directory named `ee/` within this
|
|
4
4
|
repository, including but not limited to:
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
|
|
5
|
+
- `@mastra/core/auth/ee`
|
|
6
|
+
- `@mastra/core/agent-builder/ee`
|
|
7
|
+
- `@mastra/editor/ee`
|
|
8
|
+
|
|
9
|
+
is licensed under the license defined in [`ee/LICENSE`](https://github.com/mastra-ai/mastra/blob/main/ee/LICENSE).
|
|
8
10
|
|
|
9
11
|
- All third-party components incorporated into the Mastra Software are
|
|
10
12
|
licensed under the original license provided by the owner of the
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mastra/observability
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Monitor Mastra agents, workflows, tools, and model calls with hierarchical traces, automatically extracted metrics, and structured logs correlated to the active trace.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,108 +8,40 @@ Tracing, metrics, and structured logging for AI operations in Mastra.
|
|
|
8
8
|
npm install @mastra/observability
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Usage
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
14
|
import { Mastra } from '@mastra/core';
|
|
15
|
-
import { Observability,
|
|
15
|
+
import { Observability, MastraStorageExporter, MastraPlatformExporter } from '@mastra/observability';
|
|
16
16
|
|
|
17
17
|
export const mastra = new Mastra({
|
|
18
18
|
observability: new Observability({
|
|
19
19
|
configs: {
|
|
20
20
|
default: {
|
|
21
21
|
serviceName: 'my-app',
|
|
22
|
-
exporters: [
|
|
23
|
-
new DefaultExporter(), // Persists traces for Mastra Studio
|
|
24
|
-
new CloudExporter(), // Sends to Mastra platform
|
|
25
|
-
],
|
|
26
|
-
spanOutputProcessors: [new SensitiveDataFilter()],
|
|
22
|
+
exporters: [new MastraStorageExporter(), new MastraPlatformExporter()],
|
|
27
23
|
},
|
|
28
24
|
},
|
|
29
25
|
}),
|
|
30
26
|
});
|
|
31
27
|
```
|
|
32
28
|
|
|
33
|
-
##
|
|
34
|
-
|
|
35
|
-
- **Auto-instrumentation** - Traces agent runs, LLM calls, tool executions, and workflows
|
|
36
|
-
- **Pluggable Exporters** - Exporters for Studio, plus integrations for Arize, Braintrust, Langfuse, LangSmith, and OpenTelemetry
|
|
37
|
-
- **Sampling Strategies** - Always, ratio-based, or custom sampling
|
|
38
|
-
- **Span Processors** - Transform or filter span data before export
|
|
39
|
-
- **OpenTelemetry Compatible** - Standard trace/span ID formats for integration
|
|
40
|
-
|
|
41
|
-
## Architecture
|
|
42
|
-
|
|
43
|
-
### ObservabilityBus
|
|
44
|
-
|
|
45
|
-
Central event router that dispatches tracing, metric, and log events to registered exporters. All handler promises are tracked for reliable flush and shutdown — no events are silently dropped.
|
|
46
|
-
|
|
47
|
-
Exporters register via `registerExporter()` and can optionally implement `onLogEvent` and `onMetricEvent` handlers alongside the existing `exportTracingEvent`.
|
|
48
|
-
|
|
49
|
-
### Auto-extracted metrics
|
|
50
|
-
|
|
51
|
-
Metrics are automatically extracted from span lifecycle events by `AutoExtractedMetrics`:
|
|
52
|
-
|
|
53
|
-
- `mastra_agent_duration_ms`
|
|
54
|
-
- `mastra_tool_duration_ms`
|
|
55
|
-
- `mastra_workflow_duration_ms`
|
|
56
|
-
- `mastra_model_duration_ms`
|
|
57
|
-
- `mastra_model_total_input_tokens` / `mastra_model_total_output_tokens`
|
|
58
|
-
- `mastra_model_input_text_tokens` / `mastra_model_input_cache_read_tokens` / `mastra_model_input_cache_write_tokens` / `mastra_model_input_audio_tokens` / `mastra_model_input_image_tokens`
|
|
59
|
-
- `mastra_model_output_text_tokens` / `mastra_model_output_reasoning_tokens` / `mastra_model_output_audio_tokens` / `mastra_model_output_image_tokens`
|
|
60
|
-
|
|
61
|
-
Auto-extracted metrics carry labels: `entity_type`, `entity_name`, `status`, plus `model` and `provider` on model generation spans.
|
|
62
|
-
|
|
63
|
-
### Structured logging
|
|
64
|
-
|
|
65
|
-
`LoggerContextImpl` emits log events with automatic trace correlation (traceId, spanId), inherited tags, and entity metadata. Supports minimum log level filtering (debug/info/warn/error/fatal).
|
|
66
|
-
|
|
67
|
-
### Metrics context
|
|
68
|
-
|
|
69
|
-
`MetricsContextImpl` provides counter, gauge, and histogram instruments. All labels pass through a `CardinalityFilter` that blocks high-cardinality keys (trace_id, user_id, etc.) to protect metric backends.
|
|
70
|
-
|
|
71
|
-
## Span Types
|
|
72
|
-
|
|
73
|
-
- `WORKFLOW_RUN` - Workflow execution
|
|
74
|
-
- `WORKFLOW_STEP` - Individual workflow step
|
|
75
|
-
- `AGENT_RUN` - Agent processing
|
|
76
|
-
- `MODEL_GENERATION` - LLM API calls
|
|
77
|
-
- `TOOL_CALL` - Tool execution
|
|
78
|
-
- `MCP_TOOL_CALL` - MCP tool execution
|
|
79
|
-
- `PROCESSOR_RUN` - Processor execution
|
|
80
|
-
- `GENERIC` - Custom operations
|
|
81
|
-
|
|
82
|
-
## Metrics Labels
|
|
29
|
+
## Documentation
|
|
83
30
|
|
|
84
|
-
|
|
31
|
+
`Observability` instruments agent runs, model generations, tool and MCP calls, processor execution, workflow runs, and workflow steps. Each configured observability instance has its own service name, exporters, sampling strategy, and span processors.
|
|
85
32
|
|
|
86
|
-
|
|
87
|
-
| ------------- | -------------------------------------------------------------------- | --------------------------- |
|
|
88
|
-
| `entity_type` | What is being measured (e.g., `agent`, `tool`, `workflow_run`) | Small enum (~9 values) |
|
|
89
|
-
| `entity_name` | Name of the entity (e.g., `researcher`, `search`) | Bounded by defined entities |
|
|
90
|
-
| `model` | LLM model ID (only on model generation spans) | Bounded by LLM providers |
|
|
91
|
-
| `provider` | LLM provider (only on model generation spans) | Bounded by LLM providers |
|
|
92
|
-
| `status` | Outcome of the operation (`ok` or `error`), on `_ended` metrics only | 2 values |
|
|
33
|
+
Exporters receive tracing events through the central observability bus. `MastraStorageExporter` persists them to the configured Mastra storage so Studio can query them, while `MastraPlatformExporter` sends them to Mastra Platform. Additional packages provide exporters for services such as Arize, Braintrust, Langfuse, LangSmith, Sentry, and OpenTelemetry-compatible backends.
|
|
93
34
|
|
|
94
|
-
|
|
35
|
+
A `SensitiveDataFilter` output processor is enabled by default and redacts common secrets before spans reach exporters. Set `sensitiveDataFilter: false` to disable it, or provide filter options to customize its behavior. Sampling can retain every trace, use a ratio, or apply application-specific logic.
|
|
95
36
|
|
|
96
|
-
|
|
37
|
+
The package automatically derives duration, status, model token, and cache token metrics from span lifecycle events. Structured logs inherit trace and span IDs, tags, and entity metadata, while metric labels pass through cardinality filtering to prevent user IDs, trace IDs, and other unbounded values from overwhelming metrics backends.
|
|
97
38
|
|
|
98
|
-
|
|
99
|
-
| -------------- | --------------------------------------------------------------------------- | --------------------------- |
|
|
100
|
-
| `parent_type` | Entity type of the nearest parent | Same small enum |
|
|
101
|
-
| `parent_name` | Name of the nearest parent entity | Bounded by defined entities |
|
|
102
|
-
| `root_type` | Entity type of the outermost ancestor (only set when different from parent) | Same small enum |
|
|
103
|
-
| `root_name` | Name of the outermost ancestor entity | Bounded by defined entities |
|
|
104
|
-
| `service_name` | Service name from observability config | Single value per deployment |
|
|
39
|
+
- [Observability documentation](https://mastra.ai/docs/studio/observability)
|
|
105
40
|
|
|
106
|
-
|
|
41
|
+
## Changelog
|
|
107
42
|
|
|
108
|
-
|
|
109
|
-
- **Why is this tool slow only sometimes?** → group by `parent_name`
|
|
110
|
-
- **What's the total cost of this user-facing flow?** → group by `root_name`
|
|
111
|
-
- **Which model is cheapest for this agent?** → group by `model` where `entity_name=X`
|
|
43
|
+
See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/observability/mastra/CHANGELOG.md) for version history and release notes.
|
|
112
44
|
|
|
113
|
-
##
|
|
45
|
+
## Support
|
|
114
46
|
|
|
115
|
-
|
|
47
|
+
We have an [open community Discord](https://discord.gg/mastra-ai). Come and say hello and let us know if you have any questions or need any help getting things running.
|
package/dist/bus/base.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - Clean shutdown flushes then clears subscribers
|
|
9
9
|
*
|
|
10
10
|
* Buffering/batching is intentionally NOT done here — individual exporters
|
|
11
|
-
* own their own batching strategy
|
|
11
|
+
* own their own batching strategy.
|
|
12
12
|
*/
|
|
13
13
|
import { MastraBase } from '@mastra/core/base';
|
|
14
14
|
import type { ObservabilityEventBus } from '@mastra/core/observability';
|
package/dist/bus/base.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/bus/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE,qBAAa,yBAAyB,CAAC,MAAM,CAAE,SAAQ,UAAW,YAAW,qBAAqB,CAAC,MAAM,CAAC;IACxG,OAAO,CAAC,WAAW,CAA2C;IAE9D,yEAAyE;IACzE,OAAO,CAAC,kBAAkB,CAAiC;
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/bus/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE,qBAAa,yBAAyB,CAAC,MAAM,CAAE,SAAQ,UAAW,YAAW,qBAAqB,CAAC,MAAM,CAAC;IACxG,OAAO,CAAC,WAAW,CAA2C;IAE9D,yEAAyE;IACzE,OAAO,CAAC,kBAAkB,CAAiC;IAE3D,YAAY,EAAE,IAAI,EAAE,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO,EAE3C;IAED;;;;;OAKG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAiBxB;IAED;;;;;OAKG;IACH,SAAS,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI,CAKtD;IAED,iGAAiG;IACjG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAK;IAEjD,2EAA2E;IACrE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAa3B;IAED,0DAA0D;IACpD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAG9B;CACF"}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* Handler presence = signal support. If a handler does not implement a method,
|
|
10
10
|
* events of that type are silently skipped for that handler.
|
|
11
11
|
*/
|
|
12
|
-
import type { ObservabilityExporter, ObservabilityBridge, ObservabilityEvent, SerializationOptions } from '@mastra/core/observability';
|
|
12
|
+
import type { ObservabilityExporter, ObservabilityBridge, ObservabilityEvent, ObservabilityDropEvent, SerializationOptions } from '@mastra/core/observability';
|
|
13
13
|
import { BaseObservabilityEventBus } from './base.js';
|
|
14
14
|
/**
|
|
15
15
|
* Unified event bus for all observability signals (tracing, logs, metrics, scores, feedback).
|
|
@@ -20,6 +20,8 @@ export declare class ObservabilityBus extends BaseObservabilityEventBus<Observab
|
|
|
20
20
|
private bridge?;
|
|
21
21
|
/** In-flight handler promises from routeToHandler. Self-cleaning via .finally(). */
|
|
22
22
|
private pendingHandlers;
|
|
23
|
+
private handlerBufferFlushDepth;
|
|
24
|
+
private dropEventsEmittedDuringHandlerFlush;
|
|
23
25
|
/** Resolved deepClean options applied to non-tracing events before fan-out. */
|
|
24
26
|
private deepCleanOptions;
|
|
25
27
|
constructor(opts?: {
|
|
@@ -69,13 +71,24 @@ export declare class ObservabilityBus extends BaseObservabilityEventBus<Observab
|
|
|
69
71
|
* and can be drained via flush().
|
|
70
72
|
*/
|
|
71
73
|
emit(event: ObservabilityEvent): void;
|
|
74
|
+
/**
|
|
75
|
+
* Emit exporter pipeline drop events to exporters and the bridge.
|
|
76
|
+
*
|
|
77
|
+
* Drop events describe exporter health, not user observability data, so they
|
|
78
|
+
* are intentionally not delivered to generic event-bus subscribers.
|
|
79
|
+
*/
|
|
80
|
+
emitDropEvent(event: ObservabilityDropEvent): void;
|
|
72
81
|
/**
|
|
73
82
|
* Track an async handler promise so flush() can await it.
|
|
74
83
|
* No-ops for sync (void) results.
|
|
75
84
|
*/
|
|
76
85
|
private trackPromise;
|
|
86
|
+
/** Await in-flight routed handler promises, draining until empty. */
|
|
87
|
+
private drainPendingHandlers;
|
|
88
|
+
/** Drain exporter and bridge SDK-internal buffers. */
|
|
89
|
+
private flushHandlerBuffers;
|
|
77
90
|
/**
|
|
78
|
-
*
|
|
91
|
+
* Multi-phase flush to ensure all observability data is fully exported.
|
|
79
92
|
*
|
|
80
93
|
* **Phase 1 — Delivery:** Await all in-flight handler promises (exporters,
|
|
81
94
|
* bridge, and base-class subscribers). After this resolves, all event data
|
|
@@ -83,8 +96,12 @@ export declare class ObservabilityBus extends BaseObservabilityEventBus<Observab
|
|
|
83
96
|
*
|
|
84
97
|
* **Phase 2 — Buffer drain:** Call flush() on each exporter and bridge to
|
|
85
98
|
* drain their SDK-internal buffers (e.g., OTEL BatchSpanProcessor, Langfuse
|
|
86
|
-
* client queue). Phases are sequential —
|
|
87
|
-
*
|
|
99
|
+
* client queue). Phases are sequential — buffer drains must not start until
|
|
100
|
+
* delivery completes, otherwise exporters would flush empty buffers.
|
|
101
|
+
*
|
|
102
|
+
* Exporter flushes can emit drop events. When that happens, flush loops
|
|
103
|
+
* through delivery and buffer drain again so alerting integrations that buffer
|
|
104
|
+
* drop notifications are drained before returning.
|
|
88
105
|
*/
|
|
89
106
|
flush(): Promise<void>;
|
|
90
107
|
/** Flush all pending events and exporter buffers, then clear subscribers. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observability-bus.d.ts","sourceRoot":"","sources":["../../src/bus/observability-bus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,QAAQ,CAAC;AAsCnD;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,yBAAyB,CAAC,kBAAkB,CAAC;IACjF,OAAO,CAAC,SAAS,CAA+B;IAChD,OAAO,CAAC,MAAM,CAAC,CAAsB;IAErC,oFAAoF;IACpF,OAAO,CAAC,eAAe,CAAiC;IAExD,+EAA+E;IAC/E,OAAO,CAAC,gBAAgB,CAAmB;
|
|
1
|
+
{"version":3,"file":"observability-bus.d.ts","sourceRoot":"","sources":["../../src/bus/observability-bus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACrB,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,QAAQ,CAAC;AAsCnD;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,yBAAyB,CAAC,kBAAkB,CAAC;IACjF,OAAO,CAAC,SAAS,CAA+B;IAChD,OAAO,CAAC,MAAM,CAAC,CAAsB;IAErC,oFAAoF;IACpF,OAAO,CAAC,eAAe,CAAiC;IAExD,OAAO,CAAC,uBAAuB,CAAK;IACpC,OAAO,CAAC,mCAAmC,CAAK;IAEhD,+EAA+E;IAC/E,OAAO,CAAC,gBAAgB,CAAmB;IAE3C,YAAY,IAAI,CAAC,EAAE;QAAE,oBAAoB,CAAC,EAAE,oBAAoB,CAAA;KAAE,EAGjE;IAED;;;;;OAKG;IACH,gBAAgB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,IAAI,CAKtD;IAED;;;;;OAKG;IACH,kBAAkB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,OAAO,CAO3D;IAED;;OAEG;IACH,YAAY,IAAI,SAAS,qBAAqB,EAAE,CAE/C;IAED;;;;;;OAMG;IACH,cAAc,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,CAKhD;IAED;;;;OAIG;IACH,gBAAgB,IAAI,OAAO,CAM1B;IAED;;OAEG;IACH,SAAS,IAAI,mBAAmB,GAAG,SAAS,CAE3C;IAED;;;;;;OAMG;IACH,IAAI,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAkBpC;IAED;;;;;OAKG;IACH,aAAa,CAAC,KAAK,EAAE,sBAAsB,GAAG,IAAI,CAYjD;IAED;;;OAGG;IACH,OAAO,CAAC,YAAY;IAQpB,qEAAqE;YACvD,oBAAoB;IAoBlC,sDAAsD;YACxC,mBAAmB;IAiBjC;;;;;;;;;;;;;;;OAeG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAmB3B;IAED,6EAA6E;IACvE,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAG9B;CACF"}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* the ObservabilityBus (for exporters) and BaseObservabilityInstance (for bridges).
|
|
8
8
|
*/
|
|
9
9
|
import type { IMastraLogger } from '@mastra/core/logger';
|
|
10
|
-
import type { ObservabilityEvents, ObservabilityEvent } from '@mastra/core/observability';
|
|
10
|
+
import type { ObservabilityEvents, ObservabilityEvent, ObservabilityDropEvent } from '@mastra/core/observability';
|
|
11
11
|
/**
|
|
12
12
|
* Any handler that can receive routed observability events.
|
|
13
13
|
* Both ObservabilityExporter and ObservabilityBridge extend
|
|
@@ -28,4 +28,11 @@ export type ObservabilityHandler = ObservabilityEvents & {
|
|
|
28
28
|
* Sync throws are caught so one failing handler doesn't break others.
|
|
29
29
|
*/
|
|
30
30
|
export declare function routeToHandler(handler: ObservabilityHandler, event: ObservabilityEvent, logger: IMastraLogger): void | Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Route exporter pipeline drop events to a handler.
|
|
33
|
+
*
|
|
34
|
+
* Drop events are meta-events for alerting and health reporting, so they use a
|
|
35
|
+
* dedicated hook instead of the normal observability signal router.
|
|
36
|
+
*/
|
|
37
|
+
export declare function routeDropToHandler(handler: ObservabilityHandler, event: ObservabilityDropEvent, logger: IMastraLogger): void | Promise<void>;
|
|
31
38
|
//# sourceMappingURL=route-event.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-event.d.ts","sourceRoot":"","sources":["../../src/bus/route-event.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EACV,mBAAmB,EAMnB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"route-event.d.ts","sourceRoot":"","sources":["../../src/bus/route-event.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EACV,mBAAmB,EAMnB,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,4BAA4B,CAAC;AAGpC;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,mBAAmB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAa1E;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,oBAAoB,EAC7B,KAAK,EAAE,kBAAkB,EACzB,MAAM,EAAE,aAAa,GACpB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAwDtB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,oBAAoB,EAC7B,KAAK,EAAE,sBAAsB,EAC7B,MAAM,EAAE,aAAa,GACpB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAQtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src/client/id.ts"],"names":[],"mappings":"AAAA,wBAAgB,sBAAsB,IAAI,MAAM,CAE/C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client observability for @mastra/observability.
|
|
3
|
+
*
|
|
4
|
+
* Implements the ClientObservabilityProxy interface from @mastra/core
|
|
5
|
+
* to bridge OTLP/JSON spans and logs returned by client-side execution
|
|
6
|
+
* (via the @mastra/client-js collector) into the Mastra observability
|
|
7
|
+
* bus.
|
|
8
|
+
*/
|
|
9
|
+
export { createClientObservabilityProxy, DEFAULT_LIMITS } from './proxy.js';
|
|
10
|
+
export type { ClientObservabilityProxyLimits, CreateClientObservabilityProxyOptions } from './proxy.js';
|
|
11
|
+
export { decodeResourceLogs, decodeResourceSpans, buildExportedLog, buildExportedSpan, otlpSeverityToLogLevel, } from './otlp.js';
|
|
12
|
+
export type { DecodedOtlpLog, DecodedOtlpSpan } from './otlp.js';
|
|
13
|
+
export { formatBaggage, formatTraceparent, parseBaggage, parseTraceparent } from './w3c.js';
|
|
14
|
+
export type { TraceparentParts } from './w3c.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,8BAA8B,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzE,YAAY,EAAE,8BAA8B,EAAE,qCAAqC,EAAE,MAAM,SAAS,CAAC;AACrG,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,QAAQ,CAAC;AAChB,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AACzF,YAAY,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hand-rolled OTLP/JSON decoder for the subset we need to ingest from
|
|
3
|
+
* client-side tool execution.
|
|
4
|
+
*
|
|
5
|
+
* The full OTLP/JSON spec is defined in
|
|
6
|
+
* https://opentelemetry.io/docs/specs/otlp/#otlphttp and the
|
|
7
|
+
* opentelemetry-proto repo. We only consume `ResourceSpans` (for spans)
|
|
8
|
+
* and `ResourceLogs` (for logs). The full message types are large and
|
|
9
|
+
* include backwards-compat fields we never need; this walker reads the
|
|
10
|
+
* fields we care about and ignores the rest.
|
|
11
|
+
*
|
|
12
|
+
* Using `@opentelemetry/otlp-transformer` would pull in the full proto
|
|
13
|
+
* dependency tree (~hundreds of KB) for what amounts to a 100-line walker.
|
|
14
|
+
*/
|
|
15
|
+
import type { AnyExportedSpan, EntityType, ExportedLog, LogLevel } from '@mastra/core/observability';
|
|
16
|
+
/**
|
|
17
|
+
* Decoded shape of one span pulled out of an OTLP/JSON ResourceSpans
|
|
18
|
+
* payload. Just enough fields to construct an ExportedSpan and forward
|
|
19
|
+
* it through the bus.
|
|
20
|
+
*/
|
|
21
|
+
export interface DecodedOtlpSpan {
|
|
22
|
+
traceId: string;
|
|
23
|
+
spanId: string;
|
|
24
|
+
parentSpanId?: string;
|
|
25
|
+
name: string;
|
|
26
|
+
startTime: Date;
|
|
27
|
+
endTime?: Date;
|
|
28
|
+
attributes?: Record<string, unknown>;
|
|
29
|
+
/** OTLP status code: 0 unset, 1 ok, 2 error */
|
|
30
|
+
statusCode?: number;
|
|
31
|
+
statusMessage?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface DecodedOtlpLog {
|
|
34
|
+
traceId: string;
|
|
35
|
+
spanId?: string;
|
|
36
|
+
timestamp: Date;
|
|
37
|
+
/** OTLP severityText: "INFO", "WARN", etc. */
|
|
38
|
+
severityText?: string;
|
|
39
|
+
/** OTLP severityNumber: 1-24 */
|
|
40
|
+
severityNumber?: number;
|
|
41
|
+
body?: unknown;
|
|
42
|
+
attributes?: Record<string, unknown>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Walk an OTLP/JSON ResourceSpans payload and return a flat list of
|
|
46
|
+
* decoded spans. Returns an empty array (and never throws) if the
|
|
47
|
+
* payload is malformed.
|
|
48
|
+
*/
|
|
49
|
+
export declare function decodeResourceSpans(payload: unknown): DecodedOtlpSpan[];
|
|
50
|
+
export declare function decodeResourceLogs(payload: unknown): DecodedOtlpLog[];
|
|
51
|
+
/**
|
|
52
|
+
* Translate an OTLP severity (text or number) to a Mastra LogLevel.
|
|
53
|
+
*
|
|
54
|
+
* OTEL severity numbers per spec:
|
|
55
|
+
* 1-4 trace, 5-8 debug, 9-12 info, 13-16 warn, 17-20 error, 21-24 fatal.
|
|
56
|
+
*/
|
|
57
|
+
export declare function otlpSeverityToLogLevel(text: string | undefined, num: number | undefined): LogLevel;
|
|
58
|
+
/**
|
|
59
|
+
* Convert a decoded OTLP span into the Mastra ExportedSpan shape so it
|
|
60
|
+
* can be emitted via the observability bus.
|
|
61
|
+
*
|
|
62
|
+
* All ingested spans use SpanType.GENERIC because we don't know what
|
|
63
|
+
* the user instrumented inside their client tool. The original span
|
|
64
|
+
* name and attributes are preserved.
|
|
65
|
+
*/
|
|
66
|
+
export declare function buildExportedSpan(decoded: DecodedOtlpSpan, options?: {
|
|
67
|
+
entityType?: EntityType;
|
|
68
|
+
entityName?: string;
|
|
69
|
+
isInternal?: boolean;
|
|
70
|
+
}): AnyExportedSpan;
|
|
71
|
+
export declare function buildExportedLog(decoded: DecodedOtlpLog): ExportedLog;
|
|
72
|
+
//# sourceMappingURL=otlp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otlp.d.ts","sourceRoot":"","sources":["../../src/client/otlp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAoDrG;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,8CAA8C;IAC9C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gCAAgC;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,EAAE,CAqCvE;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,cAAc,EAAE,CAmCrE;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,CAiBlG;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,eAAe,EACxB,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,UAAU,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,GACnF,eAAe,CAuBjB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,WAAW,CAUrE"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClientObservabilityProxy implementation for @mastra/observability.
|
|
3
|
+
*
|
|
4
|
+
* Handles the two halves of the client observability flow:
|
|
5
|
+
*
|
|
6
|
+
* - `inject(parentSpan)` (called from request 1) — produces the W3C
|
|
7
|
+
* carrier the server attaches to the outgoing chunk so the client
|
|
8
|
+
* SDK can extract it and parent its child spans/logs correctly.
|
|
9
|
+
*
|
|
10
|
+
* - `receive(payload, parentContext)` (called from request 2 when the
|
|
11
|
+
* client returns) — decodes the OTLP/JSON payload the client sent
|
|
12
|
+
* back, validates that it actually belongs to the parent trace
|
|
13
|
+
* identified by `parentContext`, and forwards each span/log into
|
|
14
|
+
* the observability bus so existing exporters pick them up.
|
|
15
|
+
*/
|
|
16
|
+
import type { IMastraLogger } from '@mastra/core/logger';
|
|
17
|
+
import type { ClientObservabilityProxy, ObservabilityInstance } from '@mastra/core/observability';
|
|
18
|
+
/**
|
|
19
|
+
* Hard caps. A misbehaving client could ship arbitrary OTLP; reject
|
|
20
|
+
* payloads that blow past these limits to keep the server safe.
|
|
21
|
+
*/
|
|
22
|
+
export interface ClientObservabilityProxyLimits {
|
|
23
|
+
/** Maximum number of spans accepted per receive call. */
|
|
24
|
+
maxSpans: number;
|
|
25
|
+
/** Maximum number of log records accepted per receive call. */
|
|
26
|
+
maxLogs: number;
|
|
27
|
+
/** Maximum total payload size in bytes (JSON.stringify length). */
|
|
28
|
+
maxPayloadBytes: number;
|
|
29
|
+
}
|
|
30
|
+
export declare const DEFAULT_LIMITS: ClientObservabilityProxyLimits;
|
|
31
|
+
export interface CreateClientObservabilityProxyOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Resolves the observability instance to forward into. Called per
|
|
34
|
+
* `receive()` so config selection works the same way as for
|
|
35
|
+
* server-side spans. Returning `undefined` causes the payload to be
|
|
36
|
+
* dropped silently.
|
|
37
|
+
*/
|
|
38
|
+
resolveInstance: () => ObservabilityInstance | undefined;
|
|
39
|
+
/** Logger for warnings about dropped/rejected payloads. */
|
|
40
|
+
logger?: IMastraLogger;
|
|
41
|
+
limits?: Partial<ClientObservabilityProxyLimits>;
|
|
42
|
+
}
|
|
43
|
+
export declare function createClientObservabilityProxy(options: CreateClientObservabilityProxyOptions): ClientObservabilityProxy;
|
|
44
|
+
//# sourceMappingURL=proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/client/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAGV,wBAAwB,EAIxB,qBAAqB,EAEtB,MAAM,4BAA4B,CAAC;AAQpC;;;GAGG;AACH,MAAM,WAAW,8BAA8B;IAC7C,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,cAAc,EAAE,8BAI5B,CAAC;AAEF,MAAM,WAAW,qCAAqC;IACpD;;;;;OAKG;IACH,eAAe,EAAE,MAAM,qBAAqB,GAAG,SAAS,CAAC;IACzD,2DAA2D;IAC3D,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC,8BAA8B,CAAC,CAAC;CAClD;AAqKD,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,qCAAqC,GAC7C,wBAAwB,CAE1B"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hand-rolled W3C Trace Context and Baggage propagation.
|
|
3
|
+
*
|
|
4
|
+
* The full propagators in `@opentelemetry/core` weigh ~27KB gzipped.
|
|
5
|
+
* The W3C specs (https://www.w3.org/TR/trace-context/, https://www.w3.org/TR/baggage/)
|
|
6
|
+
* are simple text formats; for the small subset we need (parse and
|
|
7
|
+
* format `traceparent`, parse and format `baggage`), hand-rolling is
|
|
8
|
+
* cheaper and avoids adding an OTEL dependency to @mastra/observability.
|
|
9
|
+
*/
|
|
10
|
+
export interface TraceparentParts {
|
|
11
|
+
/** Version, currently always "00". */
|
|
12
|
+
version: string;
|
|
13
|
+
/** 32 hex chars. */
|
|
14
|
+
traceId: string;
|
|
15
|
+
/** 16 hex chars. Refers to the parent span this carrier identifies. */
|
|
16
|
+
spanId: string;
|
|
17
|
+
/** 2 hex chars. Bit 0 is the sampled flag. */
|
|
18
|
+
flags: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function parseTraceparent(value: string | undefined): TraceparentParts | null;
|
|
21
|
+
export declare function formatTraceparent(traceId: string, spanId: string, sampled: boolean): string;
|
|
22
|
+
/**
|
|
23
|
+
* Parse a W3C Baggage header value into a Map.
|
|
24
|
+
*
|
|
25
|
+
* Format: `key=value,key2=value2;property=...`
|
|
26
|
+
* Properties (after `;`) are ignored — we don't use them.
|
|
27
|
+
* Values are percent-decoded per the spec.
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseBaggage(value: string | undefined): Map<string, string>;
|
|
30
|
+
/**
|
|
31
|
+
* Format a Map into a W3C Baggage header value.
|
|
32
|
+
* Values are percent-encoded.
|
|
33
|
+
*/
|
|
34
|
+
export declare function formatBaggage(entries: Map<string, string> | Record<string, string>): string;
|
|
35
|
+
//# sourceMappingURL=w3c.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"w3c.d.ts","sourceRoot":"","sources":["../../src/client/w3c.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,MAAM,WAAW,gBAAgB;IAC/B,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,oBAAoB;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,gBAAgB,GAAG,IAAI,CAQnF;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAE3F;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAuB3E;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAQ3F"}
|
package/dist/config.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type { RequestContext } from '@mastra/core/di';
|
|
|
8
8
|
import type { ObservabilityInstance, ObservabilityExporter, ObservabilityBridge, SpanOutputProcessor, ConfigSelector, SerializationOptions, CardinalityConfig, LogLevel, AnyExportedSpan } from '@mastra/core/observability';
|
|
9
9
|
import { SpanType } from '@mastra/core/observability';
|
|
10
10
|
import { z } from 'zod/v4';
|
|
11
|
+
import type { SensitiveDataFilterOptions } from './span_processors/index.js';
|
|
11
12
|
/**
|
|
12
13
|
* Sampling strategy types
|
|
13
14
|
*/
|
|
@@ -120,7 +121,7 @@ export interface ObservabilityInstanceConfig {
|
|
|
120
121
|
export interface ObservabilityRegistryConfig {
|
|
121
122
|
/**
|
|
122
123
|
* Enables default exporters, with sampling: always, and sensitive data filtering
|
|
123
|
-
* @deprecated Use explicit `configs` with
|
|
124
|
+
* @deprecated Use explicit `configs` with MastraStorageExporter, MastraPlatformExporter, and SensitiveDataFilter instead.
|
|
124
125
|
* This option will be removed in a future version.
|
|
125
126
|
*/
|
|
126
127
|
default?: {
|
|
@@ -130,6 +131,25 @@ export interface ObservabilityRegistryConfig {
|
|
|
130
131
|
configs?: Record<string, Omit<ObservabilityInstanceConfig, 'name'> | ObservabilityInstance>;
|
|
131
132
|
/** Optional selector function to choose which tracing instance to use */
|
|
132
133
|
configSelector?: ConfigSelector;
|
|
134
|
+
/**
|
|
135
|
+
* Controls whether a `SensitiveDataFilter` span output processor is automatically
|
|
136
|
+
* applied to every configured observability instance. This protects against
|
|
137
|
+
* accidentally exporting secrets (API keys, tokens, passwords, etc.) to
|
|
138
|
+
* exporters such as the Mastra cloud exporter.
|
|
139
|
+
*
|
|
140
|
+
* - `true` (default): apply `SensitiveDataFilter` with default options.
|
|
141
|
+
* - `false`: do not auto-apply the filter. You can still add it manually via
|
|
142
|
+
* `spanOutputProcessors` on a specific config.
|
|
143
|
+
* - an object: apply `SensitiveDataFilter` with the provided options.
|
|
144
|
+
*
|
|
145
|
+
* If a config already includes a `SensitiveDataFilter` in
|
|
146
|
+
* `spanOutputProcessors`, the auto-applied filter is skipped to avoid
|
|
147
|
+
* double redaction. The auto-applied filter runs last (after any
|
|
148
|
+
* user-provided processors) so that sensitive data introduced or
|
|
149
|
+
* surfaced by upstream processors is still redacted before export.
|
|
150
|
+
* Pre-instantiated `ObservabilityInstance` values are not modified.
|
|
151
|
+
*/
|
|
152
|
+
sensitiveDataFilter?: boolean | SensitiveDataFilterOptions;
|
|
133
153
|
}
|
|
134
154
|
/**
|
|
135
155
|
* Zod schema for SamplingStrategy
|
|
@@ -143,7 +163,7 @@ export declare const samplingStrategySchema: z.ZodDiscriminatedUnion<[z.ZodObjec
|
|
|
143
163
|
probability: z.ZodNumber;
|
|
144
164
|
}, z.core.$strip>, z.ZodObject<{
|
|
145
165
|
type: z.ZodLiteral<SamplingStrategyType.CUSTOM>;
|
|
146
|
-
sampler: z.
|
|
166
|
+
sampler: z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>;
|
|
147
167
|
}, z.core.$strip>], "type">;
|
|
148
168
|
/**
|
|
149
169
|
* Zod schema for SerializationOptions
|
|
@@ -170,14 +190,14 @@ export declare const observabilityInstanceConfigSchema: z.ZodObject<{
|
|
|
170
190
|
probability: z.ZodNumber;
|
|
171
191
|
}, z.core.$strip>, z.ZodObject<{
|
|
172
192
|
type: z.ZodLiteral<SamplingStrategyType.CUSTOM>;
|
|
173
|
-
sampler: z.
|
|
193
|
+
sampler: z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>;
|
|
174
194
|
}, z.core.$strip>], "type">>;
|
|
175
195
|
exporters: z.ZodOptional<z.ZodArray<z.ZodAny>>;
|
|
176
196
|
bridge: z.ZodOptional<z.ZodAny>;
|
|
177
197
|
spanOutputProcessors: z.ZodOptional<z.ZodArray<z.ZodAny>>;
|
|
178
198
|
includeInternalSpans: z.ZodOptional<z.ZodBoolean>;
|
|
179
199
|
excludeSpanTypes: z.ZodOptional<z.ZodArray<z.ZodEnum<typeof SpanType>>>;
|
|
180
|
-
spanFilter: z.ZodOptional<z.
|
|
200
|
+
spanFilter: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
181
201
|
requestContextKeys: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
182
202
|
serializationOptions: z.ZodOptional<z.ZodObject<{
|
|
183
203
|
maxStringLength: z.ZodOptional<z.ZodNumber>;
|
|
@@ -193,10 +213,10 @@ export declare const observabilityInstanceConfigSchema: z.ZodObject<{
|
|
|
193
213
|
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
194
214
|
level: z.ZodOptional<z.ZodEnum<{
|
|
195
215
|
debug: "debug";
|
|
196
|
-
info: "info";
|
|
197
|
-
warn: "warn";
|
|
198
216
|
error: "error";
|
|
199
217
|
fatal: "fatal";
|
|
218
|
+
info: "info";
|
|
219
|
+
warn: "warn";
|
|
200
220
|
}>>;
|
|
201
221
|
}, z.core.$strip>>;
|
|
202
222
|
name: z.ZodString;
|
|
@@ -216,14 +236,14 @@ export declare const observabilityConfigValueSchema: z.ZodObject<{
|
|
|
216
236
|
probability: z.ZodNumber;
|
|
217
237
|
}, z.core.$strip>, z.ZodObject<{
|
|
218
238
|
type: z.ZodLiteral<SamplingStrategyType.CUSTOM>;
|
|
219
|
-
sampler: z.
|
|
239
|
+
sampler: z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>;
|
|
220
240
|
}, z.core.$strip>], "type">>;
|
|
221
241
|
exporters: z.ZodOptional<z.ZodArray<z.ZodAny>>;
|
|
222
242
|
bridge: z.ZodOptional<z.ZodAny>;
|
|
223
243
|
spanOutputProcessors: z.ZodOptional<z.ZodArray<z.ZodAny>>;
|
|
224
244
|
includeInternalSpans: z.ZodOptional<z.ZodBoolean>;
|
|
225
245
|
excludeSpanTypes: z.ZodOptional<z.ZodArray<z.ZodEnum<typeof SpanType>>>;
|
|
226
|
-
spanFilter: z.ZodOptional<z.
|
|
246
|
+
spanFilter: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
227
247
|
requestContextKeys: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
228
248
|
serializationOptions: z.ZodOptional<z.ZodObject<{
|
|
229
249
|
maxStringLength: z.ZodOptional<z.ZodNumber>;
|
|
@@ -239,24 +259,27 @@ export declare const observabilityConfigValueSchema: z.ZodObject<{
|
|
|
239
259
|
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
240
260
|
level: z.ZodOptional<z.ZodEnum<{
|
|
241
261
|
debug: "debug";
|
|
242
|
-
info: "info";
|
|
243
|
-
warn: "warn";
|
|
244
262
|
error: "error";
|
|
245
263
|
fatal: "fatal";
|
|
264
|
+
info: "info";
|
|
265
|
+
warn: "warn";
|
|
246
266
|
}>>;
|
|
247
267
|
}, z.core.$strip>>;
|
|
248
268
|
}, z.core.$strip>;
|
|
249
|
-
/**
|
|
250
|
-
* Zod schema for ObservabilityRegistryConfig
|
|
251
|
-
* Note: Individual configs are validated separately in the constructor to allow for
|
|
252
|
-
* both plain config objects and pre-instantiated ObservabilityInstance objects.
|
|
253
|
-
* The schema is permissive to handle edge cases gracefully (arrays, null values).
|
|
254
|
-
*/
|
|
255
269
|
export declare const observabilityRegistryConfigSchema: z.ZodObject<{
|
|
256
270
|
default: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
257
271
|
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
258
272
|
}, z.core.$strip>>>;
|
|
259
273
|
configs: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodArray<z.ZodAny>, z.ZodNull]>>;
|
|
260
|
-
configSelector: z.ZodOptional<z.
|
|
274
|
+
configSelector: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
275
|
+
sensitiveDataFilter: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
276
|
+
sensitiveFields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
277
|
+
redactionToken: z.ZodOptional<z.ZodString>;
|
|
278
|
+
redactionStyle: z.ZodOptional<z.ZodEnum<{
|
|
279
|
+
full: "full";
|
|
280
|
+
indexed: "indexed";
|
|
281
|
+
partial: "partial";
|
|
282
|
+
}>>;
|
|
283
|
+
}, z.core.$strict>]>>;
|
|
261
284
|
}, z.core.$loose>;
|
|
262
285
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,oBAAoB,EACpB,iBAAiB,EACjB,QAAQ,EACR,eAAe,EAChB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/context/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/context/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAyB,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAErH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAG/C,MAAM,WAAW,mBAAmB;IAClC,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,wDAAwD;IACxD,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IAExC,uEAAuE;IACvE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnC,6BAA6B;IAC7B,gBAAgB,EAAE,gBAAgB,CAAC;IAEnC,wDAAwD;IACxD,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAWD,qBAAa,iBAAkB,YAAW,aAAa;IACrD,OAAO,CAAC,MAAM,CAAsB;IAEpC;;;OAGG;IACH,YAAY,MAAM,EAAE,mBAAmB,EAUtC;IAED,0BAA0B;IAC1B,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAE3D;IAED,yBAAyB;IACzB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAE1D;IAED,yBAAyB;IACzB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAE1D;IAED,0BAA0B;IAC1B,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAE3D;IAED,0BAA0B;IAC1B,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAE3D;IAED;;OAEG;IACH,OAAO,CAAC,GAAG;CAqBZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/context/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/context/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,OAAO,EACP,KAAK,EACL,SAAS,EACT,kBAAkB,EAIlB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAE/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,uDAAuD;AACvD,MAAM,WAAW,oBAAoB;IACnC,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,wDAAwD;IACxD,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,kEAAkE;IAClE,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IAExC,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnC,0DAA0D;IAC1D,iBAAiB,EAAE,iBAAiB,CAAC;IAErC,6BAA6B;IAC7B,gBAAgB,EAAE,gBAAgB,CAAC;CACpC;AAED;;;GAGG;AACH,qBAAa,kBAAmB,YAAW,cAAc;IACvD,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,kBAAkB,CAAC,CAAqB;IAChD,OAAO,CAAC,QAAQ,CAAC,CAA0B;IAC3C,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,gBAAgB,CAAmB;IAE3C;;;OAGG;IACH,YAAY,MAAM,EAAE,oBAAoB,EAOvC;IAED,iCAAiC;IACjC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAwBpG;IAED,wCAAwC;IACxC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAM7B;IAED,wCAAwC;IACxC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAMzB;IAED,wCAAwC;IACxC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAMjC;CACF"}
|