@mastra/observability 1.10.3 → 1.11.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
@@ -19435,7 +19435,7 @@ var BaseSpan = class {
19435
19435
  sessionId: getMetadataString("sessionId"),
19436
19436
  threadId: getMetadataString("threadId"),
19437
19437
  requestId: getMetadataString("requestId"),
19438
- environment: getMetadataString("environment"),
19438
+ environment: getMetadataString("environment") ?? this.observabilityInstance.getMastraEnvironment?.(),
19439
19439
  source: getMetadataString("source"),
19440
19440
  serviceName: getMetadataString("serviceName") ?? this.observabilityInstance.getConfig().serviceName,
19441
19441
  experimentId: getMetadataString("experimentId")
@@ -19707,6 +19707,12 @@ var BaseObservabilityInstance = class extends MastraBase {
19707
19707
  * Cardinality filter for metrics label protection.
19708
19708
  */
19709
19709
  cardinalityFilter;
19710
+ /**
19711
+ * Deployment environment propagated from the parent Mastra instance.
19712
+ * Set by `Observability.setMastraContext`, read by spans as a fallback when
19713
+ * a span's `metadata.environment` isn't set.
19714
+ */
19715
+ #mastraEnvironment;
19710
19716
  constructor(config2) {
19711
19717
  super({ component: RegisteredLogger.OBSERVABILITY, name: config2.serviceName });
19712
19718
  this.config = {
@@ -19799,6 +19805,7 @@ var BaseObservabilityInstance = class extends MastraBase {
19799
19805
  const tracingMetadata = !options.parent ? tracingOptions?.metadata : void 0;
19800
19806
  const mergedMetadata = metadata || tracingMetadata ? { ...metadata, ...tracingMetadata } : void 0;
19801
19807
  const enrichedMetadata = this.extractMetadataFromRequestContext(requestContext, mergedMetadata, traceState);
19808
+ const finalMetadata = !options.parent && this.#mastraEnvironment !== void 0 && (enrichedMetadata === void 0 || enrichedMetadata.environment === void 0) ? { ...enrichedMetadata ?? {}, environment: this.#mastraEnvironment } : enrichedMetadata;
19802
19809
  const tags = !options.parent ? tracingOptions?.tags : void 0;
19803
19810
  const traceId = !options.parent ? options.traceId ?? tracingOptions?.traceId : options.traceId;
19804
19811
  const parentSpanId = !options.parent ? options.parentSpanId ?? tracingOptions?.parentSpanId : options.parentSpanId;
@@ -19806,7 +19813,7 @@ var BaseObservabilityInstance = class extends MastraBase {
19806
19813
  ...rest,
19807
19814
  traceId,
19808
19815
  parentSpanId,
19809
- metadata: enrichedMetadata,
19816
+ metadata: finalMetadata,
19810
19817
  traceState,
19811
19818
  tags,
19812
19819
  requestContext
@@ -19859,6 +19866,20 @@ var BaseObservabilityInstance = class extends MastraBase {
19859
19866
  getConfig() {
19860
19867
  return { ...this.config };
19861
19868
  }
19869
+ /**
19870
+ * Returns the deployment environment propagated from the parent Mastra instance.
19871
+ * Spans use this as a fallback when `metadata.environment` isn't set.
19872
+ */
19873
+ getMastraEnvironment() {
19874
+ return this.#mastraEnvironment;
19875
+ }
19876
+ /**
19877
+ * Internal hook used by `Observability.setMastraContext` to push the
19878
+ * resolved Mastra-level environment into this instance.
19879
+ */
19880
+ __setMastraEnvironment(environment) {
19881
+ this.#mastraEnvironment = environment;
19882
+ }
19862
19883
  // ============================================================================
19863
19884
  // Plugin Access
19864
19885
  // ============================================================================
@@ -20873,7 +20894,9 @@ var Observability = class extends MastraBase {
20873
20894
  const instances = this.listInstances();
20874
20895
  const { mastra } = options;
20875
20896
  this.#mastra = mastra;
20897
+ const mastraEnvironment = mastra.getEnvironment?.();
20876
20898
  instances.forEach((instance) => {
20899
+ instance.__setMastraEnvironment?.(mastraEnvironment);
20877
20900
  const config2 = instance.getConfig();
20878
20901
  const exporters = instance.getExporters();
20879
20902
  exporters.forEach((exporter) => {
@@ -20990,6 +21013,9 @@ var Observability = class extends MastraBase {
20990
21013
  /** Register a named observability instance, optionally marking it as default. */
20991
21014
  registerInstance(name, instance, isDefault = false) {
20992
21015
  this.#registry.register(name, instance, isDefault);
21016
+ if (this.#mastra) {
21017
+ instance.__setMastraEnvironment?.(this.#mastra.getEnvironment?.());
21018
+ }
20993
21019
  }
20994
21020
  /** Get a registered instance by name. */
20995
21021
  getInstance(name) {