@mastra/observability 1.17.2 → 1.17.3-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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @mastra/observability
2
2
 
3
+ ## 1.17.3-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed the "Span not found." error when opening the span linked from a log or metric in Studio. ([#22286](https://github.com/mastra-ai/mastra/pull/22286))
8
+
9
+ Logs and metrics emitted inside an internal or excluded span were stamped with that span's own id. Those spans are dropped before export, so the id referenced a span no exporter ever received, and clicking through from a log detail panel returned a 404.
10
+
11
+ Logs and metrics now resolve to the nearest ancestor span that actually reaches exporters, and omit `spanId` entirely when no such ancestor exists. This applies to newly emitted signals; already-stored logs and metrics keep the ids they were written with.
12
+
13
+ - Updated dependencies [[`7176362`](https://github.com/mastra-ai/mastra/commit/717636281a3339911a05ea2cc8ae38afe4fd2cef), [`e3b796d`](https://github.com/mastra-ai/mastra/commit/e3b796d29a63f0d5c97dd815aadec40687346d70), [`49ccd14`](https://github.com/mastra-ai/mastra/commit/49ccd142268a61fb55ea75bc76287643a21f3677), [`3855b38`](https://github.com/mastra-ai/mastra/commit/3855b38c4c25af32ab8e298e148becc963abe92c)]:
14
+ - @mastra/core@1.63.0-alpha.0
15
+
3
16
  ## 1.17.2
4
17
 
5
18
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -2879,6 +2879,23 @@ var BaseSpan = class BaseSpan {
2879
2879
  if (parent.isExcluded || !includeInternalSpans && parent.isInternal) return parent.getParentSpan(includeInternalSpans);
2880
2880
  return this.parent;
2881
2881
  }
2882
+ /**
2883
+ * Get the spanId that observability signals (logs, metrics, scores) should
2884
+ * reference for this span. If this span itself reaches exporters, that is
2885
+ * its own id. If it is excluded from export (internal span, excludeSpanTypes,
2886
+ * or NoOpSpan), resolves to the nearest exportable ancestor instead.
2887
+ * Returns undefined when no exportable ancestor exists.
2888
+ *
2889
+ * Only covers exclusions known when the span is created (`isExcluded`). A
2890
+ * `spanFilter` or a span output processor can still drop a span at export
2891
+ * time — both run on the exported span data after the span ends, so their
2892
+ * verdict isn't knowable while signals are being stamped. Signals emitted
2893
+ * inside a span dropped that way still reference its own id.
2894
+ */
2895
+ getExportedSpanId() {
2896
+ if (!this.isExcluded) return this.id;
2897
+ return this.getParentSpanId(this.observabilityInstance.getConfig().includeInternalSpans);
2898
+ }
2882
2899
  /** Get the closest parent spanId that will reach exporters (unless includeInternalSpans) */
2883
2900
  getParentSpanId(includeInternalSpans) {
2884
2901
  if (!this.parent) return this.parentSpanId;
@@ -2920,7 +2937,7 @@ var BaseSpan = class BaseSpan {
2920
2937
  const rootTags = rootSpan.tags?.length ? [...rootSpan.tags] : void 0;
2921
2938
  this.correlationContext = {
2922
2939
  traceId: this.traceId,
2923
- spanId: this.id,
2940
+ spanId: this.getExportedSpanId(),
2924
2941
  tags: rootTags,
2925
2942
  entityType: this.entityType,
2926
2943
  entityId: this.entityId,
@@ -3439,7 +3456,7 @@ var BaseObservabilityInstance = class extends _mastra_core_base.MastraBase {
3439
3456
  const metadata = span?.metadata ? structuredClone(span.metadata) : void 0;
3440
3457
  return new LoggerContextImpl({
3441
3458
  traceId: span?.traceId,
3442
- spanId: span?.id,
3459
+ spanId: (0, _mastra_core_observability.resolveExportedSpanId)(span),
3443
3460
  correlationContext,
3444
3461
  metadata,
3445
3462
  observabilityBus: this.observabilityBus,
@@ -3456,7 +3473,7 @@ var BaseObservabilityInstance = class extends _mastra_core_base.MastraBase {
3456
3473
  const metadata = span?.metadata ? structuredClone(span.metadata) : void 0;
3457
3474
  return new MetricsContextImpl({
3458
3475
  traceId: span?.traceId,
3459
- spanId: span?.id,
3476
+ spanId: (0, _mastra_core_observability.resolveExportedSpanId)(span),
3460
3477
  correlationContext,
3461
3478
  metadata,
3462
3479
  cardinalityFilter: this.cardinalityFilter,