Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@instana/core

Package Overview
Dependencies
Maintainers
3
Versions
261
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@instana/core - npm Package Compare versions

Comparing version 1.102.0 to 1.103.0

src/tracing/instrumentation/protocols/http2Client.js

4

package.json
{
"name": "@instana/core",
"version": "1.102.0",
"version": "1.103.0",
"description": "Core library for Instana's Node.js packages",

@@ -136,3 +136,3 @@ "main": "src/index.js",

},
"gitHead": "ffc9b8ad0bae3bcc06541297cbdac1912163ff5a"
"gitHead": "5a71014e072f20b0d5021e8e9fee613f103fdacb"
}

@@ -52,2 +52,4 @@ 'use strict';

'./instrumentation/protocols/httpServer',
'./instrumentation/protocols/http2Client',
'./instrumentation/protocols/http2Server',
'./instrumentation/protocols/superagent'

@@ -54,0 +56,0 @@ ];

@@ -5,5 +5,14 @@ 'use strict';

* Used in http server instrumentation, the headers are already lower cased in the data we receive. This method is less
* expensive than getExtraHeadersCaseInsensitive.
* expensive than getExtraHeadersCaseInsensitive/getExtraHeadersFromOptions.
*/
exports.getExtraHeaders = function getExtraHeaders(message, extraHttpHeadersToCapture) {
exports.getExtraHeadersFromMessage = function getExtraHeadersFromMessage(message, extraHttpHeadersToCapture) {
return exports.getExtraHeadersFromHeaders(message.headers, extraHttpHeadersToCapture);
};
/*
* Used in http2 server instrumentation (and indirectly in http1 server instrumentation), the headers are already lower
* cased in the data we receive. This method is less expensive than
* getExtraHeadersCaseInsensitive/getExtraHeadersFromOptions.
*/
exports.getExtraHeadersFromHeaders = function getExtraHeadersFromHeaders(headers, extraHttpHeadersToCapture) {
if (!extraHttpHeadersToCapture || extraHttpHeadersToCapture.length === 0) {

@@ -17,3 +26,3 @@ return undefined;

var key = extraHttpHeadersToCapture[i];
var value = message.headers[key];
var value = headers[key];
if (value) {

@@ -32,16 +41,21 @@ extraHeaders[key] = value;

* Used in http client instrumentation, the headers can appear in any lower case/upper case combination there. This is
* slightly more expensive than getExtraHeaders.
* slightly more expensive than getExtraHeadersFromMessage.
*/
exports.getExtraHeadersCaseInsensitive = function getExtraHeaders(options, extraHttpHeadersToCapture) {
if (
!extraHttpHeadersToCapture ||
extraHttpHeadersToCapture.length === 0 ||
!options ||
!options.headers ||
typeof options.headers !== 'object'
) {
exports.getExtraHeadersFromOptions = function getExtraHeadersFromOptions(options, extraHttpHeadersToCapture) {
if (!options) {
return undefined;
}
return exports.getExtraHeadersCaseInsensitive(options.headers, extraHttpHeadersToCapture);
};
var keys = Object.keys(options.headers).map(function(key) {
/*
* Used in http2 (and indirectly http 1.x client) instrumentation, the headers can appear in any lower case/upper case
* combination there. This is slightly more expensive than getExtraHeadersFromMessage.
*/
exports.getExtraHeadersCaseInsensitive = function getExtraHeadersCaseInsensitive(headers, extraHttpHeadersToCapture) {
if (!extraHttpHeadersToCapture || extraHttpHeadersToCapture.length === 0 || !headers || typeof headers !== 'object') {
return undefined;
}
var keys = Object.keys(headers).map(function(key) {
return { orig: key, low: key.toLowerCase() };

@@ -55,3 +69,3 @@ });

if (keys[j].low === keyToCapture) {
extraHeaders[keys[j].low] = options.headers[keys[j].orig];
extraHeaders[keys[j].low] = headers[keys[j].orig];
extraHeadersFound = true;

@@ -78,3 +92,3 @@ }

exports.mergeExtraHeadersFromIncomingMessage = function mergeExtraHeadersForExit(
exports.mergeExtraHeadersFromIncomingMessage = function mergeExtraHeadersFromIncomingMessage(
headersAlreadyCapturedIfAny,

@@ -84,7 +98,45 @@ incomingMessage,

) {
return exports.mergeExtraHeadersFromHeaders(
headersAlreadyCapturedIfAny,
incomingMessage.headers,
extraHttpHeadersToCapture
);
};
exports.mergeExtraHeadersFromHeaders = function mergeExtraHeadersFromHeaders(
headersAlreadyCapturedIfAny,
headers,
extraHttpHeadersToCapture
) {
if (!headers) {
return headersAlreadyCapturedIfAny;
}
return mergeExtraHeaders(headersAlreadyCapturedIfAny, extraHttpHeadersToCapture, function(key) {
return incomingMessage.headers[key];
return headers[key];
});
};
exports.mergeExtraHeadersCaseInsensitive = function mergeExtraHeadersCaseInsensitive(
headersAlreadyCapturedIfAny,
headers,
extraHttpHeadersToCapture
) {
if (!extraHttpHeadersToCapture || extraHttpHeadersToCapture.length === 0 || !headers) {
return headersAlreadyCapturedIfAny;
}
var keys = Object.keys(headers).map(function(key) {
return { orig: key, low: key.toLowerCase() };
});
return mergeExtraHeaders(headersAlreadyCapturedIfAny, extraHttpHeadersToCapture, function(keyToCapture) {
for (var j = 0; j < keys.length; j++) {
if (keys[j].low === keyToCapture) {
return headers[keys[j].orig];
}
}
return null;
});
};
function mergeExtraHeaders(headersAlreadyCapturedIfAny, extraHttpHeadersToCapture, getHeader) {

@@ -91,0 +143,0 @@ if (!extraHttpHeadersToCapture || extraHttpHeadersToCapture.length === 0) {

@@ -376,3 +376,3 @@ 'use strict';

var parts = fullUrl.split('?');
if (parts.length >= 1) {
if (parts.length >= 2) {
return filterParams(parts[1]);

@@ -391,3 +391,3 @@ }

function captureRequestHeaders(options, clientRequest, response) {
var headers = httpCommon.getExtraHeadersCaseInsensitive(options, extraHttpHeadersToCapture);
var headers = httpCommon.getExtraHeadersFromOptions(options, extraHttpHeadersToCapture);
headers = httpCommon.mergeExtraHeadersFromServerResponseOrClientResponse(

@@ -394,0 +394,0 @@ headers,

@@ -87,3 +87,3 @@ 'use strict';

var urlParts = req.url.split('?');
if (urlParts.length >= 1) {
if (urlParts.length >= 2) {
urlParts[1] = filterParams(urlParts[1]);

@@ -94,5 +94,5 @@ }

url: discardUrlParameters(urlParts.shift()),
params: urlParts.join('?'),
params: urlParts.length > 0 ? urlParts.join('?') : undefined,
host: req.headers.host,
header: httpCommon.getExtraHeaders(req, extraHttpHeadersToCapture)
header: httpCommon.getExtraHeadersFromMessage(req, extraHttpHeadersToCapture)
};

@@ -109,3 +109,3 @@ var incomingServiceName =

// eslint-disable-next-line max-len
// https://docs.instana.io/products/website_monitoring/backendCorrelation/#retrieve-the-backend-trace-id-in-nodejs
// https://www.instana.com/docs/products/website_monitoring/backendCorrelation/#retrieve-the-backend-trace-id-in-nodejs
req.headers['x-instana-t'] = span.t;

@@ -112,0 +112,0 @@

@@ -15,11 +15,18 @@ 'use strict';

}
return exports.fromHeaders(req.headers);
};
var xInstanaT = readInstanaTraceId(req);
var xInstanaS = readInstanaParentId(req);
var levelAndCorrelation = readLevelAndCorrelation(req);
/**
* Inspects the given headers for X-INSTANA-T, X-INSTANA-S, X-INSTANA-L, as well as the W3C trace
* context headers traceparent and tracestate.
*/
exports.fromHeaders = function fromHeaders(headers) {
var xInstanaT = readInstanaTraceId(headers);
var xInstanaS = readInstanaParentId(headers);
var levelAndCorrelation = readLevelAndCorrelation(headers);
var level = levelAndCorrelation.level;
var correlationType = levelAndCorrelation.correlationType;
var correlationId = levelAndCorrelation.correlationId;
var synthetic = readSyntheticMarker(req);
var w3cTraceContext = readW3cTraceContext(req);
var synthetic = readSyntheticMarker(headers);
var w3cTraceContext = readW3cTraceContext(headers);

@@ -152,4 +159,4 @@ if (correlationType && correlationId) {

function readInstanaTraceId(req) {
var xInstanaT = req.headers[constants.traceIdHeaderNameLowerCase];
function readInstanaTraceId(headers) {
var xInstanaT = headers[constants.traceIdHeaderNameLowerCase];
if (xInstanaT == null) {

@@ -161,4 +168,4 @@ return null;

function readInstanaParentId(req) {
var xInstanaS = req.headers[constants.spanIdHeaderNameLowerCase];
function readInstanaParentId(headers) {
var xInstanaS = headers[constants.spanIdHeaderNameLowerCase];
if (xInstanaS == null) {

@@ -170,4 +177,4 @@ return null;

function readLevelAndCorrelation(req) {
var xInstanaL = req.headers[constants.traceLevelHeaderNameLowerCase];
function readLevelAndCorrelation(headers) {
var xInstanaL = headers[constants.traceLevelHeaderNameLowerCase];
if (xInstanaL == null) {

@@ -219,4 +226,4 @@ // fast path for when we did not receive the header at all

function readSyntheticMarker(req) {
return req.headers[constants.syntheticHeaderNameLowerCase] === '1';
function readSyntheticMarker(headers) {
return headers[constants.syntheticHeaderNameLowerCase] === '1';
}

@@ -228,7 +235,7 @@

function readW3cTraceContext(req) {
var traceParent = req.headers[constants.w3cTraceParent];
function readW3cTraceContext(headers) {
var traceParent = headers[constants.w3cTraceParent];
// The spec mandates that multiple tracestate headers should be treated by concatenating them. Node.js' http core
// library takes care of that already.
var traceState = req.headers[constants.w3cTraceState];
var traceState = headers[constants.w3cTraceState];
var traceContext;

@@ -235,0 +242,0 @@ if (traceParent) {

@@ -143,3 +143,3 @@ /* eslint-disable */

'Not enabling automatic tracing, this is an unsupported version of Node.js. ' +
'See: https://docs.instana.io/ecosystem/node-js/#supported-nodejs-versions'
'See: https://www.instana.com/docs/ecosystem/node-js/#supported-nodejs-versions'
);

@@ -146,0 +146,0 @@ config.tracing.automaticTracingEnabled = false;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc