@loadstrike/loadstrike-sdk 1.0.21401 → 1.0.22301

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.
@@ -1724,9 +1724,10 @@ class LoadStrikeScenario {
1724
1724
  throw new Error("Tracking source endpoint must be provided.");
1725
1725
  }
1726
1726
  const destinationSpec = asTrackingRecord(pickTrackingValue(copied, "Destination", "destination"));
1727
- const sourceEndpoint = mapRuntimeTrackingEndpointSpec(sourceSpec);
1727
+ const useLoadStrikeTraceIdHeader = readUseLoadStrikeTraceIdHeader(copied);
1728
+ const sourceEndpoint = mapRuntimeTrackingEndpointSpec(sourceSpec, useLoadStrikeTraceIdHeader);
1728
1729
  const destinationEndpoint = Object.keys(destinationSpec).length
1729
- ? mapRuntimeTrackingEndpointSpec(destinationSpec)
1730
+ ? mapRuntimeTrackingEndpointSpec(destinationSpec, useLoadStrikeTraceIdHeader)
1730
1731
  : null;
1731
1732
  validateRuntimeTrackingConfiguration(copied, sourceEndpoint, destinationEndpoint);
1732
1733
  return new LoadStrikeScenario(this.name, this.runHandler, this.initHandler, this.cleanHandler, this.loadSimulations, this.thresholds, copied, this.maxFailCount, this.withoutWarmUpValue, this.warmUpDurationSeconds, this.weight, this.restartIterationOnFail, this.internalLicenseFeatures);
@@ -5730,9 +5731,10 @@ class ManagedScenarioTrackingRuntime {
5730
5731
  this.timeoutLoop = null;
5731
5732
  const sourceSpec = asTrackingRecord(pickTrackingValue(tracking, "Source", "source"));
5732
5733
  const destinationSpec = asTrackingRecord(pickTrackingValue(tracking, "Destination", "destination"));
5733
- this.sourceEndpoint = mapRuntimeTrackingEndpointSpec(sourceSpec);
5734
+ const useLoadStrikeTraceIdHeader = readUseLoadStrikeTraceIdHeader(tracking);
5735
+ this.sourceEndpoint = mapRuntimeTrackingEndpointSpec(sourceSpec, useLoadStrikeTraceIdHeader);
5734
5736
  this.destinationEndpoint = Object.keys(destinationSpec).length
5735
- ? mapRuntimeTrackingEndpointSpec(destinationSpec)
5737
+ ? mapRuntimeTrackingEndpointSpec(destinationSpec, useLoadStrikeTraceIdHeader)
5736
5738
  : null;
5737
5739
  validateRuntimeTrackingConfiguration(tracking, this.sourceEndpoint, this.destinationEndpoint);
5738
5740
  this.runMode = normalizeTrackingRunMode(pickTrackingString(tracking, "RunMode", "runMode", "GenerateAndCorrelate"));
@@ -6227,9 +6229,12 @@ function getScenarioTrackingRuntime(context, tracking) {
6227
6229
  return lease.runtime;
6228
6230
  }
6229
6231
  function buildTrackingLeaseKey(sessionId, scenarioName, tracking) {
6230
- const source = mapRuntimeTrackingEndpointSpec(asTrackingRecord(pickTrackingValue(tracking, "Source", "source")));
6232
+ const useLoadStrikeTraceIdHeader = readUseLoadStrikeTraceIdHeader(tracking);
6233
+ const source = mapRuntimeTrackingEndpointSpec(asTrackingRecord(pickTrackingValue(tracking, "Source", "source")), useLoadStrikeTraceIdHeader);
6231
6234
  const destinationSpec = asTrackingRecord(pickTrackingValue(tracking, "Destination", "destination"));
6232
- const destination = Object.keys(destinationSpec).length ? mapRuntimeTrackingEndpointSpec(destinationSpec) : null;
6235
+ const destination = Object.keys(destinationSpec).length
6236
+ ? mapRuntimeTrackingEndpointSpec(destinationSpec, useLoadStrikeTraceIdHeader)
6237
+ : null;
6233
6238
  const runMode = normalizeTrackingRunMode(pickTrackingString(tracking, "RunMode", "runMode", "GenerateAndCorrelate"));
6234
6239
  return `${sessionId}|${scenarioName}|${source.name}|${destination?.name ?? "<source-only>"}|${runMode}`;
6235
6240
  }
@@ -6309,6 +6314,9 @@ function validateRuntimeTrackingConfiguration(tracking, sourceEndpoint, destinat
6309
6314
  }
6310
6315
  throw new RangeError(`Unsupported tracking run mode: ${runMode}.`);
6311
6316
  }
6317
+ function readUseLoadStrikeTraceIdHeader(tracking) {
6318
+ return pickTrackingBoolean(tracking, "UseLoadStrikeTraceIdHeader", "useLoadStrikeTraceIdHeader", false);
6319
+ }
6312
6320
  function validateRuntimeRedisCorrelationStoreConfiguration(tracking) {
6313
6321
  const storeSpec = asTrackingRecord(pickTrackingValue(tracking, "CorrelationStore", "correlationStore"));
6314
6322
  const kind = pickTrackingString(storeSpec, "Kind", "kind", "").trim().toLowerCase();
@@ -6392,12 +6400,12 @@ function sanitizeTrackingNamespacePart(value) {
6392
6400
  .replace(/\s+/g, "_");
6393
6401
  }
6394
6402
  async function produceOrConsumeTrackingPayload(adapter, endpoint, runMode, index) {
6395
- const payload = runMode === "correlateexistingtraffic"
6396
- ? await adapter.consume()
6397
- : await adapter.produce();
6398
- return normalizeRuntimeTrackingPayload(payload, endpoint, index);
6403
+ if (runMode === "correlateexistingtraffic") {
6404
+ return normalizeRuntimeObservedTrackingPayload(await adapter.consume(), endpoint);
6405
+ }
6406
+ return normalizeRuntimeTrackingPayload(await adapter.produce(), endpoint, index);
6399
6407
  }
6400
- function mapRuntimeTrackingEndpointSpec(spec) {
6408
+ function mapRuntimeTrackingEndpointSpec(spec, useLoadStrikeTraceIdHeader = false) {
6401
6409
  const pollIntervalMs = Math.trunc(pickTrackingNumber(spec, ["PollIntervalMs", "pollIntervalMs"], pickTrackingNumber(spec, ["PollIntervalSeconds", "pollIntervalSeconds", "PollInterval"], 0.25) * 1000));
6402
6410
  const httpSpec = asTrackingRecord(pickTrackingValue(spec, "Http", "http"));
6403
6411
  const delegateSpec = asTrackingRecord(pickTrackingValue(spec, "delegate", "Delegate", "DelegateStream"));
@@ -6424,7 +6432,7 @@ function mapRuntimeTrackingEndpointSpec(spec) {
6424
6432
  kind: pickTrackingString(spec, "Kind", "kind", "DelegateStream"),
6425
6433
  mode: pickTrackingString(spec, "Mode", "mode", "Produce"),
6426
6434
  name: pickTrackingString(spec, "Name", "name", "endpoint"),
6427
- trackingField: pickTrackingSelectorString(spec, "TrackingField", "trackingField", "header:x-correlation-id"),
6435
+ trackingField: pickTrackingSelectorString(spec, "TrackingField", "trackingField", useLoadStrikeTraceIdHeader ? transports_js_1.LOADSTRIKE_TRACE_ID_TRACKING_FIELD : "header:x-correlation-id"),
6428
6436
  gatherByField: pickOptionalTrackingSelectorString(spec, "GatherByField", "gatherByField"),
6429
6437
  autoGenerateTrackingIdWhenMissing: pickTrackingBoolean(spec, "AutoGenerateTrackingIdWhenMissing", "autoGenerateTrackingIdWhenMissing", true),
6430
6438
  pollIntervalMs,
@@ -6530,7 +6538,9 @@ function normalizeRuntimeTrackingPayload(payload, endpoint, index) {
6530
6538
  if (existing || !endpoint.autoGenerateTrackingIdWhenMissing) {
6531
6539
  return normalized;
6532
6540
  }
6533
- const generated = `${endpoint.name}-auto-${index + 1}`;
6541
+ const generated = endpoint.trackingField.trim().toLowerCase() === transports_js_1.LOADSTRIKE_TRACE_ID_TRACKING_FIELD
6542
+ ? (0, node_crypto_1.randomUUID)()
6543
+ : `${endpoint.name}-auto-${index + 1}`;
6534
6544
  const selector = endpoint.trackingField.trim();
6535
6545
  if (selector.toLowerCase().startsWith("header:")) {
6536
6546
  const headerName = selector.slice("header:".length).trim();
@@ -8034,7 +8044,7 @@ function buildRichHtmlReport(result) {
8034
8044
  <section id="scenarios" class="panel active">
8035
8045
  ${bars || "<div>No scenario data.</div>"}
8036
8046
  <table>
8037
- <thead><tr><th>Scenario</th><th>Requests</th><th>OK</th><th>Fail</th><th>TotalBytes</th><th>AvgLatencyMs</th></tr></thead>
8047
+ <thead><tr><th>Scenario</th><th>Requests</th><th>OK</th><th>Fail</th><th>TotalBytes</th><th>AvgLatency (ms)</th></tr></thead>
8038
8048
  <tbody>${scenarioRows || "<tr><td colspan='6'>No rows</td></tr>"}</tbody>
8039
8049
  </table>
8040
8050
  </section>
@@ -33,9 +33,11 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.__loadstrikeTestExports = exports.EndpointAdapterFactory = exports.KafkaSaslOptions = exports.HttpAuthOptions = exports.HttpOAuth2ClientCredentialsOptions = exports.PushDiffusionEndpointDefinition = exports.DelegateStreamEndpointDefinition = exports.AzureEventHubsEndpointDefinition = exports.RedisStreamsEndpointDefinition = exports.NatsEndpointDefinition = exports.RabbitMqEndpointDefinition = exports.KafkaEndpointDefinition = exports.HttpEndpointDefinition = exports.TrafficEndpointDefinition = void 0;
36
+ exports.__loadstrikeTestExports = exports.EndpointAdapterFactory = exports.KafkaSaslOptions = exports.HttpAuthOptions = exports.HttpOAuth2ClientCredentialsOptions = exports.PushDiffusionEndpointDefinition = exports.DelegateStreamEndpointDefinition = exports.AzureEventHubsEndpointDefinition = exports.RedisStreamsEndpointDefinition = exports.NatsEndpointDefinition = exports.RabbitMqEndpointDefinition = exports.KafkaEndpointDefinition = exports.HttpEndpointDefinition = exports.TrafficEndpointDefinition = exports.LOADSTRIKE_TRACE_ID_TRACKING_FIELD = exports.LOADSTRIKE_TRACE_ID_HEADER = void 0;
37
37
  const node_crypto_1 = require("node:crypto");
38
38
  const correlation_js_1 = require("./correlation.js");
39
+ exports.LOADSTRIKE_TRACE_ID_HEADER = "loadstrike-trace-id";
40
+ exports.LOADSTRIKE_TRACE_ID_TRACKING_FIELD = `header:${exports.LOADSTRIKE_TRACE_ID_HEADER}`;
39
41
  class TrafficEndpointDefinitionModel {
40
42
  get JsonSerializerSettings() {
41
43
  return this.JsonSettings;
@@ -1084,8 +1086,9 @@ class HttpEndpointAdapter extends CallbackAdapter {
1084
1086
  if (this.endpoint.mode !== "Produce") {
1085
1087
  return null;
1086
1088
  }
1087
- const resolved = payload ?? this.defaultPayload();
1088
1089
  const httpOptions = this.endpoint.http;
1090
+ const responseTracking = canonicalizeHttpTrackingPayloadSource(String(httpOptions?.trackingPayloadSource ?? "Request")) === "Response";
1091
+ const resolved = prepareProducedPayload(this.endpoint, payload, !responseTracking);
1089
1092
  if (!httpOptions?.url) {
1090
1093
  return super.produce(resolved);
1091
1094
  }
@@ -2988,7 +2991,7 @@ function createDefaultPayload(endpoint) {
2988
2991
  jsonConvertSettings: endpoint.jsonConvertSettings ? { ...endpoint.jsonConvertSettings } : undefined
2989
2992
  });
2990
2993
  }
2991
- function prepareProducedPayload(endpoint, payload) {
2994
+ function prepareProducedPayload(endpoint, payload, allowAutoGenerateTrackingId = true) {
2992
2995
  const base = payload
2993
2996
  ? attachPayloadHelpers({
2994
2997
  headers: {
@@ -3007,15 +3010,24 @@ function prepareProducedPayload(endpoint, payload) {
3007
3010
  if (trackingId) {
3008
3011
  return base;
3009
3012
  }
3013
+ if (!allowAutoGenerateTrackingId) {
3014
+ return base;
3015
+ }
3010
3016
  if (endpoint.autoGenerateTrackingIdWhenMissing === false) {
3011
3017
  throw new Error(`Tracking id could not be extracted using selector \`${endpoint.trackingField}\` and AutoGenerateTrackingIdWhenMissing is disabled for endpoint \`${endpoint.name}\`.`);
3012
3018
  }
3013
- const generated = (0, node_crypto_1.randomUUID)().replace(/-/g, "");
3019
+ const generated = isLoadStrikeTraceSelector(endpoint.trackingField)
3020
+ ? (0, node_crypto_1.randomUUID)()
3021
+ : (0, node_crypto_1.randomUUID)().replace(/-/g, "");
3014
3022
  if (!injectTrackingValue(base, endpoint.trackingField, generated)) {
3015
3023
  throw new Error(`Tracking id could not be injected using selector \`${endpoint.trackingField}\` for endpoint \`${endpoint.name}\`. Verify the selector and payload shape.`);
3016
3024
  }
3017
3025
  return base;
3018
3026
  }
3027
+ function isLoadStrikeTraceSelector(selector) {
3028
+ const trimmed = selector.trim();
3029
+ return trimmed.toLowerCase() === exports.LOADSTRIKE_TRACE_ID_TRACKING_FIELD;
3030
+ }
3019
3031
  function toWirePayload(payload, endpoint) {
3020
3032
  return {
3021
3033
  headers: { ...(payload.headers ?? {}) },
package/dist/esm/index.js CHANGED
@@ -2,5 +2,5 @@ export { LoadStrikeAutopilot, LoadStrikeAutopilotResult } from "./autopilot.js";
2
2
  export { LoadStrikeAutopilotReadiness } from "./autopilot-contracts.js";
3
3
  export { CrossPlatformScenarioConfigurator, ScenarioTrackingExtensions, LoadStrikeContext, LoadStrikePluginData, LoadStrikePluginDataTable, LoadStrikeNodeType, LoadStrikeReportFormat, LoadStrikeResponse, LoadStrikeLogLevel, LoadStrikeScenarioOperation, LoadStrikeOperationType, LoadStrikeRunner, LoadStrikeScenario, LoadStrikeSimulation, LoadStrikeMetric, LoadStrikeCounter, LoadStrikeGauge, LoadStrikeStep, LoadStrikeThreshold } from "./runtime.js";
4
4
  export { CorrelationStoreConfiguration, CrossPlatformTrackingRuntime, InMemoryCorrelationStore, RedisCorrelationStoreOptions, RedisCorrelationStore, TrackingPayloadBuilder, TrackingFieldSelector } from "./correlation.js";
5
- export { EndpointAdapterFactory, TrafficEndpointDefinition, HttpEndpointDefinition, KafkaEndpointDefinition, KafkaSaslOptions, RabbitMqEndpointDefinition, NatsEndpointDefinition, RedisStreamsEndpointDefinition, AzureEventHubsEndpointDefinition, DelegateStreamEndpointDefinition, PushDiffusionEndpointDefinition, HttpOAuth2ClientCredentialsOptions, HttpAuthOptions } from "./transports.js";
5
+ export { EndpointAdapterFactory, LOADSTRIKE_TRACE_ID_HEADER, LOADSTRIKE_TRACE_ID_TRACKING_FIELD, TrafficEndpointDefinition, HttpEndpointDefinition, KafkaEndpointDefinition, KafkaSaslOptions, RabbitMqEndpointDefinition, NatsEndpointDefinition, RedisStreamsEndpointDefinition, AzureEventHubsEndpointDefinition, DelegateStreamEndpointDefinition, PushDiffusionEndpointDefinition, HttpOAuth2ClientCredentialsOptions, HttpAuthOptions } from "./transports.js";
6
6
  export { DatadogReportingSink, DatadogReportingSinkOptions, GrafanaLokiReportingSink, GrafanaLokiReportingSinkOptions, InfluxDbReportingSink, InfluxDbReportingSinkOptions, OtelCollectorReportingSink, OtelCollectorReportingSinkOptions, SplunkReportingSink, SplunkReportingSinkOptions, TimescaleDbReportingSink, TimescaleDbReportingSinkOptions } from "./sinks.js";
package/dist/esm/local.js CHANGED
@@ -3,7 +3,7 @@ import * as fs from "node:fs";
3
3
  import * as childProcess from "node:child_process";
4
4
  import { createHash, createVerify, randomUUID } from "node:crypto";
5
5
  import { CorrelationStoreConfiguration, CrossPlatformTrackingRuntime, RedisCorrelationStoreOptions, RedisCorrelationStore, TrackingFieldSelector } from "./correlation.js";
6
- import { EndpointAdapterFactory } from "./transports.js";
6
+ import { EndpointAdapterFactory, LOADSTRIKE_TRACE_ID_TRACKING_FIELD } from "./transports.js";
7
7
  const DEFAULT_LICENSING_API_BASE_URL = "https://licensing.loadstrike.com";
8
8
  const INTERNAL_BLACKBOX_LICENSING_API_BASE_URL_ENVIRONMENT_VARIABLE = "LOADSTRIKE_INTERNAL_BLACKBOX_API_BASE_URL";
9
9
  let developmentLicensingApiBaseUrlOverride;
@@ -810,10 +810,11 @@ async function evaluateScenarioOutcome(scenario, requestCount, context) {
810
810
  if (!Object.keys(sourceSpec).length) {
811
811
  return { requestCount, okCount: requestCount, failCount: 0 };
812
812
  }
813
- const sourceEndpoint = mapEndpointSpec(sourceSpec);
813
+ const useLoadStrikeTraceIdHeader = toBoolean(pickValue(tracking, "UseLoadStrikeTraceIdHeader", "useLoadStrikeTraceIdHeader"), false);
814
+ const sourceEndpoint = mapEndpointSpec(sourceSpec, useLoadStrikeTraceIdHeader);
814
815
  const destinationSpec = asRecord(tracking.Destination);
815
816
  const hasDestination = Object.keys(destinationSpec).length > 0;
816
- const destinationEndpoint = hasDestination ? mapEndpointSpec(destinationSpec) : null;
817
+ const destinationEndpoint = hasDestination ? mapEndpointSpec(destinationSpec, useLoadStrikeTraceIdHeader) : null;
817
818
  validateTrackingConfiguration(tracking, sourceEndpoint, destinationEndpoint);
818
819
  const sourceAdapter = EndpointAdapterFactory.create(sourceEndpoint);
819
820
  const destinationAdapter = destinationEndpoint ? EndpointAdapterFactory.create(destinationEndpoint) : null;
@@ -1069,7 +1070,7 @@ function inferLegacyHttpResponseSourceValue(value) {
1069
1070
  return undefined;
1070
1071
  }
1071
1072
  }
1072
- function mapEndpointSpec(spec) {
1073
+ function mapEndpointSpec(spec, useLoadStrikeTraceIdHeader = false) {
1073
1074
  const pollIntervalOverride = pickValue(spec, "PollIntervalMs", "pollIntervalMs");
1074
1075
  const pollIntervalSeconds = pickValue(spec, "PollIntervalSeconds", "pollIntervalSeconds", "PollInterval");
1075
1076
  const pollIntervalMs = pollIntervalOverride != null && String(pollIntervalOverride).trim() !== ""
@@ -1102,7 +1103,7 @@ function mapEndpointSpec(spec) {
1102
1103
  kind: stringOrDefault(pickValue(spec, "Kind", "kind"), "DelegateStream"),
1103
1104
  mode: stringOrDefault(pickValue(spec, "Mode", "mode"), "Produce"),
1104
1105
  name: stringOrDefault(pickValue(spec, "Name", "name"), "endpoint"),
1105
- trackingField: readTrackingSelectorValue(pickValue(spec, "TrackingField", "trackingField"), "header:x-correlation-id"),
1106
+ trackingField: readTrackingSelectorValue(pickValue(spec, "TrackingField", "trackingField"), useLoadStrikeTraceIdHeader ? LOADSTRIKE_TRACE_ID_TRACKING_FIELD : "header:x-correlation-id"),
1106
1107
  gatherByField: readOptionalTrackingSelectorValue(pickValue(spec, "GatherByField", "gatherByField")),
1107
1108
  autoGenerateTrackingIdWhenMissing: toBoolean(pickValue(spec, "AutoGenerateTrackingIdWhenMissing", "autoGenerateTrackingIdWhenMissing"), true),
1108
1109
  pollIntervalMs,
@@ -1202,10 +1203,13 @@ function normalizePayload(payload, endpoint, index) {
1202
1203
  return normalized;
1203
1204
  }
1204
1205
  const existing = readTrackingId(normalized, selector);
1205
- if (existing || !endpoint.autoGenerateTrackingIdWhenMissing) {
1206
+ const endpointMode = String(endpoint.mode ?? "Produce").trim().toLowerCase();
1207
+ if (existing || endpointMode === "consume" || !endpoint.autoGenerateTrackingIdWhenMissing) {
1206
1208
  return normalized;
1207
1209
  }
1208
- const generated = `${endpoint.name}-auto-${index + 1}`;
1210
+ const generated = selector.toLowerCase() === LOADSTRIKE_TRACE_ID_TRACKING_FIELD
1211
+ ? randomUUID()
1212
+ : `${endpoint.name}-auto-${index + 1}`;
1209
1213
  if (selector.toLowerCase().startsWith("header:")) {
1210
1214
  const headerName = selector.slice("header:".length).trim();
1211
1215
  if (headerName) {