@mastra/observability 1.16.3 → 1.16.4-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.js CHANGED
@@ -3083,13 +3083,24 @@ var BaseObservabilityInstance = class extends MastraBase {
3083
3083
  return this.observabilityBus;
3084
3084
  }
3085
3085
  /**
3086
+ * Minimal correlation context for span-less logger and metrics contexts,
3087
+ * so their signals still carry the Mastra-level environment and serviceName
3088
+ * instead of persisting null.
3089
+ */
3090
+ buildFallbackCorrelationContext() {
3091
+ return {
3092
+ environment: this.#mastraEnvironment,
3093
+ serviceName: this.config.serviceName
3094
+ };
3095
+ }
3096
+ /**
3086
3097
  * Get a LoggerContext correlated to a span.
3087
3098
  * Called by the context-factory in core (deriveLoggerContext) so that
3088
3099
  * `observabilityContext.loggerVNext` is a real logger instead of no-op.
3089
3100
  */
3090
3101
  getLoggerContext(span) {
3091
3102
  if (this.config.logging?.enabled === false) return noOpLoggerContext;
3092
- const correlationContext = span?.getCorrelationContext?.();
3103
+ const correlationContext = span?.getCorrelationContext?.() ?? this.buildFallbackCorrelationContext();
3093
3104
  const metadata = span?.metadata ? structuredClone(span.metadata) : void 0;
3094
3105
  return new LoggerContextImpl({
3095
3106
  traceId: span?.traceId,
@@ -3106,7 +3117,7 @@ var BaseObservabilityInstance = class extends MastraBase {
3106
3117
  * `observabilityContext.metrics` is a real metrics context instead of no-op.
3107
3118
  */
3108
3119
  getMetricsContext(span) {
3109
- const correlationContext = span?.getCorrelationContext?.();
3120
+ const correlationContext = span?.getCorrelationContext?.() ?? this.buildFallbackCorrelationContext();
3110
3121
  const metadata = span?.metadata ? structuredClone(span.metadata) : void 0;
3111
3122
  return new MetricsContextImpl({
3112
3123
  traceId: span?.traceId,