Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.

Commit a369ec5

Browse files
authored
fix(http.js): add debug prints (#427)
* fix(http.js): add debug prints * fix(http.js): add debug prints * fix(http.js): add debug prints
1 parent 91ebf9b commit a369ec5

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/events/http.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,6 @@ function httpWrapper(wrappedFunction) {
148148
const { url, options, callback } = parseArgs(a, b, c);
149149
const chunks = [];
150150

151-
if (callback && callback.__epsagonCallback) { // eslint-disable-line no-underscore-dangle
152-
// we are already tracing this request. can happen in
153-
// https->http cases
154-
return wrappedFunction.apply(this, [a, b, c]);
155-
}
156151
let clientRequest = null;
157152
try {
158153
let parsedUrl = url;
@@ -169,8 +164,18 @@ function httpWrapper(wrappedFunction) {
169164
(options && options.uri && options.uri.hostname) ||
170165
'localhost'
171166
);
167+
utils.debugLog(`[http] captured call ${hostname}`);
168+
169+
// eslint-disable-next-line no-underscore-dangle
170+
if (callback && callback.__epsagonCallback) {
171+
// we are already tracing this request. can happen in
172+
// https->http cases
173+
utils.debugLog(`[http] filtered patched callback ${hostname}`);
174+
return wrappedFunction.apply(this, [a, b, c]);
175+
}
176+
172177
// Capture the port if provided and is different than standard 80 and 443
173-
if (options.port && !['80', '443'].includes(options.port)) {
178+
if (options.port && !['80', '443', 80, 443].includes(options.port)) {
174179
hostname = `${hostname}:${options.port}`;
175180
}
176181

@@ -191,11 +196,11 @@ function httpWrapper(wrappedFunction) {
191196
);
192197

193198
if (isBlacklistURL(hostname, URL_BLACKLIST, path) || isURLIgnoredByUser(hostname)) {
194-
utils.debugLog(`filtered blacklist hostname ${hostname}`);
199+
utils.debugLog(`[http] filtered ignored hostname ${hostname}`);
195200
return wrappedFunction.apply(this, [a, b, c]);
196201
}
197202
if (isBlacklistHeader(headers, USER_AGENTS_BLACKLIST)) {
198-
utils.debugLog('filtered blacklist headers headers');
203+
utils.debugLog('[http] filtered ignored headers');
199204
return wrappedFunction.apply(this, [a, b, c]);
200205
}
201206

@@ -277,6 +282,7 @@ function httpWrapper(wrappedFunction) {
277282
}
278283

279284
const patchedCallback = (res) => {
285+
utils.debugLog(`[http] patched callback called for ${hostname}`);
280286
const metadataFields = {};
281287
if ('x-openwhisk-activation-id' in res.headers) {
282288
// This field is used to identify activation ID from 'OpenWhisk'
@@ -316,6 +322,7 @@ function httpWrapper(wrappedFunction) {
316322
clientRequest = wrappedFunction.apply(
317323
this, buildParams(url, options, patchedCallback)
318324
);
325+
utils.debugLog(`[http] request sent ${hostname}`);
319326

320327
if (
321328
options &&
@@ -425,6 +432,7 @@ function httpWrapper(wrappedFunction) {
425432
};
426433

427434
clientRequest.on('response', (res) => {
435+
utils.debugLog(`[http] response arrived for ${hostname}`);
428436
// Listening to data only if options.epsagonSkipResponseData!=true or no options
429437
if (!checkIfOmitData()) {
430438
res.on('data', chunk => addChunk(chunk, chunks));
@@ -440,14 +448,17 @@ function httpWrapper(wrappedFunction) {
440448
});
441449

442450
tracer.addEvent(httpEvent, responsePromise);
451+
utils.debugLog(`[http] event added ${hostname}`);
443452
} catch (error) {
444453
tracer.addException(error);
445454
}
446455

447456
if (!clientRequest) {
457+
utils.debugLog('[http] not client request set');
448458
clientRequest = wrappedFunction.apply(this, [a, b, c]);
449459
}
450460

461+
utils.debugLog('[http] done handling call');
451462
return clientRequest;
452463
};
453464
}

0 commit comments

Comments
 (0)