@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.js CHANGED
@@ -4978,31 +4978,31 @@ var require_SamplingResult = /* @__PURE__ */ __commonJS({ "node_modules/@opentel
4978
4978
  var require_span_kind = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/api/build/src/trace/span_kind.js": ((exports) => {
4979
4979
  Object.defineProperty(exports, "__esModule", { value: true });
4980
4980
  exports.SpanKind = void 0;
4981
- (function(SpanKind$24) {
4981
+ (function(SpanKind$25) {
4982
4982
  /** Default value. Indicates that the span is used internally. */
4983
- SpanKind$24[SpanKind$24["INTERNAL"] = 0] = "INTERNAL";
4983
+ SpanKind$25[SpanKind$25["INTERNAL"] = 0] = "INTERNAL";
4984
4984
  /**
4985
4985
  * Indicates that the span covers server-side handling of an RPC or other
4986
4986
  * remote request.
4987
4987
  */
4988
- SpanKind$24[SpanKind$24["SERVER"] = 1] = "SERVER";
4988
+ SpanKind$25[SpanKind$25["SERVER"] = 1] = "SERVER";
4989
4989
  /**
4990
4990
  * Indicates that the span covers the client-side wrapper around an RPC or
4991
4991
  * other remote request.
4992
4992
  */
4993
- SpanKind$24[SpanKind$24["CLIENT"] = 2] = "CLIENT";
4993
+ SpanKind$25[SpanKind$25["CLIENT"] = 2] = "CLIENT";
4994
4994
  /**
4995
4995
  * Indicates that the span describes producer sending a message to a
4996
4996
  * broker. Unlike client and server, there is no direct critical path latency
4997
4997
  * relationship between producer and consumer spans.
4998
4998
  */
4999
- SpanKind$24[SpanKind$24["PRODUCER"] = 3] = "PRODUCER";
4999
+ SpanKind$25[SpanKind$25["PRODUCER"] = 3] = "PRODUCER";
5000
5000
  /**
5001
5001
  * Indicates that the span describes consumer receiving a message from a
5002
5002
  * broker. Unlike client and server, there is no direct critical path latency
5003
5003
  * relationship between producer and consumer spans.
5004
5004
  */
5005
- SpanKind$24[SpanKind$24["CONSUMER"] = 4] = "CONSUMER";
5005
+ SpanKind$25[SpanKind$25["CONSUMER"] = 4] = "CONSUMER";
5006
5006
  })(exports.SpanKind || (exports.SpanKind = {}));
5007
5007
  }) });
5008
5008
 
@@ -5011,20 +5011,20 @@ var require_span_kind = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetr
5011
5011
  var require_status = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/api/build/src/trace/status.js": ((exports) => {
5012
5012
  Object.defineProperty(exports, "__esModule", { value: true });
5013
5013
  exports.SpanStatusCode = void 0;
5014
- (function(SpanStatusCode$13) {
5014
+ (function(SpanStatusCode$14) {
5015
5015
  /**
5016
5016
  * The default status.
5017
5017
  */
5018
- SpanStatusCode$13[SpanStatusCode$13["UNSET"] = 0] = "UNSET";
5018
+ SpanStatusCode$14[SpanStatusCode$14["UNSET"] = 0] = "UNSET";
5019
5019
  /**
5020
5020
  * The operation has been validated by an Application developer or
5021
5021
  * Operator to have completed successfully.
5022
5022
  */
5023
- SpanStatusCode$13[SpanStatusCode$13["OK"] = 1] = "OK";
5023
+ SpanStatusCode$14[SpanStatusCode$14["OK"] = 1] = "OK";
5024
5024
  /**
5025
5025
  * The operation contains an error.
5026
5026
  */
5027
- SpanStatusCode$13[SpanStatusCode$13["ERROR"] = 2] = "ERROR";
5027
+ SpanStatusCode$14[SpanStatusCode$14["ERROR"] = 2] = "ERROR";
5028
5028
  })(exports.SpanStatusCode || (exports.SpanStatusCode = {}));
5029
5029
  }) });
5030
5030
 
@@ -6198,7 +6198,7 @@ var JsonSchema$Type = class extends import_commonjs$7.MessageType {
6198
6198
  const JsonSchema = new JsonSchema$Type();
6199
6199
 
6200
6200
  //#endregion
6201
- //#region node_modules/@use-tusk/drift-schemas/dist/span-BZ89ct3l.js
6201
+ //#region node_modules/@use-tusk/drift-schemas/dist/span-CsBrzhI_.js
6202
6202
  var import_commonjs$6 = /* @__PURE__ */ __toESM(require_commonjs$2(), 1);
6203
6203
  /**
6204
6204
  * Package type classification enum
@@ -6284,7 +6284,7 @@ let PackageType = /* @__PURE__ */ function(PackageType$1) {
6284
6284
  *
6285
6285
  * @generated from protobuf enum tusk.drift.core.v1.SpanKind
6286
6286
  */
6287
- let SpanKind = /* @__PURE__ */ function(SpanKind$1$1) {
6287
+ let SpanKind$1 = /* @__PURE__ */ function(SpanKind$1$1) {
6288
6288
  /**
6289
6289
  * @generated from protobuf enum value: SPAN_KIND_UNSPECIFIED = 0;
6290
6290
  */
@@ -6454,7 +6454,7 @@ var Span$Type = class extends import_commonjs$6.MessageType {
6454
6454
  kind: "enum",
6455
6455
  T: () => [
6456
6456
  "tusk.drift.core.v1.SpanKind",
6457
- SpanKind,
6457
+ SpanKind$1,
6458
6458
  "SPAN_KIND_"
6459
6459
  ]
6460
6460
  },
@@ -6493,6 +6493,13 @@ var Span$Type = class extends import_commonjs$6.MessageType {
6493
6493
  name: "metadata",
6494
6494
  kind: "message",
6495
6495
  T: () => Struct
6496
+ },
6497
+ {
6498
+ no: 24,
6499
+ name: "environment",
6500
+ kind: "scalar",
6501
+ opt: true,
6502
+ T: 9
6496
6503
  }
6497
6504
  ]);
6498
6505
  }
@@ -6590,6 +6597,9 @@ var Span$Type = class extends import_commonjs$6.MessageType {
6590
6597
  case 23:
6591
6598
  message.metadata = Struct.internalBinaryRead(reader, reader.uint32(), options, message.metadata);
6592
6599
  break;
6600
+ case 24:
6601
+ message.environment = reader.string();
6602
+ break;
6593
6603
  default:
6594
6604
  let u = options.readUnknownField;
6595
6605
  if (u === "throw") throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
@@ -6623,6 +6633,7 @@ var Span$Type = class extends import_commonjs$6.MessageType {
6623
6633
  if (message.duration) Duration.internalBinaryWrite(message.duration, writer.tag(21, import_commonjs$6.WireType.LengthDelimited).fork(), options).join();
6624
6634
  if (message.isRootSpan !== false) writer.tag(22, import_commonjs$6.WireType.Varint).bool(message.isRootSpan);
6625
6635
  if (message.metadata) Struct.internalBinaryWrite(message.metadata, writer.tag(23, import_commonjs$6.WireType.LengthDelimited).fork(), options).join();
6636
+ if (message.environment !== void 0) writer.tag(24, import_commonjs$6.WireType.LengthDelimited).string(message.environment);
6626
6637
  let u = options.writeUnknownFields;
6627
6638
  if (u !== false) (u == true ? import_commonjs$6.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
6628
6639
  return writer;
@@ -6986,12 +6997,12 @@ const Trace = new Trace$Type();
6986
6997
  const toStruct = (obj) => obj ? objectToProtobufStruct(obj) : void 0;
6987
6998
  const mapOtToPb = (k) => {
6988
6999
  switch (k) {
6989
- case import_src$34.SpanKind.INTERNAL: return SpanKind.INTERNAL;
6990
- case import_src$34.SpanKind.SERVER: return SpanKind.SERVER;
6991
- case import_src$34.SpanKind.CLIENT: return SpanKind.CLIENT;
6992
- case import_src$34.SpanKind.PRODUCER: return SpanKind.PRODUCER;
6993
- case import_src$34.SpanKind.CONSUMER: return SpanKind.CONSUMER;
6994
- default: return SpanKind.UNSPECIFIED;
7000
+ case import_src$34.SpanKind.INTERNAL: return SpanKind$1.INTERNAL;
7001
+ case import_src$34.SpanKind.SERVER: return SpanKind$1.SERVER;
7002
+ case import_src$34.SpanKind.CLIENT: return SpanKind$1.CLIENT;
7003
+ case import_src$34.SpanKind.PRODUCER: return SpanKind$1.PRODUCER;
7004
+ case import_src$34.SpanKind.CONSUMER: return SpanKind$1.CONSUMER;
7005
+ default: return SpanKind$1.UNSPECIFIED;
6995
7006
  }
6996
7007
  };
6997
7008
  /**
@@ -7575,7 +7586,7 @@ var SpanUtils = class SpanUtils {
7575
7586
  return originalFunctionCall();
7576
7587
  }
7577
7588
  }
7578
- const { name, kind, packageName, instrumentationName, packageType, submodule, inputValue, inputSchemaMerges, isPreAppStart, metadata, stopRecordingChildSpans } = options;
7589
+ const { name, kind, packageName, instrumentationName, packageType, submodule, inputValue, outputValue, inputSchemaMerges, isPreAppStart, metadata, stopRecordingChildSpans } = options;
7579
7590
  let spanInfo = null;
7580
7591
  try {
7581
7592
  spanInfo = SpanUtils.createSpan({
@@ -7589,6 +7600,7 @@ var SpanUtils = class SpanUtils {
7589
7600
  [TdSpanAttributes.INSTRUMENTATION_NAME]: instrumentationName,
7590
7601
  [TdSpanAttributes.PACKAGE_TYPE]: packageType,
7591
7602
  [TdSpanAttributes.INPUT_VALUE]: createSpanInputValue(inputValue),
7603
+ ...outputValue && { [TdSpanAttributes.OUTPUT_VALUE]: JSON.stringify(outputValue) },
7592
7604
  [TdSpanAttributes.IS_PRE_APP_START]: isPreAppStart,
7593
7605
  ...inputSchemaMerges && { [TdSpanAttributes.INPUT_SCHEMA_MERGES]: JSON.stringify(inputSchemaMerges) },
7594
7606
  ...metadata && { [TdSpanAttributes.METADATA]: JSON.stringify(metadata) }
@@ -7955,30 +7967,6 @@ var TdHttpMockSocket = class extends EventEmitter {
7955
7967
  }
7956
7968
  };
7957
7969
 
7958
- //#endregion
7959
- //#region src/instrumentation/core/trackers/EnvVarTracker.ts
7960
- var EnvVarTracker = class {
7961
- static setEnvVar({ traceId, key, value }) {
7962
- this.envVars.set(traceId, {
7963
- ...this.envVars.get(traceId) || {},
7964
- [key]: value
7965
- });
7966
- }
7967
- static setEnvVars(traceId, envVars) {
7968
- this.envVars.set(traceId, envVars);
7969
- }
7970
- static getEnvVar(traceId, key) {
7971
- return this.envVars.get(traceId)?.[key];
7972
- }
7973
- static getEnvVars(traceId) {
7974
- return this.envVars.get(traceId);
7975
- }
7976
- static clearEnvVars(traceId) {
7977
- this.envVars.delete(traceId);
7978
- }
7979
- };
7980
- EnvVarTracker.envVars = /* @__PURE__ */ new Map();
7981
-
7982
7970
  //#endregion
7983
7971
  //#region src/instrumentation/core/trackers/DateTracker.ts
7984
7972
  /**
@@ -8279,6 +8267,7 @@ function convertMockRequestDataToCleanSpanData(mockRequestData, tuskDrift, input
8279
8267
  return {
8280
8268
  ...mockRequestData,
8281
8269
  parentSpanId: "",
8270
+ environment: tuskDrift.getEnvironment(),
8282
8271
  inputValueHash,
8283
8272
  inputSchema,
8284
8273
  inputSchemaHash,
@@ -8675,13 +8664,6 @@ var HttpReplayHooks = class {
8675
8664
  return traceIdHeader ? String(traceIdHeader) : null;
8676
8665
  }
8677
8666
  /**
8678
- * Check if we should fetch env vars from CLI
8679
- */
8680
- extractShouldFetchEnvVars(req) {
8681
- const fetchHeader = req.headers["x-td-fetch-env-vars"] || req.headers["X-TD-FETCH-ENV-VARS"];
8682
- return fetchHeader === "true" || fetchHeader === true;
8683
- }
8684
- /**
8685
8667
  * Handle outbound HTTP requests in replay mode
8686
8668
  * Uses TdMockClientRequest for simplified mocking approach
8687
8669
  */
@@ -9970,7 +9952,7 @@ var require_commonjs$1 = /* @__PURE__ */ __commonJS({ "node_modules/@protobuf-ts
9970
9952
  }) });
9971
9953
 
9972
9954
  //#endregion
9973
- //#region node_modules/@use-tusk/drift-schemas/dist/span_export_service-XwF6hpEK.js
9955
+ //#region node_modules/@use-tusk/drift-schemas/dist/span_export_service-CmkFvTqD.js
9974
9956
  var import_commonjs$4 = /* @__PURE__ */ __toESM(require_commonjs$1(), 1);
9975
9957
  var import_commonjs$5 = /* @__PURE__ */ __toESM(require_commonjs$2(), 1);
9976
9958
  var ExportSpansRequest$Type = class extends import_commonjs$5.MessageType {
@@ -10660,13 +10642,6 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10660
10642
  return originalHandler.call(this);
10661
10643
  }
10662
10644
  logger.debug(`[HttpInstrumentation] Setting replay trace id`, replayTraceId);
10663
- if (this.replayHooks.extractShouldFetchEnvVars(req)) try {
10664
- const envVars = this.tuskDrift.requestEnvVarsSync(replayTraceId);
10665
- EnvVarTracker.setEnvVars(replayTraceId, envVars);
10666
- logger.debug(`[HttpInstrumentation] Fetched env vars from CLI for trace ${replayTraceId}`);
10667
- } catch (error) {
10668
- logger.error(`[HttpInstrumentation] Failed to fetch env vars from CLI:`, error);
10669
- }
10670
10645
  const ctxWithReplayTraceId = SpanUtils.setCurrentReplayTraceId(replayTraceId);
10671
10646
  if (!ctxWithReplayTraceId) throw new Error("Error setting current replay trace id");
10672
10647
  return import_src$28.context.with(ctxWithReplayTraceId, () => {
@@ -10809,10 +10784,8 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10809
10784
  },
10810
10785
  headers: { matchImportance: 0 }
10811
10786
  },
10812
- metadata: { ENV_VARS: EnvVarTracker.getEnvVars(spanInfo.traceId) },
10813
10787
  ...spanData.transformMetadata && { transformMetadata: spanData.transformMetadata }
10814
10788
  });
10815
- EnvVarTracker.clearEnvVars(spanInfo.traceId);
10816
10789
  const status = statusCode >= 400 ? {
10817
10790
  code: import_src$28.SpanStatusCode.ERROR,
10818
10791
  message: `HTTP ${statusCode}`
@@ -10858,6 +10831,7 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
10858
10831
  instrumentationName: "HttpInstrumentation",
10859
10832
  submoduleName: completeInputValue.method || inputValue.method,
10860
10833
  inputValue: completeInputValue,
10834
+ environment: self.tuskDrift.getEnvironment(),
10861
10835
  outputValue,
10862
10836
  inputSchema,
10863
10837
  outputSchema,
@@ -11378,96 +11352,6 @@ var HttpInstrumentation = class extends TdInstrumentationBase {
11378
11352
  }
11379
11353
  };
11380
11354
 
11381
- //#endregion
11382
- //#region src/instrumentation/libraries/env/Instrumentation.ts
11383
- /**
11384
- * Environment variable instrumentation that records and replays process.env access.
11385
- * In record mode, captures environment variable values.
11386
- * In replay mode, returns previously recorded values for deterministic behavior.
11387
- */
11388
- var EnvInstrumentation = class extends TdInstrumentationBase {
11389
- constructor(config = {}) {
11390
- super("env", config);
11391
- this.isInPatchedCall = false;
11392
- this.mode = config.mode || TuskDriftMode.DISABLED;
11393
- }
11394
- init() {
11395
- this.patchProcessEnv();
11396
- return [];
11397
- }
11398
- patchProcessEnv() {
11399
- if (this.mode === TuskDriftMode.DISABLED || !this._config.enabled) return;
11400
- this.originalProcessEnv = process.env;
11401
- const envProxy = new Proxy(this.originalProcessEnv, {
11402
- get: (target, property, receiver) => {
11403
- return this._handleEnvAccess(target, property);
11404
- },
11405
- set: (target, property, value, receiver) => {
11406
- target[property] = value;
11407
- return true;
11408
- },
11409
- deleteProperty: (target, property) => {
11410
- delete target[property];
11411
- return true;
11412
- },
11413
- ownKeys: (target) => {
11414
- return Reflect.ownKeys(target);
11415
- },
11416
- getOwnPropertyDescriptor: (target, property) => {
11417
- return Reflect.getOwnPropertyDescriptor(target, property);
11418
- },
11419
- has: (target, property) => {
11420
- return Reflect.has(target, property);
11421
- }
11422
- });
11423
- process.env = envProxy;
11424
- }
11425
- _handleEnvAccess(target, key) {
11426
- if (this.isInPatchedCall) return target[key];
11427
- if (!TuskDriftCore.getInstance().isAppReady()) return target[key];
11428
- this.isInPatchedCall = true;
11429
- try {
11430
- return this._handleEnvAccessInMode(target, key);
11431
- } finally {
11432
- this.isInPatchedCall = false;
11433
- }
11434
- }
11435
- _handleEnvAccessInMode(target, key) {
11436
- let currentSpanInfo = null;
11437
- try {
11438
- currentSpanInfo = SpanUtils.getCurrentSpanInfo();
11439
- } catch (error) {
11440
- logger.error(`EnvInstrumentation error getting current span info:`, error);
11441
- }
11442
- if (!currentSpanInfo) return target[key];
11443
- if (this.mode === TuskDriftMode.REPLAY) return this._handleReplayMode(target, key);
11444
- else if (this.mode === TuskDriftMode.RECORD) return this._handleRecordMode(currentSpanInfo, target, key);
11445
- else return target[key];
11446
- }
11447
- _handleReplayMode(target, key) {
11448
- const replayTraceId = SpanUtils.getCurrentReplayTraceId();
11449
- if (!replayTraceId) return target[key];
11450
- const envVar = EnvVarTracker.getEnvVar(replayTraceId, key);
11451
- if (envVar) {
11452
- logger.debug(`Returning env var ${key} for trace ${replayTraceId}: ${envVar}`);
11453
- return envVar;
11454
- }
11455
- return target[key];
11456
- }
11457
- _handleRecordMode(spanInfo, target, key) {
11458
- try {
11459
- EnvVarTracker.setEnvVar({
11460
- traceId: spanInfo.traceId,
11461
- key,
11462
- value: target[key] || void 0
11463
- });
11464
- } catch (error) {
11465
- logger.error(`EnvInstrumentation error storing env var:`, error);
11466
- }
11467
- return target[key];
11468
- }
11469
- };
11470
-
11471
11355
  //#endregion
11472
11356
  //#region src/instrumentation/libraries/date/Instrumentation.ts
11473
11357
  var import_src$27 = /* @__PURE__ */ __toESM(require_src$7(), 1);
@@ -19552,13 +19436,6 @@ var NextjsInstrumentation = class extends TdInstrumentationBase {
19552
19436
  return originalHandleRequest.call(this, req, res, parsedUrl);
19553
19437
  }
19554
19438
  logger.debug(`[NextjsInstrumentation] Setting replay trace id`, replayTraceId);
19555
- if (self.replayHooks.extractShouldFetchEnvVars(req)) try {
19556
- const envVars = self.tuskDrift.requestEnvVarsSync(replayTraceId);
19557
- EnvVarTracker.setEnvVars(replayTraceId, envVars);
19558
- logger.debug(`[NextjsInstrumentation] Fetched env vars from CLI for trace ${replayTraceId}`);
19559
- } catch (error) {
19560
- logger.error(`[NextjsInstrumentation] Failed to fetch env vars from CLI:`, error);
19561
- }
19562
19439
  const ctxWithReplayTraceId = SpanUtils.setCurrentReplayTraceId(replayTraceId);
19563
19440
  if (!ctxWithReplayTraceId) throw new Error("Error setting current replay trace id");
19564
19441
  return import_src$11.context.with(ctxWithReplayTraceId, () => {
@@ -19713,10 +19590,8 @@ var NextjsInstrumentation = class extends TdInstrumentationBase {
19713
19590
  decodedType: getDecodedType(outputValue.headers?.["content-type"] || "")
19714
19591
  },
19715
19592
  headers: { matchImportance: 0 }
19716
- },
19717
- metadata: { ENV_VARS: EnvVarTracker.getEnvVars(spanInfo.traceId) }
19593
+ }
19718
19594
  });
19719
- EnvVarTracker.clearEnvVars(spanInfo.traceId);
19720
19595
  const status = (capturedStatusCode || 200) >= 400 ? {
19721
19596
  code: import_src$11.SpanStatusCode.ERROR,
19722
19597
  message: `HTTP ${capturedStatusCode}`
@@ -19754,6 +19629,7 @@ var NextjsInstrumentation = class extends TdInstrumentationBase {
19754
19629
  instrumentationName: self.INSTRUMENTATION_NAME,
19755
19630
  submoduleName: completeInputValue.method,
19756
19631
  inputValue: completeInputValue,
19632
+ environment: self.tuskDrift.getEnvironment(),
19757
19633
  outputValue,
19758
19634
  inputSchema,
19759
19635
  outputSchema,
@@ -24243,7 +24119,7 @@ var SpanTransformer = class SpanTransformer {
24243
24119
  * Return type is derived from protobuf schema but uses clean JSON.
24244
24120
  * We use JSON because serialized protobuf is extremely verbose and not readable.
24245
24121
  */
24246
- static transformSpanToCleanJSON(span) {
24122
+ static transformSpanToCleanJSON(span, environment) {
24247
24123
  const isRootSpan = !span.parentSpanId || span.kind === import_src$9.SpanKind.SERVER;
24248
24124
  const attributes = span.attributes;
24249
24125
  const packageName = SpanTransformer.extractPackageName(attributes);
@@ -24287,6 +24163,7 @@ var SpanTransformer = class SpanTransformer {
24287
24163
  instrumentationName,
24288
24164
  submoduleName: submoduleName || "",
24289
24165
  packageType: attributes[TdSpanAttributes.PACKAGE_TYPE] || void 0,
24166
+ environment,
24290
24167
  inputValue: inputData,
24291
24168
  outputValue: outputData,
24292
24169
  inputSchema,
@@ -24750,7 +24627,7 @@ var ApiSpanAdapter = class {
24750
24627
  const protoSpans = spans.map((span) => this.transformSpanToProtobuf(span));
24751
24628
  const request = {
24752
24629
  observableServiceId: this.observableServiceId,
24753
- environment: this.environment,
24630
+ environment: this.environment || "",
24754
24631
  sdkVersion: this.sdkVersion,
24755
24632
  sdkInstanceId: this.sdkInstanceId,
24756
24633
  spans: protoSpans
@@ -24777,6 +24654,7 @@ var ApiSpanAdapter = class {
24777
24654
  instrumentationName: cleanSpan.instrumentationName,
24778
24655
  submoduleName: cleanSpan.submoduleName,
24779
24656
  packageType: cleanSpan.packageType || PackageType.UNSPECIFIED,
24657
+ environment: this.environment,
24780
24658
  inputValue: toStruct(cleanSpan.inputValue),
24781
24659
  outputValue: toStruct(cleanSpan.outputValue),
24782
24660
  inputSchema: cleanSpan.inputSchema,
@@ -24802,12 +24680,12 @@ var ApiSpanAdapter = class {
24802
24680
  }
24803
24681
  mapSpanKind(kind) {
24804
24682
  switch (kind) {
24805
- case import_src$7.SpanKind.CLIENT: return SpanKind.CLIENT;
24806
- case import_src$7.SpanKind.SERVER: return SpanKind.SERVER;
24807
- case import_src$7.SpanKind.PRODUCER: return SpanKind.PRODUCER;
24808
- case import_src$7.SpanKind.CONSUMER: return SpanKind.CONSUMER;
24809
- case import_src$7.SpanKind.INTERNAL: return SpanKind.INTERNAL;
24810
- default: return SpanKind.UNSPECIFIED;
24683
+ case import_src$7.SpanKind.CLIENT: return SpanKind$1.CLIENT;
24684
+ case import_src$7.SpanKind.SERVER: return SpanKind$1.SERVER;
24685
+ case import_src$7.SpanKind.PRODUCER: return SpanKind$1.PRODUCER;
24686
+ case import_src$7.SpanKind.CONSUMER: return SpanKind$1.CONSUMER;
24687
+ case import_src$7.SpanKind.INTERNAL: return SpanKind$1.INTERNAL;
24688
+ default: return SpanKind$1.UNSPECIFIED;
24811
24689
  }
24812
24690
  }
24813
24691
  async shutdown() {
@@ -24822,6 +24700,7 @@ var TdSpanExporter = class {
24822
24700
  constructor(config) {
24823
24701
  this.adapters = [];
24824
24702
  this.mode = config.mode;
24703
+ this.environment = config.environment;
24825
24704
  this.setupDefaultAdapters(config);
24826
24705
  logger.debug(`TdSpanExporter initialized with ${this.adapters.length} adapter(s)`);
24827
24706
  }
@@ -24905,7 +24784,7 @@ var TdSpanExporter = class {
24905
24784
  return true;
24906
24785
  });
24907
24786
  logger.debug(`Filtered ${filteredSpansBasedOnLibraryName.length - filteredBlockedSpans.length} blocked/oversized span(s), ${filteredBlockedSpans.length} remaining`);
24908
- const cleanSpans = filteredBlockedSpans.map((span) => SpanTransformer.transformSpanToCleanJSON(span));
24787
+ const cleanSpans = filteredBlockedSpans.map((span) => SpanTransformer.transformSpanToCleanJSON(span, this.environment));
24909
24788
  if (this.adapters.length === 0) {
24910
24789
  logger.debug("No adapters configured");
24911
24790
  resultCallback({ code: import_src$5.ExportResultCode.SUCCESS });
@@ -32056,7 +31935,7 @@ var require_src = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/sdk-
32056
31935
  //#endregion
32057
31936
  //#region package.json
32058
31937
  var import_src$1 = /* @__PURE__ */ __toESM(require_src(), 1);
32059
- var version = "0.1.17";
31938
+ var version = "0.1.18";
32060
31939
 
32061
31940
  //#endregion
32062
31941
  //#region src/version.ts
@@ -32064,7 +31943,7 @@ const SDK_VERSION = version;
32064
31943
  const MIN_CLI_VERSION = "0.1.0";
32065
31944
 
32066
31945
  //#endregion
32067
- //#region node_modules/@use-tusk/drift-schemas/dist/communication-D4zqMBSI.js
31946
+ //#region node_modules/@use-tusk/drift-schemas/dist/communication-BY2KZhrg.js
32068
31947
  var import_commonjs = /* @__PURE__ */ __toESM(require_commonjs$1(), 1);
32069
31948
  var import_commonjs$1 = /* @__PURE__ */ __toESM(require_commonjs$2(), 1);
32070
31949
  /**
@@ -33208,12 +33087,6 @@ var ProtobufCommunicator = class ProtobufCommunicator {
33208
33087
  });
33209
33088
  await this.sendProtobufMessage(sdkMessage);
33210
33089
  }
33211
- getStackTrace() {
33212
- Error.stackTraceLimit = 100;
33213
- const s = (/* @__PURE__ */ new Error()).stack || "";
33214
- Error.stackTraceLimit = 10;
33215
- return s.split("\n").slice(2).filter((l) => !l.includes("ProtobufCommunicator")).join("\n");
33216
- }
33217
33090
  async requestMockAsync(mockRequest) {
33218
33091
  const requestId = this.generateRequestId();
33219
33092
  const cleanSpan = mockRequest.outboundSpan ? this.cleanSpan(mockRequest.outboundSpan) : void 0;
@@ -33246,7 +33119,7 @@ var ProtobufCommunicator = class ProtobufCommunicator {
33246
33119
  /**
33247
33120
  * Generic synchronous request handler that spawns a child process.
33248
33121
  * @param sdkMessage The SDK message to send
33249
- * @param filePrefix Prefix for temporary files (e.g., 'envvar', 'mock')
33122
+ * @param filePrefix Prefix for temporary files (e.g., 'mock')
33250
33123
  * @param responseHandler Function to extract and return the desired response
33251
33124
  */
33252
33125
  executeSyncRequest(sdkMessage, filePrefix, responseHandler) {
@@ -33315,35 +33188,6 @@ var ProtobufCommunicator = class ProtobufCommunicator {
33315
33188
  }
33316
33189
  }
33317
33190
  /**
33318
- * Request environment variables from CLI synchronously using a child process.
33319
- * This blocks the main thread, so it should be used carefully.
33320
- * Similar to requestMockSync but for environment variables.
33321
- */
33322
- requestEnvVarsSync(traceTestServerSpanId) {
33323
- const requestId = this.generateRequestId();
33324
- const envVarRequest = EnvVarRequest.create({ traceTestServerSpanId });
33325
- const sdkMessage = SDKMessage.create({
33326
- type: MessageType$1.ENV_VAR_REQUEST,
33327
- requestId,
33328
- payload: {
33329
- oneofKind: "envVarRequest",
33330
- envVarRequest
33331
- }
33332
- });
33333
- logger.debug(`[ProtobufCommunicator] Requesting env vars (sync) for trace: ${traceTestServerSpanId}`);
33334
- return this.executeSyncRequest(sdkMessage, "envvar", (cliMessage) => {
33335
- if (cliMessage.payload.oneofKind !== "envVarResponse") throw new Error(`Unexpected response type: ${cliMessage.type}`);
33336
- const envVarResponse = cliMessage.payload.envVarResponse;
33337
- if (!envVarResponse) throw new Error("No env var response received");
33338
- const envVars = {};
33339
- if (envVarResponse.envVars) Object.entries(envVarResponse.envVars).forEach(([key, value]) => {
33340
- envVars[key] = value;
33341
- });
33342
- logger.debug(`[ProtobufCommunicator] Received env vars (sync), count: ${Object.keys(envVars).length}`);
33343
- return envVars;
33344
- });
33345
- }
33346
- /**
33347
33191
  * This function uses a separate Node.js child process to communicate with the CLI over a socket.
33348
33192
  * The child process creates its own connection and event loop, allowing proper async socket handling.
33349
33193
  * The parent process blocks synchronously waiting for the child to complete.
@@ -33554,22 +33398,6 @@ var ProtobufCommunicator = class ProtobufCommunicator {
33554
33398
  error: mockResponse.error || "Mock not found"
33555
33399
  });
33556
33400
  }
33557
- if (message.payload.oneofKind === "envVarResponse") {
33558
- const envVarResponse = message.payload.envVarResponse;
33559
- logger.debug(`[ProtobufCommunicator] Received env var response for requestId: ${requestId}`);
33560
- const pendingRequest = this.pendingRequests.get(requestId);
33561
- if (!pendingRequest) {
33562
- logger.warn("[ProtobufCommunicator] received env var response for unknown request:", requestId);
33563
- return;
33564
- }
33565
- this.pendingRequests.delete(requestId);
33566
- const envVars = {};
33567
- if (envVarResponse?.envVars) Object.entries(envVarResponse.envVars).forEach(([key, value]) => {
33568
- envVars[key] = value;
33569
- });
33570
- pendingRequest.resolve(envVars);
33571
- return;
33572
- }
33573
33401
  }
33574
33402
  /**
33575
33403
  * Extract response data from MockResponse
@@ -33869,10 +33697,6 @@ var TuskDriftCore = class TuskDriftCore {
33869
33697
  enabled: true,
33870
33698
  mode: this.mode
33871
33699
  });
33872
- new EnvInstrumentation({
33873
- enabled: this.config.recording?.enable_env_var_recording || false,
33874
- mode: this.mode
33875
- });
33876
33700
  new PostgresInstrumentation({
33877
33701
  enabled: true,
33878
33702
  mode: this.mode
@@ -33920,7 +33744,7 @@ var TuskDriftCore = class TuskDriftCore {
33920
33744
  observableServiceId: this.config.service?.id,
33921
33745
  apiKey: this.initParams.apiKey,
33922
33746
  tuskBackendBaseUrl: this.config.tusk_api?.url || "https://api.usetusk.ai",
33923
- environment: this.initParams.env || "unknown",
33747
+ environment: this.initParams.env,
33924
33748
  sdkVersion: SDK_VERSION,
33925
33749
  sdkInstanceId: this.generateSdkInstanceId()
33926
33750
  });
@@ -33938,6 +33762,34 @@ var TuskDriftCore = class TuskDriftCore {
33938
33762
  generateSdkInstanceId() {
33939
33763
  return `sdk-${OriginalGlobalUtils.getOriginalDate().getTime()}-${Math.random().toString(36).substr(2, 9)}`;
33940
33764
  }
33765
+ /**
33766
+ * Creates a pre-app-start span containing a snapshot of all environment variables.
33767
+ * Only runs in RECORD mode when env var recording is enabled.
33768
+ */
33769
+ createEnvVarsSnapshot() {
33770
+ if (this.mode !== TuskDriftMode.RECORD || !this.config.recording?.enable_env_var_recording) return;
33771
+ try {
33772
+ const envVarsSnapshot = {};
33773
+ for (const key of Object.keys(process.env)) envVarsSnapshot[key] = process.env[key];
33774
+ logger.debug(`Creating env vars snapshot with ${Object.keys(envVarsSnapshot).length} variables`);
33775
+ SpanUtils.createAndExecuteSpan(this.mode, () => {}, {
33776
+ name: "ENV_VARS_SNAPSHOT",
33777
+ kind: import_src.SpanKind.INTERNAL,
33778
+ packageName: "process.env",
33779
+ packageType: PackageType.UNSPECIFIED,
33780
+ instrumentationName: "TuskDriftCore",
33781
+ submodule: "env",
33782
+ inputValue: {},
33783
+ outputValue: { ENV_VARS: envVarsSnapshot },
33784
+ isPreAppStart: true
33785
+ }, (spanInfo) => {
33786
+ SpanUtils.endSpan(spanInfo.span, { code: import_src.SpanStatusCode.OK });
33787
+ logger.debug(`Env vars snapshot span created: ${spanInfo.spanId}`);
33788
+ });
33789
+ } catch (error) {
33790
+ logger.error("Failed to create env vars snapshot:", error);
33791
+ }
33792
+ }
33941
33793
  initialize(initParams) {
33942
33794
  initializeGlobalLogger({
33943
33795
  logLevel: initParams.logLevel || "info",
@@ -34014,6 +33866,7 @@ var TuskDriftCore = class TuskDriftCore {
34014
33866
  logger.debug(`Base directory: ${baseDirectory}`);
34015
33867
  this.registerDefaultInstrumentations();
34016
33868
  this.initializeTracing({ baseDirectory });
33869
+ this.createEnvVarsSnapshot();
34017
33870
  this.initialized = true;
34018
33871
  logger.info("SDK initialized successfully");
34019
33872
  }
@@ -34077,30 +33930,6 @@ var TuskDriftCore = class TuskDriftCore {
34077
33930
  };
34078
33931
  }
34079
33932
  }
34080
- /**
34081
- * Request environment variables from CLI for a specific trace (synchronously).
34082
- * This blocks the main thread, so it should be used carefully.
34083
- */
34084
- requestEnvVarsSync(traceTestServerSpanId) {
34085
- if (!this.isConnectedWithCLI) {
34086
- logger.error("Requesting sync env vars but CLI is not ready yet");
34087
- throw new Error("Requesting sync env vars but CLI is not ready yet");
34088
- }
34089
- if (!this.communicator || this.mode !== TuskDriftMode.REPLAY) {
34090
- logger.debug("Cannot request env vars: not in replay mode or no CLI connection");
34091
- return {};
34092
- }
34093
- try {
34094
- logger.debug(`Requesting env vars (sync) for trace: ${traceTestServerSpanId}`);
34095
- const envVars = this.communicator.requestEnvVarsSync(traceTestServerSpanId);
34096
- logger.debug(`Received env vars from CLI, count: ${Object.keys(envVars).length}`);
34097
- logger.debug(`First 10 env vars: ${JSON.stringify(Object.keys(envVars).slice(0, 10), null, 2)}`);
34098
- return envVars;
34099
- } catch (error) {
34100
- logger.error(`[TuskDrift] Error requesting env vars from CLI:`, error);
34101
- return {};
34102
- }
34103
- }
34104
33933
  requestMockSync(mockRequest) {
34105
33934
  if (!this.isConnectedWithCLI) {
34106
33935
  logger.error("Requesting sync mock but CLI is not ready yet");
@@ -34152,6 +33981,9 @@ var TuskDriftCore = class TuskDriftCore {
34152
33981
  getInitParams() {
34153
33982
  return this.initParams;
34154
33983
  }
33984
+ getEnvironment() {
33985
+ return this.initParams.env;
33986
+ }
34155
33987
  getTracer() {
34156
33988
  return import_src.trace.getTracer(TD_INSTRUMENTATION_LIBRARY_NAME);
34157
33989
  }