@use-tusk/drift-node-sdk 0.1.17 → 0.1.18

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
@@ -4989,31 +4989,31 @@ var require_SamplingResult = /* @__PURE__ */ __commonJS({ "node_modules/@opentel
4989
4989
  var require_span_kind = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/api/build/src/trace/span_kind.js": ((exports) => {
4990
4990
  Object.defineProperty(exports, "__esModule", { value: true });
4991
4991
  exports.SpanKind = void 0;
4992
- (function(SpanKind$24) {
4992
+ (function(SpanKind$25) {
4993
4993
  /** Default value. Indicates that the span is used internally. */
4994
- SpanKind$24[SpanKind$24["INTERNAL"] = 0] = "INTERNAL";
4994
+ SpanKind$25[SpanKind$25["INTERNAL"] = 0] = "INTERNAL";
4995
4995
  /**
4996
4996
  * Indicates that the span covers server-side handling of an RPC or other
4997
4997
  * remote request.
4998
4998
  */
4999
- SpanKind$24[SpanKind$24["SERVER"] = 1] = "SERVER";
4999
+ SpanKind$25[SpanKind$25["SERVER"] = 1] = "SERVER";
5000
5000
  /**
5001
5001
  * Indicates that the span covers the client-side wrapper around an RPC or
5002
5002
  * other remote request.
5003
5003
  */
5004
- SpanKind$24[SpanKind$24["CLIENT"] = 2] = "CLIENT";
5004
+ SpanKind$25[SpanKind$25["CLIENT"] = 2] = "CLIENT";
5005
5005
  /**
5006
5006
  * Indicates that the span describes producer sending a message to a
5007
5007
  * broker. Unlike client and server, there is no direct critical path latency
5008
5008
  * relationship between producer and consumer spans.
5009
5009
  */
5010
- SpanKind$24[SpanKind$24["PRODUCER"] = 3] = "PRODUCER";
5010
+ SpanKind$25[SpanKind$25["PRODUCER"] = 3] = "PRODUCER";
5011
5011
  /**
5012
5012
  * Indicates that the span describes consumer receiving a message from a
5013
5013
  * broker. Unlike client and server, there is no direct critical path latency
5014
5014
  * relationship between producer and consumer spans.
5015
5015
  */
5016
- SpanKind$24[SpanKind$24["CONSUMER"] = 4] = "CONSUMER";
5016
+ SpanKind$25[SpanKind$25["CONSUMER"] = 4] = "CONSUMER";
5017
5017
  })(exports.SpanKind || (exports.SpanKind = {}));
5018
5018
  }) });
5019
5019
 
@@ -5022,20 +5022,20 @@ var require_span_kind = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetr
5022
5022
  var require_status = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/api/build/src/trace/status.js": ((exports) => {
5023
5023
  Object.defineProperty(exports, "__esModule", { value: true });
5024
5024
  exports.SpanStatusCode = void 0;
5025
- (function(SpanStatusCode$13) {
5025
+ (function(SpanStatusCode$14) {
5026
5026
  /**
5027
5027
  * The default status.
5028
5028
  */
5029
- SpanStatusCode$13[SpanStatusCode$13["UNSET"] = 0] = "UNSET";
5029
+ SpanStatusCode$14[SpanStatusCode$14["UNSET"] = 0] = "UNSET";
5030
5030
  /**
5031
5031
  * The operation has been validated by an Application developer or
5032
5032
  * Operator to have completed successfully.
5033
5033
  */
5034
- SpanStatusCode$13[SpanStatusCode$13["OK"] = 1] = "OK";
5034
+ SpanStatusCode$14[SpanStatusCode$14["OK"] = 1] = "OK";
5035
5035
  /**
5036
5036
  * The operation contains an error.
5037
5037
  */
5038
- SpanStatusCode$13[SpanStatusCode$13["ERROR"] = 2] = "ERROR";
5038
+ SpanStatusCode$14[SpanStatusCode$14["ERROR"] = 2] = "ERROR";
5039
5039
  })(exports.SpanStatusCode || (exports.SpanStatusCode = {}));
5040
5040
  }) });
5041
5041
 
@@ -6209,7 +6209,7 @@ var JsonSchema$Type = class extends import_commonjs$7.MessageType {
6209
6209
  const JsonSchema = new JsonSchema$Type();
6210
6210
 
6211
6211
  //#endregion
6212
- //#region node_modules/@use-tusk/drift-schemas/dist/span-BZ89ct3l.js
6212
+ //#region node_modules/@use-tusk/drift-schemas/dist/span-CsBrzhI_.js
6213
6213
  var import_commonjs$6 = /* @__PURE__ */ __toESM(require_commonjs$2(), 1);
6214
6214
  /**
6215
6215
  * Package type classification enum
@@ -6295,7 +6295,7 @@ let PackageType = /* @__PURE__ */ function(PackageType$1) {
6295
6295
  *
6296
6296
  * @generated from protobuf enum tusk.drift.core.v1.SpanKind
6297
6297
  */
6298
- let SpanKind = /* @__PURE__ */ function(SpanKind$1$1) {
6298
+ let SpanKind$1 = /* @__PURE__ */ function(SpanKind$1$1) {
6299
6299
  /**
6300
6300
  * @generated from protobuf enum value: SPAN_KIND_UNSPECIFIED = 0;
6301
6301
  */
@@ -6465,7 +6465,7 @@ var Span$Type = class extends import_commonjs$6.MessageType {
6465
6465
  kind: "enum",
6466
6466
  T: () => [
6467
6467
  "tusk.drift.core.v1.SpanKind",
6468
- SpanKind,
6468
+ SpanKind$1,
6469
6469
  "SPAN_KIND_"
6470
6470
  ]
6471
6471
  },
@@ -6504,6 +6504,13 @@ var Span$Type = class extends import_commonjs$6.MessageType {
6504
6504
  name: "metadata",
6505
6505
  kind: "message",
6506
6506
  T: () => Struct
6507
+ },
6508
+ {
6509
+ no: 24,
6510
+ name: "environment",
6511
+ kind: "scalar",
6512
+ opt: true,
6513
+ T: 9
6507
6514
  }
6508
6515
  ]);
6509
6516
  }
@@ -6601,6 +6608,9 @@ var Span$Type = class extends import_commonjs$6.MessageType {
6601
6608
  case 23:
6602
6609
  message.metadata = Struct.internalBinaryRead(reader, reader.uint32(), options, message.metadata);
6603
6610
  break;
6611
+ case 24:
6612
+ message.environment = reader.string();
6613
+ break;
6604
6614
  default:
6605
6615
  let u = options.readUnknownField;
6606
6616
  if (u === "throw") throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
@@ -6634,6 +6644,7 @@ var Span$Type = class extends import_commonjs$6.MessageType {
6634
6644
  if (message.duration) Duration.internalBinaryWrite(message.duration, writer.tag(21, import_commonjs$6.WireType.LengthDelimited).fork(), options).join();
6635
6645
  if (message.isRootSpan !== false) writer.tag(22, import_commonjs$6.WireType.Varint).bool(message.isRootSpan);
6636
6646
  if (message.metadata) Struct.internalBinaryWrite(message.metadata, writer.tag(23, import_commonjs$6.WireType.LengthDelimited).fork(), options).join();
6647
+ if (message.environment !== void 0) writer.tag(24, import_commonjs$6.WireType.LengthDelimited).string(message.environment);
6637
6648
  let u = options.writeUnknownFields;
6638
6649
  if (u !== false) (u == true ? import_commonjs$6.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
6639
6650
  return writer;
@@ -6997,12 +7008,12 @@ const Trace = new Trace$Type();
6997
7008
  const toStruct = (obj) => obj ? objectToProtobufStruct(obj) : void 0;
6998
7009
  const mapOtToPb = (k) => {
6999
7010
  switch (k) {
7000
- case import_src$34.SpanKind.INTERNAL: return SpanKind.INTERNAL;
7001
- case import_src$34.SpanKind.SERVER: return SpanKind.SERVER;
7002
- case import_src$34.SpanKind.CLIENT: return SpanKind.CLIENT;
7003
- case import_src$34.SpanKind.PRODUCER: return SpanKind.PRODUCER;
7004
- case import_src$34.SpanKind.CONSUMER: return SpanKind.CONSUMER;
7005
- default: return SpanKind.UNSPECIFIED;
7011
+ case import_src$34.SpanKind.INTERNAL: return SpanKind$1.INTERNAL;
7012
+ case import_src$34.SpanKind.SERVER: return SpanKind$1.SERVER;
7013
+ case import_src$34.SpanKind.CLIENT: return SpanKind$1.CLIENT;
7014
+ case import_src$34.SpanKind.PRODUCER: return SpanKind$1.PRODUCER;
7015
+ case import_src$34.SpanKind.CONSUMER: return SpanKind$1.CONSUMER;
7016
+ default: return SpanKind$1.UNSPECIFIED;
7006
7017
  }
7007
7018
  };
7008
7019
  /**
@@ -7586,7 +7597,7 @@ var SpanUtils = class SpanUtils {
7586
7597
  return originalFunctionCall();
7587
7598
  }
7588
7599
  }
7589
- const { name, kind, packageName, instrumentationName, packageType, submodule, inputValue, inputSchemaMerges, isPreAppStart, metadata, stopRecordingChildSpans } = options;
7600
+ const { name, kind, packageName, instrumentationName, packageType, submodule, inputValue, outputValue, inputSchemaMerges, isPreAppStart, metadata, stopRecordingChildSpans } = options;
7590
7601
  let spanInfo = null;
7591
7602
  try {
7592
7603
  spanInfo = SpanUtils.createSpan({
@@ -7600,6 +7611,7 @@ var SpanUtils = class SpanUtils {
7600
7611
  [TdSpanAttributes.INSTRUMENTATION_NAME]: instrumentationName,
7601
7612
  [TdSpanAttributes.PACKAGE_TYPE]: packageType,
7602
7613
  [TdSpanAttributes.INPUT_VALUE]: createSpanInputValue(inputValue),
7614
+ ...outputValue && { [TdSpanAttributes.OUTPUT_VALUE]: JSON.stringify(outputValue) },
7603
7615
  [TdSpanAttributes.IS_PRE_APP_START]: isPreAppStart,
7604
7616
  ...inputSchemaMerges && { [TdSpanAttributes.INPUT_SCHEMA_MERGES]: JSON.stringify(inputSchemaMerges) },
7605
7617
  ...metadata && { [TdSpanAttributes.METADATA]: JSON.stringify(metadata) }
@@ -7966,30 +7978,6 @@ var TdHttpMockSocket = class extends events.EventEmitter {
7966
7978
  }
7967
7979
  };
7968
7980
 
7969
- //#endregion
7970
- //#region src/instrumentation/core/trackers/EnvVarTracker.ts
7971
- var EnvVarTracker = class {
7972
- static setEnvVar({ traceId, key, value }) {
7973
- this.envVars.set(traceId, {
7974
- ...this.envVars.get(traceId) || {},
7975
- [key]: value
7976
- });
7977
- }
7978
- static setEnvVars(traceId, envVars) {
7979
- this.envVars.set(traceId, envVars);
7980
- }
7981
- static getEnvVar(traceId, key) {
7982
- return this.envVars.get(traceId)?.[key];
7983
- }
7984
- static getEnvVars(traceId) {
7985
- return this.envVars.get(traceId);
7986
- }
7987
- static clearEnvVars(traceId) {
7988
- this.envVars.delete(traceId);
7989
- }
7990
- };
7991
- EnvVarTracker.envVars = /* @__PURE__ */ new Map();
7992
-
7993
7981
  //#endregion
7994
7982
  //#region src/instrumentation/core/trackers/DateTracker.ts
7995
7983
  /**
@@ -8290,6 +8278,7 @@ function convertMockRequestDataToCleanSpanData(mockRequestData, tuskDrift, input
8290
8278
  return {
8291
8279
  ...mockRequestData,
8292
8280
  parentSpanId: "",
8281
+ environment: tuskDrift.getEnvironment(),
8293
8282
  inputValueHash,
8294
8283
  inputSchema,
8295
8284
  inputSchemaHash,
@@ -8686,13 +8675,6 @@ var HttpReplayHooks = class {
8686
8675
  return traceIdHeader ? String(traceIdHeader) : null;
8687
8676
  }
8688
8677
  /**
8689
- * Check if we should fetch env vars from CLI
8690
- */
8691
- extractShouldFetchEnvVars(req) {
8692
- const fetchHeader = req.headers["x-td-fetch-env-vars"] || req.headers["X-TD-FETCH-ENV-VARS"];
8693
- return fetchHeader === "true" || fetchHeader === true;
8694
- }
8695
- /**
8696
8678
  * Handle outbound HTTP requests in replay mode
8697
8679
  * Uses TdMockClientRequest for simplified mocking approach
8698
8680
  */
@@ -9981,7 +9963,7 @@ var require_commonjs$1 = /* @__PURE__ */ __commonJS({ "node_modules/@protobuf-ts
9981
9963
  }) });
9982
9964
 
9983
9965
  //#endregion
9984
- //#region node_modules/@use-tusk/drift-schemas/dist/span_export_service-XwF6hpEK.js
9966
+ //#region node_modules/@use-tusk/drift-schemas/dist/span_export_service-CmkFvTqD.js
9985
9967
  var import_commonjs$4 = /* @__PURE__ */ __toESM(require_commonjs$1(), 1);
9986
9968
  var import_commonjs$5 = /* @__PURE__ */ __toESM(require_commonjs$2(), 1);
9987
9969
  var ExportSpansRequest$Type = class extends import_commonjs$5.MessageType {
@@ -10671,13 +10653,6 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10671
10653
  return originalHandler.call(this);
10672
10654
  }
10673
10655
  logger.debug(`[HttpInstrumentation] Setting replay trace id`, replayTraceId);
10674
- if (this.replayHooks.extractShouldFetchEnvVars(req)) try {
10675
- const envVars = this.tuskDrift.requestEnvVarsSync(replayTraceId);
10676
- EnvVarTracker.setEnvVars(replayTraceId, envVars);
10677
- logger.debug(`[HttpInstrumentation] Fetched env vars from CLI for trace ${replayTraceId}`);
10678
- } catch (error) {
10679
- logger.error(`[HttpInstrumentation] Failed to fetch env vars from CLI:`, error);
10680
- }
10681
10656
  const ctxWithReplayTraceId = SpanUtils.setCurrentReplayTraceId(replayTraceId);
10682
10657
  if (!ctxWithReplayTraceId) throw new Error("Error setting current replay trace id");
10683
10658
  return import_src$28.context.with(ctxWithReplayTraceId, () => {
@@ -10820,10 +10795,8 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10820
10795
  },
10821
10796
  headers: { matchImportance: 0 }
10822
10797
  },
10823
- metadata: { ENV_VARS: EnvVarTracker.getEnvVars(spanInfo.traceId) },
10824
10798
  ...spanData.transformMetadata && { transformMetadata: spanData.transformMetadata }
10825
10799
  });
10826
- EnvVarTracker.clearEnvVars(spanInfo.traceId);
10827
10800
  const status = statusCode >= 400 ? {
10828
10801
  code: import_src$28.SpanStatusCode.ERROR,
10829
10802
  message: `HTTP ${statusCode}`
@@ -10869,6 +10842,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10869
10842
  instrumentationName: "HttpInstrumentation",
10870
10843
  submoduleName: completeInputValue.method || inputValue.method,
10871
10844
  inputValue: completeInputValue,
10845
+ environment: self.tuskDrift.getEnvironment(),
10872
10846
  outputValue,
10873
10847
  inputSchema,
10874
10848
  outputSchema,
@@ -11389,96 +11363,6 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11389
11363
  }
11390
11364
  };
11391
11365
 
11392
- //#endregion
11393
- //#region src/instrumentation/libraries/env/Instrumentation.ts
11394
- /**
11395
- * Environment variable instrumentation that records and replays process.env access.
11396
- * In record mode, captures environment variable values.
11397
- * In replay mode, returns previously recorded values for deterministic behavior.
11398
- */
11399
- var EnvInstrumentation = class extends TdInstrumentationBase {
11400
- constructor(config = {}) {
11401
- super("env", config);
11402
- this.isInPatchedCall = false;
11403
- this.mode = config.mode || TuskDriftMode.DISABLED;
11404
- }
11405
- init() {
11406
- this.patchProcessEnv();
11407
- return [];
11408
- }
11409
- patchProcessEnv() {
11410
- if (this.mode === TuskDriftMode.DISABLED || !this._config.enabled) return;
11411
- this.originalProcessEnv = process.env;
11412
- const envProxy = new Proxy(this.originalProcessEnv, {
11413
- get: (target, property, receiver) => {
11414
- return this._handleEnvAccess(target, property);
11415
- },
11416
- set: (target, property, value, receiver) => {
11417
- target[property] = value;
11418
- return true;
11419
- },
11420
- deleteProperty: (target, property) => {
11421
- delete target[property];
11422
- return true;
11423
- },
11424
- ownKeys: (target) => {
11425
- return Reflect.ownKeys(target);
11426
- },
11427
- getOwnPropertyDescriptor: (target, property) => {
11428
- return Reflect.getOwnPropertyDescriptor(target, property);
11429
- },
11430
- has: (target, property) => {
11431
- return Reflect.has(target, property);
11432
- }
11433
- });
11434
- process.env = envProxy;
11435
- }
11436
- _handleEnvAccess(target, key) {
11437
- if (this.isInPatchedCall) return target[key];
11438
- if (!TuskDriftCore.getInstance().isAppReady()) return target[key];
11439
- this.isInPatchedCall = true;
11440
- try {
11441
- return this._handleEnvAccessInMode(target, key);
11442
- } finally {
11443
- this.isInPatchedCall = false;
11444
- }
11445
- }
11446
- _handleEnvAccessInMode(target, key) {
11447
- let currentSpanInfo = null;
11448
- try {
11449
- currentSpanInfo = SpanUtils.getCurrentSpanInfo();
11450
- } catch (error) {
11451
- logger.error(`EnvInstrumentation error getting current span info:`, error);
11452
- }
11453
- if (!currentSpanInfo) return target[key];
11454
- if (this.mode === TuskDriftMode.REPLAY) return this._handleReplayMode(target, key);
11455
- else if (this.mode === TuskDriftMode.RECORD) return this._handleRecordMode(currentSpanInfo, target, key);
11456
- else return target[key];
11457
- }
11458
- _handleReplayMode(target, key) {
11459
- const replayTraceId = SpanUtils.getCurrentReplayTraceId();
11460
- if (!replayTraceId) return target[key];
11461
- const envVar = EnvVarTracker.getEnvVar(replayTraceId, key);
11462
- if (envVar) {
11463
- logger.debug(`Returning env var ${key} for trace ${replayTraceId}: ${envVar}`);
11464
- return envVar;
11465
- }
11466
- return target[key];
11467
- }
11468
- _handleRecordMode(spanInfo, target, key) {
11469
- try {
11470
- EnvVarTracker.setEnvVar({
11471
- traceId: spanInfo.traceId,
11472
- key,
11473
- value: target[key] || void 0
11474
- });
11475
- } catch (error) {
11476
- logger.error(`EnvInstrumentation error storing env var:`, error);
11477
- }
11478
- return target[key];
11479
- }
11480
- };
11481
-
11482
11366
  //#endregion
11483
11367
  //#region src/instrumentation/libraries/date/Instrumentation.ts
11484
11368
  var import_src$27 = /* @__PURE__ */ __toESM(require_src$7(), 1);
@@ -19563,13 +19447,6 @@ var NextjsInstrumentation = class extends TdInstrumentationBase {
19563
19447
  return originalHandleRequest.call(this, req, res, parsedUrl);
19564
19448
  }
19565
19449
  logger.debug(`[NextjsInstrumentation] Setting replay trace id`, replayTraceId);
19566
- if (self.replayHooks.extractShouldFetchEnvVars(req)) try {
19567
- const envVars = self.tuskDrift.requestEnvVarsSync(replayTraceId);
19568
- EnvVarTracker.setEnvVars(replayTraceId, envVars);
19569
- logger.debug(`[NextjsInstrumentation] Fetched env vars from CLI for trace ${replayTraceId}`);
19570
- } catch (error) {
19571
- logger.error(`[NextjsInstrumentation] Failed to fetch env vars from CLI:`, error);
19572
- }
19573
19450
  const ctxWithReplayTraceId = SpanUtils.setCurrentReplayTraceId(replayTraceId);
19574
19451
  if (!ctxWithReplayTraceId) throw new Error("Error setting current replay trace id");
19575
19452
  return import_src$11.context.with(ctxWithReplayTraceId, () => {
@@ -19724,10 +19601,8 @@ var NextjsInstrumentation = class extends TdInstrumentationBase {
19724
19601
  decodedType: getDecodedType(outputValue.headers?.["content-type"] || "")
19725
19602
  },
19726
19603
  headers: { matchImportance: 0 }
19727
- },
19728
- metadata: { ENV_VARS: EnvVarTracker.getEnvVars(spanInfo.traceId) }
19604
+ }
19729
19605
  });
19730
- EnvVarTracker.clearEnvVars(spanInfo.traceId);
19731
19606
  const status = (capturedStatusCode || 200) >= 400 ? {
19732
19607
  code: import_src$11.SpanStatusCode.ERROR,
19733
19608
  message: `HTTP ${capturedStatusCode}`
@@ -19765,6 +19640,7 @@ var NextjsInstrumentation = class extends TdInstrumentationBase {
19765
19640
  instrumentationName: self.INSTRUMENTATION_NAME,
19766
19641
  submoduleName: completeInputValue.method,
19767
19642
  inputValue: completeInputValue,
19643
+ environment: self.tuskDrift.getEnvironment(),
19768
19644
  outputValue,
19769
19645
  inputSchema,
19770
19646
  outputSchema,
@@ -24254,7 +24130,7 @@ var SpanTransformer = class SpanTransformer {
24254
24130
  * Return type is derived from protobuf schema but uses clean JSON.
24255
24131
  * We use JSON because serialized protobuf is extremely verbose and not readable.
24256
24132
  */
24257
- static transformSpanToCleanJSON(span) {
24133
+ static transformSpanToCleanJSON(span, environment) {
24258
24134
  const isRootSpan = !span.parentSpanId || span.kind === import_src$9.SpanKind.SERVER;
24259
24135
  const attributes = span.attributes;
24260
24136
  const packageName = SpanTransformer.extractPackageName(attributes);
@@ -24298,6 +24174,7 @@ var SpanTransformer = class SpanTransformer {
24298
24174
  instrumentationName,
24299
24175
  submoduleName: submoduleName || "",
24300
24176
  packageType: attributes[TdSpanAttributes.PACKAGE_TYPE] || void 0,
24177
+ environment,
24301
24178
  inputValue: inputData,
24302
24179
  outputValue: outputData,
24303
24180
  inputSchema,
@@ -24761,7 +24638,7 @@ var ApiSpanAdapter = class {
24761
24638
  const protoSpans = spans.map((span) => this.transformSpanToProtobuf(span));
24762
24639
  const request = {
24763
24640
  observableServiceId: this.observableServiceId,
24764
- environment: this.environment,
24641
+ environment: this.environment || "",
24765
24642
  sdkVersion: this.sdkVersion,
24766
24643
  sdkInstanceId: this.sdkInstanceId,
24767
24644
  spans: protoSpans
@@ -24788,6 +24665,7 @@ var ApiSpanAdapter = class {
24788
24665
  instrumentationName: cleanSpan.instrumentationName,
24789
24666
  submoduleName: cleanSpan.submoduleName,
24790
24667
  packageType: cleanSpan.packageType || PackageType.UNSPECIFIED,
24668
+ environment: this.environment,
24791
24669
  inputValue: toStruct(cleanSpan.inputValue),
24792
24670
  outputValue: toStruct(cleanSpan.outputValue),
24793
24671
  inputSchema: cleanSpan.inputSchema,
@@ -24813,12 +24691,12 @@ var ApiSpanAdapter = class {
24813
24691
  }
24814
24692
  mapSpanKind(kind) {
24815
24693
  switch (kind) {
24816
- case import_src$7.SpanKind.CLIENT: return SpanKind.CLIENT;
24817
- case import_src$7.SpanKind.SERVER: return SpanKind.SERVER;
24818
- case import_src$7.SpanKind.PRODUCER: return SpanKind.PRODUCER;
24819
- case import_src$7.SpanKind.CONSUMER: return SpanKind.CONSUMER;
24820
- case import_src$7.SpanKind.INTERNAL: return SpanKind.INTERNAL;
24821
- default: return SpanKind.UNSPECIFIED;
24694
+ case import_src$7.SpanKind.CLIENT: return SpanKind$1.CLIENT;
24695
+ case import_src$7.SpanKind.SERVER: return SpanKind$1.SERVER;
24696
+ case import_src$7.SpanKind.PRODUCER: return SpanKind$1.PRODUCER;
24697
+ case import_src$7.SpanKind.CONSUMER: return SpanKind$1.CONSUMER;
24698
+ case import_src$7.SpanKind.INTERNAL: return SpanKind$1.INTERNAL;
24699
+ default: return SpanKind$1.UNSPECIFIED;
24822
24700
  }
24823
24701
  }
24824
24702
  async shutdown() {
@@ -24833,6 +24711,7 @@ var TdSpanExporter = class {
24833
24711
  constructor(config) {
24834
24712
  this.adapters = [];
24835
24713
  this.mode = config.mode;
24714
+ this.environment = config.environment;
24836
24715
  this.setupDefaultAdapters(config);
24837
24716
  logger.debug(`TdSpanExporter initialized with ${this.adapters.length} adapter(s)`);
24838
24717
  }
@@ -24916,7 +24795,7 @@ var TdSpanExporter = class {
24916
24795
  return true;
24917
24796
  });
24918
24797
  logger.debug(`Filtered ${filteredSpansBasedOnLibraryName.length - filteredBlockedSpans.length} blocked/oversized span(s), ${filteredBlockedSpans.length} remaining`);
24919
- const cleanSpans = filteredBlockedSpans.map((span) => SpanTransformer.transformSpanToCleanJSON(span));
24798
+ const cleanSpans = filteredBlockedSpans.map((span) => SpanTransformer.transformSpanToCleanJSON(span, this.environment));
24920
24799
  if (this.adapters.length === 0) {
24921
24800
  logger.debug("No adapters configured");
24922
24801
  resultCallback({ code: import_src$5.ExportResultCode.SUCCESS });
@@ -32067,7 +31946,7 @@ var require_src = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/sdk-
32067
31946
  //#endregion
32068
31947
  //#region package.json
32069
31948
  var import_src$1 = /* @__PURE__ */ __toESM(require_src(), 1);
32070
- var version = "0.1.17";
31949
+ var version = "0.1.18";
32071
31950
 
32072
31951
  //#endregion
32073
31952
  //#region src/version.ts
@@ -32075,7 +31954,7 @@ const SDK_VERSION = version;
32075
31954
  const MIN_CLI_VERSION = "0.1.0";
32076
31955
 
32077
31956
  //#endregion
32078
- //#region node_modules/@use-tusk/drift-schemas/dist/communication-D4zqMBSI.js
31957
+ //#region node_modules/@use-tusk/drift-schemas/dist/communication-BY2KZhrg.js
32079
31958
  var import_commonjs = /* @__PURE__ */ __toESM(require_commonjs$1(), 1);
32080
31959
  var import_commonjs$1 = /* @__PURE__ */ __toESM(require_commonjs$2(), 1);
32081
31960
  /**
@@ -33219,12 +33098,6 @@ var ProtobufCommunicator = class ProtobufCommunicator {
33219
33098
  });
33220
33099
  await this.sendProtobufMessage(sdkMessage);
33221
33100
  }
33222
- getStackTrace() {
33223
- Error.stackTraceLimit = 100;
33224
- const s = (/* @__PURE__ */ new Error()).stack || "";
33225
- Error.stackTraceLimit = 10;
33226
- return s.split("\n").slice(2).filter((l) => !l.includes("ProtobufCommunicator")).join("\n");
33227
- }
33228
33101
  async requestMockAsync(mockRequest) {
33229
33102
  const requestId = this.generateRequestId();
33230
33103
  const cleanSpan = mockRequest.outboundSpan ? this.cleanSpan(mockRequest.outboundSpan) : void 0;
@@ -33257,7 +33130,7 @@ var ProtobufCommunicator = class ProtobufCommunicator {
33257
33130
  /**
33258
33131
  * Generic synchronous request handler that spawns a child process.
33259
33132
  * @param sdkMessage The SDK message to send
33260
- * @param filePrefix Prefix for temporary files (e.g., 'envvar', 'mock')
33133
+ * @param filePrefix Prefix for temporary files (e.g., 'mock')
33261
33134
  * @param responseHandler Function to extract and return the desired response
33262
33135
  */
33263
33136
  executeSyncRequest(sdkMessage, filePrefix, responseHandler) {
@@ -33326,35 +33199,6 @@ var ProtobufCommunicator = class ProtobufCommunicator {
33326
33199
  }
33327
33200
  }
33328
33201
  /**
33329
- * Request environment variables from CLI synchronously using a child process.
33330
- * This blocks the main thread, so it should be used carefully.
33331
- * Similar to requestMockSync but for environment variables.
33332
- */
33333
- requestEnvVarsSync(traceTestServerSpanId) {
33334
- const requestId = this.generateRequestId();
33335
- const envVarRequest = EnvVarRequest.create({ traceTestServerSpanId });
33336
- const sdkMessage = SDKMessage.create({
33337
- type: MessageType$1.ENV_VAR_REQUEST,
33338
- requestId,
33339
- payload: {
33340
- oneofKind: "envVarRequest",
33341
- envVarRequest
33342
- }
33343
- });
33344
- logger.debug(`[ProtobufCommunicator] Requesting env vars (sync) for trace: ${traceTestServerSpanId}`);
33345
- return this.executeSyncRequest(sdkMessage, "envvar", (cliMessage) => {
33346
- if (cliMessage.payload.oneofKind !== "envVarResponse") throw new Error(`Unexpected response type: ${cliMessage.type}`);
33347
- const envVarResponse = cliMessage.payload.envVarResponse;
33348
- if (!envVarResponse) throw new Error("No env var response received");
33349
- const envVars = {};
33350
- if (envVarResponse.envVars) Object.entries(envVarResponse.envVars).forEach(([key, value]) => {
33351
- envVars[key] = value;
33352
- });
33353
- logger.debug(`[ProtobufCommunicator] Received env vars (sync), count: ${Object.keys(envVars).length}`);
33354
- return envVars;
33355
- });
33356
- }
33357
- /**
33358
33202
  * This function uses a separate Node.js child process to communicate with the CLI over a socket.
33359
33203
  * The child process creates its own connection and event loop, allowing proper async socket handling.
33360
33204
  * The parent process blocks synchronously waiting for the child to complete.
@@ -33565,22 +33409,6 @@ var ProtobufCommunicator = class ProtobufCommunicator {
33565
33409
  error: mockResponse.error || "Mock not found"
33566
33410
  });
33567
33411
  }
33568
- if (message.payload.oneofKind === "envVarResponse") {
33569
- const envVarResponse = message.payload.envVarResponse;
33570
- logger.debug(`[ProtobufCommunicator] Received env var response for requestId: ${requestId}`);
33571
- const pendingRequest = this.pendingRequests.get(requestId);
33572
- if (!pendingRequest) {
33573
- logger.warn("[ProtobufCommunicator] received env var response for unknown request:", requestId);
33574
- return;
33575
- }
33576
- this.pendingRequests.delete(requestId);
33577
- const envVars = {};
33578
- if (envVarResponse?.envVars) Object.entries(envVarResponse.envVars).forEach(([key, value]) => {
33579
- envVars[key] = value;
33580
- });
33581
- pendingRequest.resolve(envVars);
33582
- return;
33583
- }
33584
33412
  }
33585
33413
  /**
33586
33414
  * Extract response data from MockResponse
@@ -33880,10 +33708,6 @@ var TuskDriftCore = class TuskDriftCore {
33880
33708
  enabled: true,
33881
33709
  mode: this.mode
33882
33710
  });
33883
- new EnvInstrumentation({
33884
- enabled: this.config.recording?.enable_env_var_recording || false,
33885
- mode: this.mode
33886
- });
33887
33711
  new PostgresInstrumentation({
33888
33712
  enabled: true,
33889
33713
  mode: this.mode
@@ -33931,7 +33755,7 @@ var TuskDriftCore = class TuskDriftCore {
33931
33755
  observableServiceId: this.config.service?.id,
33932
33756
  apiKey: this.initParams.apiKey,
33933
33757
  tuskBackendBaseUrl: this.config.tusk_api?.url || "https://api.usetusk.ai",
33934
- environment: this.initParams.env || "unknown",
33758
+ environment: this.initParams.env,
33935
33759
  sdkVersion: SDK_VERSION,
33936
33760
  sdkInstanceId: this.generateSdkInstanceId()
33937
33761
  });
@@ -33949,6 +33773,34 @@ var TuskDriftCore = class TuskDriftCore {
33949
33773
  generateSdkInstanceId() {
33950
33774
  return `sdk-${OriginalGlobalUtils.getOriginalDate().getTime()}-${Math.random().toString(36).substr(2, 9)}`;
33951
33775
  }
33776
+ /**
33777
+ * Creates a pre-app-start span containing a snapshot of all environment variables.
33778
+ * Only runs in RECORD mode when env var recording is enabled.
33779
+ */
33780
+ createEnvVarsSnapshot() {
33781
+ if (this.mode !== TuskDriftMode.RECORD || !this.config.recording?.enable_env_var_recording) return;
33782
+ try {
33783
+ const envVarsSnapshot = {};
33784
+ for (const key of Object.keys(process.env)) envVarsSnapshot[key] = process.env[key];
33785
+ logger.debug(`Creating env vars snapshot with ${Object.keys(envVarsSnapshot).length} variables`);
33786
+ SpanUtils.createAndExecuteSpan(this.mode, () => {}, {
33787
+ name: "ENV_VARS_SNAPSHOT",
33788
+ kind: import_src.SpanKind.INTERNAL,
33789
+ packageName: "process.env",
33790
+ packageType: PackageType.UNSPECIFIED,
33791
+ instrumentationName: "TuskDriftCore",
33792
+ submodule: "env",
33793
+ inputValue: {},
33794
+ outputValue: { ENV_VARS: envVarsSnapshot },
33795
+ isPreAppStart: true
33796
+ }, (spanInfo) => {
33797
+ SpanUtils.endSpan(spanInfo.span, { code: import_src.SpanStatusCode.OK });
33798
+ logger.debug(`Env vars snapshot span created: ${spanInfo.spanId}`);
33799
+ });
33800
+ } catch (error) {
33801
+ logger.error("Failed to create env vars snapshot:", error);
33802
+ }
33803
+ }
33952
33804
  initialize(initParams) {
33953
33805
  initializeGlobalLogger({
33954
33806
  logLevel: initParams.logLevel || "info",
@@ -34025,6 +33877,7 @@ var TuskDriftCore = class TuskDriftCore {
34025
33877
  logger.debug(`Base directory: ${baseDirectory}`);
34026
33878
  this.registerDefaultInstrumentations();
34027
33879
  this.initializeTracing({ baseDirectory });
33880
+ this.createEnvVarsSnapshot();
34028
33881
  this.initialized = true;
34029
33882
  logger.info("SDK initialized successfully");
34030
33883
  }
@@ -34088,30 +33941,6 @@ var TuskDriftCore = class TuskDriftCore {
34088
33941
  };
34089
33942
  }
34090
33943
  }
34091
- /**
34092
- * Request environment variables from CLI for a specific trace (synchronously).
34093
- * This blocks the main thread, so it should be used carefully.
34094
- */
34095
- requestEnvVarsSync(traceTestServerSpanId) {
34096
- if (!this.isConnectedWithCLI) {
34097
- logger.error("Requesting sync env vars but CLI is not ready yet");
34098
- throw new Error("Requesting sync env vars but CLI is not ready yet");
34099
- }
34100
- if (!this.communicator || this.mode !== TuskDriftMode.REPLAY) {
34101
- logger.debug("Cannot request env vars: not in replay mode or no CLI connection");
34102
- return {};
34103
- }
34104
- try {
34105
- logger.debug(`Requesting env vars (sync) for trace: ${traceTestServerSpanId}`);
34106
- const envVars = this.communicator.requestEnvVarsSync(traceTestServerSpanId);
34107
- logger.debug(`Received env vars from CLI, count: ${Object.keys(envVars).length}`);
34108
- logger.debug(`First 10 env vars: ${JSON.stringify(Object.keys(envVars).slice(0, 10), null, 2)}`);
34109
- return envVars;
34110
- } catch (error) {
34111
- logger.error(`[TuskDrift] Error requesting env vars from CLI:`, error);
34112
- return {};
34113
- }
34114
- }
34115
33944
  requestMockSync(mockRequest) {
34116
33945
  if (!this.isConnectedWithCLI) {
34117
33946
  logger.error("Requesting sync mock but CLI is not ready yet");
@@ -34163,6 +33992,9 @@ var TuskDriftCore = class TuskDriftCore {
34163
33992
  getInitParams() {
34164
33993
  return this.initParams;
34165
33994
  }
33995
+ getEnvironment() {
33996
+ return this.initParams.env;
33997
+ }
34166
33998
  getTracer() {
34167
33999
  return import_src.trace.getTracer(TD_INSTRUMENTATION_LIBRARY_NAME);
34168
34000
  }