@artilleryio/int-core 2.25.0-e72f537 → 2.25.0-eb2ea5e
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/lib/engine_http.js +63 -0
- package/package.json +3 -3
package/lib/engine_http.js
CHANGED
|
@@ -153,6 +153,62 @@ HttpEngine.prototype.init = async function () {
|
|
|
153
153
|
this.request = (await import('got')).default;
|
|
154
154
|
};
|
|
155
155
|
|
|
156
|
+
HttpEngine.prototype._isDistributedTracingEnabled = function (config) {
|
|
157
|
+
const dtConfig = config.http?.distributedTracing;
|
|
158
|
+
if (!dtConfig) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Handle both boolean and object forms
|
|
163
|
+
if (typeof dtConfig === 'boolean') {
|
|
164
|
+
return dtConfig;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (typeof dtConfig === 'object' && dtConfig.enabled !== undefined) {
|
|
168
|
+
return dtConfig.enabled;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Default to true if distributedTracing is set but enabled is not specified
|
|
172
|
+
return true;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
HttpEngine.prototype._generateTraceparent = function (config) {
|
|
176
|
+
// W3C Trace Context format: version-trace-id-parent-id-trace-flags
|
|
177
|
+
const version = '00';
|
|
178
|
+
|
|
179
|
+
// Get configuration
|
|
180
|
+
const dtConfig = config.http?.distributedTracing;
|
|
181
|
+
let sampled = true; // Default to sampled
|
|
182
|
+
let traceIdPrefix = 'a9'; // Default prefix
|
|
183
|
+
|
|
184
|
+
if (typeof dtConfig === 'object') {
|
|
185
|
+
if (dtConfig.sampled !== undefined) {
|
|
186
|
+
sampled = dtConfig.sampled;
|
|
187
|
+
}
|
|
188
|
+
if (dtConfig.traceIdPrefix !== undefined) {
|
|
189
|
+
traceIdPrefix = dtConfig.traceIdPrefix;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Validate and normalize prefix (must be valid hex, max 8 chars)
|
|
194
|
+
traceIdPrefix = traceIdPrefix.toLowerCase().replace(/[^0-9a-f]/g, '').slice(0, 8);
|
|
195
|
+
if (traceIdPrefix.length === 0) {
|
|
196
|
+
traceIdPrefix = 'a9'; // Fallback to default if invalid
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Generate trace-id with prefix (32 hex chars total)
|
|
200
|
+
const remainingBytes = Math.ceil((32 - traceIdPrefix.length) / 2);
|
|
201
|
+
const randomPart = crypto.randomBytes(remainingBytes).toString('hex');
|
|
202
|
+
const traceId = (traceIdPrefix + randomPart).slice(0, 32);
|
|
203
|
+
|
|
204
|
+
// Generate 8-byte parent-id (16 hex chars)
|
|
205
|
+
const parentId = crypto.randomBytes(8).toString('hex');
|
|
206
|
+
|
|
207
|
+
const traceFlags = sampled ? '01' : '00';
|
|
208
|
+
|
|
209
|
+
return `${version}-${traceId}-${parentId}-${traceFlags}`;
|
|
210
|
+
};
|
|
211
|
+
|
|
156
212
|
HttpEngine.prototype.createScenario = function (scenarioSpec, ee) {
|
|
157
213
|
ensurePropertyIsAList(scenarioSpec, 'beforeRequest');
|
|
158
214
|
ensurePropertyIsAList(scenarioSpec, 'afterResponse');
|
|
@@ -715,6 +771,13 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
|
|
|
715
771
|
const gotOptions = _.pick(requestParams, GOT_OPTION_NAMES);
|
|
716
772
|
gotOptions.timeout = { response: requestParams.timeout * 1000 };
|
|
717
773
|
|
|
774
|
+
// Add W3C Trace Context headers if distributed tracing is enabled
|
|
775
|
+
if (self._isDistributedTracingEnabled(config)) {
|
|
776
|
+
const traceparent = self._generateTraceparent(config);
|
|
777
|
+
gotOptions.headers = gotOptions.headers || {};
|
|
778
|
+
gotOptions.headers.traceparent = traceparent;
|
|
779
|
+
}
|
|
780
|
+
|
|
718
781
|
let totalDownloaded = 0;
|
|
719
782
|
self
|
|
720
783
|
.request(gotOptions)
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artilleryio/int-core",
|
|
3
|
-
"version": "2.25.0-
|
|
3
|
+
"version": "2.25.0-eb2ea5e",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@artilleryio/int-commons": "2.21.0-
|
|
7
|
+
"@artilleryio/int-commons": "2.21.0-eb2ea5e",
|
|
8
8
|
"@artilleryio/sketches-js": "^2.1.1",
|
|
9
9
|
"agentkeepalive": "^4.6.0",
|
|
10
10
|
"arrivals": "^2.1.2",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"got": "^14.6.6",
|
|
26
26
|
"hpagent": "^0.1.1",
|
|
27
27
|
"https-proxy-agent": "^5.0.0",
|
|
28
|
-
"lodash": "^4.
|
|
28
|
+
"lodash": "^4.18.0",
|
|
29
29
|
"ms": "^2.1.3",
|
|
30
30
|
"protobufjs": "^7.5.4",
|
|
31
31
|
"socket.io-client": "^4.8.3",
|