@mastra/observability 1.17.2-alpha.1 → 1.17.2-alpha.2
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 +16 -0
- package/dist/index.cjs +18 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/dist/instances/base.d.ts.map +1 -1
- package/dist/spans/base.d.ts +5 -0
- package/dist/spans/base.d.ts.map +1 -1
- package/dist/spans/default.d.ts.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @mastra/observability
|
|
2
2
|
|
|
3
|
+
## 1.17.2-alpha.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Added `span.endTree()` for closing a span together with every descendant span that is still open, so an operation that is abandoned rather than completed can still emit a full trace. The options you pass are applied to every span it closes, so a force-closed child is distinguishable from one that finished on its own. ([#22278](https://github.com/mastra-ai/mastra/pull/22278))
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// Ends the span and any child spans still open beneath it, marking each canceled
|
|
11
|
+
workflowSpan.endTree({ attributes: { status: 'canceled' } });
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Repeat calls to `span.end()` are now ignored. A span that was force-closed this way keeps the state it was closed with and reports its end exactly once, even if the work it covered finishes later and ends the span again.
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`b05f486`](https://github.com/mastra-ai/mastra/commit/b05f48612984d5fe2447ea2d6cdd5c604d285b97), [`7960688`](https://github.com/mastra-ai/mastra/commit/7960688828e04eaf3106e34f7758fa580257eef6)]:
|
|
17
|
+
- @mastra/core@1.62.0-alpha.10
|
|
18
|
+
|
|
3
19
|
## 1.17.2-alpha.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -2718,7 +2718,7 @@ function getExternalParentId(options) {
|
|
|
2718
2718
|
if (parent.isInternal || parent.isExcluded) return parent.getParentSpanId(false);
|
|
2719
2719
|
return parent.id;
|
|
2720
2720
|
}
|
|
2721
|
-
var BaseSpan = class {
|
|
2721
|
+
var BaseSpan = class BaseSpan {
|
|
2722
2722
|
name;
|
|
2723
2723
|
type;
|
|
2724
2724
|
attributes;
|
|
@@ -2768,6 +2768,8 @@ var BaseSpan = class {
|
|
|
2768
2768
|
isExcluded;
|
|
2769
2769
|
/** Cached canonical correlation context for this live span */
|
|
2770
2770
|
correlationContext;
|
|
2771
|
+
/** Child spans that have started but not yet ended */
|
|
2772
|
+
#openChildren;
|
|
2771
2773
|
/**
|
|
2772
2774
|
* Subclasses can override to unconditionally mark the span as excluded.
|
|
2773
2775
|
* NoOpSpan uses this because it is never exported regardless of config.
|
|
@@ -2789,6 +2791,8 @@ var BaseSpan = class {
|
|
|
2789
2791
|
this.isEvent = options.isEvent ?? false;
|
|
2790
2792
|
this.tracingPolicy = options.tracingPolicy;
|
|
2791
2793
|
this.traceState = options.traceState;
|
|
2794
|
+
const parent = options.parent;
|
|
2795
|
+
if (!this.isEvent && parent instanceof BaseSpan && parent.isValid) (parent.#openChildren ??= /* @__PURE__ */ new Set()).add(this);
|
|
2792
2796
|
this.tags = !options.parent && options.tags?.length ? options.tags : void 0;
|
|
2793
2797
|
const entityParent = this.getParentSpan(false);
|
|
2794
2798
|
this.entityType = options.entityType ?? entityParent?.entityType;
|
|
@@ -2826,6 +2830,16 @@ var BaseSpan = class {
|
|
|
2826
2830
|
return value;
|
|
2827
2831
|
}
|
|
2828
2832
|
}
|
|
2833
|
+
/** End the span and any descendant spans that are still open, applying `options` to each */
|
|
2834
|
+
endTree(options) {
|
|
2835
|
+
if (this.#openChildren) for (const child of [...this.#openChildren]) child.endTree(options);
|
|
2836
|
+
this.end(options);
|
|
2837
|
+
}
|
|
2838
|
+
/** Release this span from its parent's open-child set once it has ended */
|
|
2839
|
+
detachFromParent() {
|
|
2840
|
+
const parent = this.parent;
|
|
2841
|
+
if (parent instanceof BaseSpan) parent.#openChildren?.delete(this);
|
|
2842
|
+
}
|
|
2829
2843
|
createChildSpan(options) {
|
|
2830
2844
|
return this.observabilityInstance.startSpan({
|
|
2831
2845
|
...options,
|
|
@@ -3029,7 +3043,9 @@ var DefaultSpan = class extends BaseSpan {
|
|
|
3029
3043
|
}
|
|
3030
3044
|
end(options) {
|
|
3031
3045
|
if (this.isEvent) return;
|
|
3046
|
+
if (this.endTime) return;
|
|
3032
3047
|
this.endTime = /* @__PURE__ */ new Date();
|
|
3048
|
+
this.detachFromParent();
|
|
3033
3049
|
if (options?.metadata) this.metadata = {
|
|
3034
3050
|
...this.metadata,
|
|
3035
3051
|
...deepClean(this.prepareSpanMetadata(options.metadata), this.deepCleanOptions)
|
|
@@ -3485,6 +3501,7 @@ var BaseObservabilityInstance = class extends _mastra_core_base.MastraBase {
|
|
|
3485
3501
|
this.logger.warn(`End event is not available on event spans`);
|
|
3486
3502
|
return;
|
|
3487
3503
|
}
|
|
3504
|
+
if (span.endTime) return;
|
|
3488
3505
|
const rollupTarget = this.captureModelUsageRollup(span, options);
|
|
3489
3506
|
const excludedModelUsage = this.captureExcludedModelUsage(span, options);
|
|
3490
3507
|
originalEnd(options);
|