@mastra/observability 1.18.2-alpha.1 → 1.18.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/dist/index.cjs CHANGED
@@ -3248,6 +3248,30 @@ var BaseSpan = class BaseSpan {
3248
3248
  };
3249
3249
  //#endregion
3250
3250
  //#region src/spans/default.ts
3251
+ /** Every AI SDK `APICallError` (v4, v5 and v6) carries this shared marker symbol. */
3252
+ const API_CALL_ERROR_MARKER = Symbol.for("vercel.ai.error.AI_APICallError");
3253
+ function isApiCallError(value) {
3254
+ return typeof value === "object" && value !== null && value[API_CALL_ERROR_MARKER] === true;
3255
+ }
3256
+ /**
3257
+ * HTTP facts of a provider call failure, read from an AI SDK `APICallError` or
3258
+ * from the one a wrapper (MastraError, durable transport) carries as `cause`.
3259
+ * Without them a span only says "Service Unavailable", with no status or URL.
3260
+ */
3261
+ function apiCallErrorDetails(error) {
3262
+ const apiError = isApiCallError(error) ? error : isApiCallError(error.cause) ? error.cause : void 0;
3263
+ if (!apiError) return void 0;
3264
+ const details = {};
3265
+ if (apiError.statusCode !== void 0) details.statusCode = apiError.statusCode;
3266
+ if (apiError.url !== void 0) details.url = apiError.url.split("?")[0];
3267
+ if (apiError.isRetryable !== void 0) details.isRetryable = apiError.isRetryable;
3268
+ if (apiError.responseBody !== void 0) try {
3269
+ details.responseBody = JSON.parse(apiError.responseBody);
3270
+ } catch {
3271
+ details.responseBody = apiError.responseBody;
3272
+ }
3273
+ return details;
3274
+ }
3251
3275
  var DefaultSpan = class extends BaseSpan {
3252
3276
  id;
3253
3277
  traceId;
@@ -3309,9 +3333,13 @@ var DefaultSpan = class extends BaseSpan {
3309
3333
  ...deepClean(this.prepareSpanMetadata(metadata), this.deepCleanOptions)
3310
3334
  };
3311
3335
  if (!this.isExcluded) {
3336
+ const apiDetails = apiCallErrorDetails(error);
3312
3337
  this.errorInfo = deepClean(error instanceof _mastra_core_error.MastraError ? {
3313
3338
  id: error.id,
3314
- details: error.details,
3339
+ details: apiDetails ? {
3340
+ ...error.details,
3341
+ ...apiDetails
3342
+ } : error.details,
3315
3343
  category: error.category,
3316
3344
  domain: error.domain,
3317
3345
  message: error.message,
@@ -3320,7 +3348,8 @@ var DefaultSpan = class extends BaseSpan {
3320
3348
  } : {
3321
3349
  message: error.message,
3322
3350
  name: error.name,
3323
- stack: error.stack
3351
+ stack: error.stack,
3352
+ ...apiDetails && { details: apiDetails }
3324
3353
  }, this.deepCleanOptions);
3325
3354
  if (attributes) this.attributes = {
3326
3355
  ...this.attributes,
@@ -9144,7 +9173,7 @@ var RecordedTraceImpl = class {
9144
9173
  };
9145
9174
  function findRootSpan(spans) {
9146
9175
  const spanIds = new Set(spans.map((span) => span.spanId));
9147
- return spans.find((span) => !span.parentSpanId || !spanIds.has(span.parentSpanId)) ?? spans[0];
9176
+ return spans.find((span) => !span.parentSpanId) ?? spans.find((span) => !spanIds.has(span.parentSpanId)) ?? spans[0];
9148
9177
  }
9149
9178
  function hydrateRecordedTrace(args) {
9150
9179
  const { trace, emitRecordedEvent, canEmitRecordedEvent = () => true, debugRecordedAnnotationUnavailable = () => {} } = args;